Académique Documents
Professionnel Documents
Culture Documents
be necesary.
Outside the assembler statements, JAL also manages the hole RAM memory and se
lects the bank when necesary. Example:
<JAL>
include f452_20
var volatile byte myvar01 at 0x0123
var volatile byte myvar02 at 0x0047
myvar01 = 0x10
myvar02 = 0x10
</JAL>
<ASM>
;; 006 : var volatile byte myvar01 at 0x0123
; var H'123:000' myvar01
;; 007 : var volatile byte myvar02 at 0x0047
; var H'047:000' myvar02
;; 009 : myvar01 = 0x10
movlw H'10'
movlb H'01' ; bank=1
movwf H'123' ; true_address=0x123
;; 010 : myvar02 = 0x10
movlw H'10'
movwf H'047' ; access_bank ; true_address=0x047
</ASM>
With PIC_16 cores this is enhanced by 3 diferent FSRs (address holders) and 5
diferent INDF for each one of the FSRs.
As the RAM memory it's larger than a byte (0..255) the FSRs are splitted in 2
registers for High byte of the address and Low byte of the address.
SFR name Address Description
=========================================
FSR0H 0xFEA High byte of FSR0 (address holder #0)
FSR0L 0xFE9 Low byte of FSR0 (address holder #0)
-----------------------------------------
FSR1H 0xFE2 High byte of FSR1 (address holder #1)
FSR1L 0xFE1 Low byte of FSR1 (address holder #1)
-----------------------------------------
FSR2H 0xFDA High byte of FSR2 (address holder #2)
FSR2L 0xFD9 Low byte of FSR2 (address holder #2)
With these registers we can select any address on the chip. Example:
<JAL>
FSR0H == 0x00
FSR0L == 0x23 -- FSR0 = 0x023
FSR1H == 0x02
FSR1L == 0x44 -- FSR1 = 0x244
FSR2H == 0x0F
FSR2L == 0xFC -- FSR2 = 0xFFC
</JAL>
<JAL>
assembler
LFSR 0,0x0023 ; FSR0 = 0x023
LFSR 1,0x0244 ; FSR1 = 0x244
LFSR 2,0x0FFC ; FSR2 = 0xFFC
end assembler
</JAL>
In order to manage the data pointed by FSRs we have the INDFs registers. They
have the following meaning:
Some examples:
<JAL>
-- Initialize the FSRs
assembler
LFSR 0,0x0100 ; FSR0 = 0x100
LFSR 1,0x0200 ; FSR1 = 0x200
LFSR 2,0x0300 ; FSR2 = 0x300
end assembler
-- Store some value into 0x100..0x123, 0x200..0x223, 0x200..0x223.
-- 105 bytes changed with this loop:
for 0x23 loop -- assigment
POSTINC0 = 0x00 -- [FSR0]<-0x00 and then FSR0=FSR0+1
POSTINC1 = " " -- [FSR1]<-0x20 and then FSR1=FSR1+1
POSTINC2 = 0xFF -- [FSR2]<-0xFF and then FSR2=FSR2+1
end loop
-- Store some value into 0x101..0x124, 0x201..0x224, 0x201..0x224.
for 0x23 loop -- assigment
PREINC0 = 0x00 -- FSR0=FSR0+1 and then [FSR0]<-0x00
PREINC1 = " " -- FSR1=FSR1+1 and then [FSR1]<-0x20
PREINC2 = 0xFF -- FSR2=FSR2+1 and then [FSR2]<-0xFF
end loop
-- Store some value into 0x100, 0x200, 0x200.
-- the same value are written 35 times in the same address.
for 0x23 loop -- assigment
INDF0 = 0x00 -- [FSR0]<-0x00; FSR0 = 0x100
INDF1 = " " -- [FSR1]<-0x20; FSR1 = 0x200
INDF2 = 0xFF -- [FSR2]<-0xFF; FSR2 = 0x300
end loop
</JAL>
<JAL>
assembler
local label01 , label02
bsf status_c
bra label02 ; Jump to label02. Coded as: bra H'001' (+1)
label01:
bcf status_c
label02:
movlw 0x10
movwf myvar01
bc label01 ; If carry jumps to label01. Coded as: bc H'FC' (-4)
end assembler
</JAL>
Sequence:
1.- bsf status_c ; Set carry
2.- bra label02 ; Jump to label02. PC+2+2n, n=+1
3.- movlw 0x10 ; Wreg<=0x10
4.- movwf myvar01 ; myvar01<=Wreg
5.- bc label01 ; Carry. Jump to label01. PC+2+2n, n=-4
6.- bcf status_c ; clear Carry
7.- movlw 0x10 ; Wreg<=0x10
8.- movwf myvar01 ; myvar01<=Wreg
9.- bc label01 ; Not Carry. Continues without jump.
The folloging mnemonics uses signed jumps, but we will use them with labels:
Name Description
======================
BC Branch if carry
BNC Branch if not carry
BN Branch if negative
BNC Branch if not negative
Bz Branch if zero
BNZ Branch if not zero
BOV Branch if overflow
BNOV Branch if not overflow
BRA Branch unconditionally
RCALL Relative call