the_proj_main.asm ; ; the_proj_main.asm ; ; Created: 23/12/2019 16:27:40 ; Author : W7 ; ; .include "8def.inc" .MACRO INITSTACK ldi r16,LOW(RAMEND) ; initialize out SPL,r16 ; stack pointer ldi r16,HIGH(RAMEND); to RAMEND out SPH,r16 ; " .ENDMACRO .def index_reg = r17 .def readValue_reg = r18 .def zero_reg = r19 .def temp_reg = r21 .def subr_param_1_reg = r24 .def subr_param_2_reg = r25 .equ BLOCK_SIZE = .equ NUM_OF_BLOCKS = 3 ;data .dseg .org 0x60 arrout1: .byte BLOCK_SIZE ; destination for data .org 0x68 arrout2: .byte BLOCK_SIZE ; destination for data .org 0x70 arrout3: .byte BLOCK_SIZE ; destination for data .cseg ;code start: INITSTACK ldi zero_reg, ;initialize index reg ldi index_reg,0 main: ; set subr_param_1_reg to index_reg mov subr_param_1_reg, index_reg rcall setUpPointersAndReadBlock ; increment the index inc index_reg 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( ) 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 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 ; ; 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 ; ; 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 ...