Hi, I`v just started working with the 18F4550 chip and complied a program that simply flashes an LED on/off.
when I looked at the ASM list, the whole code is littered with the word "Access".
what is this all about? when I look at the code in MPLAB (I use it to burn the 18F chip using the PICKit2), and hold the mouse pointer over the word "access" anywhere in the list, it says "Access =0x00".
and yet there`s no "access" variable declared anywhere.
what`s even stranger is that when I wrote code in GCBasic for the 16c54 chip, there was no mention of "Access" anywhere in the listing.
Both programs for both chips worked perfectly, I`m just curious what it is.
Thanks :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It's not a variable, it's a way of telling the PIC how it should access the variable in the instruction on 18Fs.
The full technical explanation is that it's to do with how variables are stored in the RAM on the PIC. The RAM is divided in to banks, each of which contains a certain number of locations. On the 18F4550, there are 16 memory banks. The first 8 each have 256 bytes of RAM, then there are 7 empty banks, and a 16th bank that stores all of the special function registers (things like PORTB that control I/O).
When referring to a variable, it isn't enough to say "the variable at location 10", because there are 8 "location 10"s - one in each data bank, and then one in the SFR bank. It's also necessary to say which bank the variable is in. So a variable that GCBASIC puts at location 0x000 is in bank 0, location 0. One at 0x012 is in bank 0, location 0x12. One at 0x504 is in bank 5, location 0x04. The trouble is, instructions (like movwf) only have room to store the location number, not the bank number.
This means that the bank needs to be specified somewhere else. The "ACCESS" or "BANKED" tells the PIC where it can find the bank. If there is a "BANKED" after the variable, GCBASIC will look at the BSR (bank select register) to find the bank. So if the BSR is 4, and the address in the instruction is 0x12, then the PIC will read the variable at 0x412. If there is an "ACCESS" after it, the PIC ignores the bank select register, and reads from the "access bank". If the PIC reads the first half of the access bank, it's the same as reading from the first data bank. So reading from location "0x31" in the access bank will read bank 0, location 0x31. Reading the second half of the access bank is the same as reading from the SFR bank - so reading from location 0x81 in the access bank will read from location 0xF81, which is PORTB.
The reason you don't see this on PIC10/12/16 chips is that there is no access bank on these. This means that every time a variable or SFR is read or written on one of these chips, the bank select register is checked. This in turn means a lot more work for the compiler (or the assembly programmer), because before every instruction they must make sure the correct bank has been chosen (using the banksel command). This takes more time to write, more time for the PIC to run, and more memory to store.
So basically, "ACCESS" tells the PIC to read a system register, and "BANKED" tells it to read a data variable. The access bank is one of the things that makes 18Fs more efficient because it doesn't have to change banks as often.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, I`v just started working with the 18F4550 chip and complied a program that simply flashes an LED on/off.
when I looked at the ASM list, the whole code is littered with the word "Access".
what is this all about? when I look at the code in MPLAB (I use it to burn the 18F chip using the PICKit2), and hold the mouse pointer over the word "access" anywhere in the list, it says "Access =0x00".
and yet there`s no "access" variable declared anywhere.
what`s even stranger is that when I wrote code in GCBasic for the 16c54 chip, there was no mention of "Access" anywhere in the listing.
Both programs for both chips worked perfectly, I`m just curious what it is.
Thanks :)
It's not a variable, it's a way of telling the PIC how it should access the variable in the instruction on 18Fs.
The full technical explanation is that it's to do with how variables are stored in the RAM on the PIC. The RAM is divided in to banks, each of which contains a certain number of locations. On the 18F4550, there are 16 memory banks. The first 8 each have 256 bytes of RAM, then there are 7 empty banks, and a 16th bank that stores all of the special function registers (things like PORTB that control I/O).
When referring to a variable, it isn't enough to say "the variable at location 10", because there are 8 "location 10"s - one in each data bank, and then one in the SFR bank. It's also necessary to say which bank the variable is in. So a variable that GCBASIC puts at location 0x000 is in bank 0, location 0. One at 0x012 is in bank 0, location 0x12. One at 0x504 is in bank 5, location 0x04. The trouble is, instructions (like movwf) only have room to store the location number, not the bank number.
This means that the bank needs to be specified somewhere else. The "ACCESS" or "BANKED" tells the PIC where it can find the bank. If there is a "BANKED" after the variable, GCBASIC will look at the BSR (bank select register) to find the bank. So if the BSR is 4, and the address in the instruction is 0x12, then the PIC will read the variable at 0x412. If there is an "ACCESS" after it, the PIC ignores the bank select register, and reads from the "access bank". If the PIC reads the first half of the access bank, it's the same as reading from the first data bank. So reading from location "0x31" in the access bank will read bank 0, location 0x31. Reading the second half of the access bank is the same as reading from the SFR bank - so reading from location 0x81 in the access bank will read from location 0xF81, which is PORTB.
The reason you don't see this on PIC10/12/16 chips is that there is no access bank on these. This means that every time a variable or SFR is read or written on one of these chips, the bank select register is checked. This in turn means a lot more work for the compiler (or the assembly programmer), because before every instruction they must make sure the correct bank has been chosen (using the banksel command). This takes more time to write, more time for the PIC to run, and more memory to store.
So basically, "ACCESS" tells the PIC to read a system register, and "BANKED" tells it to read a data variable. The access bank is one of the things that makes 18Fs more efficient because it doesn't have to change banks as often.
What a great reply! that answers it all perfectly, Thanks! :)