.BS expression1 [,expression2]
With .BS you can skip a block of memory.
The number of bytes to be skipped is determined by expression1.
The skipped bytes can be filled with the 8 bits value of expression2.
The .BS directive is often used in combination with the .DU and .ED directives to define RAM variables. Version 3 of the SB-Assembler can use the .SM directive in combination with the .BS directive to define RAM addresses more effectively.
In Version 3 of the SB-Assembler this directive will perform a boundary sync.
Expression1 may not contain forward referenced labels, otherwise a fatal Undefined label error will be reported.
The value of expression1 can range from 0 to $FFFFFFFF, although it is not very likely that you're going to use the maximum value.
If the value is 0 no bytes are skipped at all.
The maximum value of expression2 is $FF. Larger values will simply be truncated at the lowest byte before they are used. Thus a value of $100 will fill the skipped memory with the value $00.
The .BS directive is often used to declare RAM buffers and RAM variables. Normally it is not very useful to declare buffers in ROM memory because ROM values can not be changed while the program is running.
Operation of the .BS directive differs a little between formatted and unformatted target files.
With unformatted target files a filling value is always used, whether expression2 is given or not. If expression2 is omitted the value $00 is used to fill the skipped memory.
With formatted target files a filling value is only used if expression2 is given. Otherwise the skipped memory block will be skipped completely. The current data record is terminated and a new one is started with the new target address of the address field.
There is an exception to this rule and that is when the number of bytes skipped is less than the line record length of the target file. In that case bytes with the value of $00 are used to fill the skipped memory.
The list file will only contain the first address of the skipped memory block. The filled bytes are not listed in the list file.
The .BS directive will perform a boundary sync before it skips any bytes in code memory. Usually the beginning of a skipped block of memory is signaled by a label, which, by itself, will also perform a boundary sync anyway.
Things get a little complicated when you want to skip a certain number of bytes for processors which use multiple bytes per instructions (e.g. PIC and AVR).
Some of those processors can store only one byte per instruction word, others can store 2 bytes per instruction word.
That's why I've decided to always fill the skipped code memory for processors which store word sized instructions. That way I'm sure the assembler will always skip the right number of instruction words, whether they store one byte per instruction word or 2.
This doesn't apply to RAM or EEPROM memory though, as these memory types are always byte sized.
0000- .OR $0000 Define RAM memory 0000- .DU but don't produce any code 0000- PNTR .BS 2 Define a 2 bytes pointer 0002- CNTR .BS 2 Define a 2 bytes counter 0004- TEMP .BS 1 Define a 1 byte temp location 0005- FLAGS .BS 1 Define a flags byte 0006- KEYIN .BS 1 Last pressed key (1 byte) 0007- DSPPNT .BS 1 Display buffer pntr (1 byte) 0008- DSPBUF .BS 6 Define a 6 byte display buffer 000E- .ED End of dummy block 8000- .OR $8000 Begin of the program in ROM 8000- .BS $100,$FF Skip part of ROM memory 8100- ; and fill it with $FF
Please note that no code is generated in the .DUmmy block. Only the addresses are assigned to the appropriate labels.