4. cpi index_reg, NUM_OF_BLOCKS+1
br end
rjmp main ; do while (index_reg < NUM_OF_BLOCKS) ....
end: rjmp end
;
; SUBROUTINE setUpPointersAndReadBlock
; Inputs: subr_param_1_reg = index to read/write from/to array
;
setUpPointersAndReadBlock:
push xL
; First read the RAM output Address
ldi zH, HIGH( )
5. ldi zL, LOW(outPtrs)
; subr_param_1_reg already contains the desired index
rcall setInArrayPtrRegs
; set Y to beginning of RAM array
yH,z+
yL,z+
; set Z to the base-address + offset in the FLASH input-array
of pointers
ldi zH, HIGH(inPtrs)
ldi zL, LOW(inPtrs)
rcall setInArrayPtrRegs
;
; save the ptr to the data block in xL & xH
lpm xH,z+
lpm xL,z+
; now move the address of the data block to Z
6. mov zH,
mov zL,
; set input param to BLOCK_SIZE and call the subroutine
readOneBlock
subr_param_1_reg, BLOCK_SIZE
rcall readOneBlock
pop xL
pop xH
pop yL
pop yH
pop zL
pop zH
ret
;
7. ; SUBROUTINE readOneBlock - from Flash
; Inputs: zH & zL = base address of input array in FLASH
; yH & yL = base address of output array in RAM
;
readOneBlock:
push readValue_reg
push index_reg
mov index_reg,subr_param_1_reg
; copy each byte in the data from the FLASH data block to
the RAM data block
loop3: readValue_reg,Z+
y+,readValue_reg
dec index_reg
brne loop3
ret
8. ;
; SUBROUTINE setInArrayPtrRegs - sets up the input Z pointer
reg to arrin base-address (to read from flash)
;
; inputs: zH & zL = base address of the input array in flash
; subr_param_1_reg = index to read/write from/to array
; output: zH & zL = address of the requested entry in the array
with address adjusted to byte-based (like RAM)
setInArrayPtrRegs:
; use index to access next byte to be copied
add zL,subr_param_1_reg
zH,zero_reg
; fix offset for address in FLASH (words)
zL
rol zH ; *2
9. ret
; Finds the highest value in all the bytes in the current block
; and saves the value in the array MaxNum located at address 90
in the RAM
; Input: subr_param_1_reg = index to array blocks and to
MaxNum array
findMaxNumAndSaveIt:
ret
.org 0x80
outPtrs: .db 0x0, 0x70, 0x0, 0x68, 0x0, 0x60 ; target in RAM
for each data block
inPtrs: .db 0x1, 0xC, 0x1, 0x14, 0x1, 0x1C ; source in
FLASH for each data block
; Data Blocks with their data
block1: 0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B