Complete an assembly file

profileTimmyDrake
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 rol zH ; *2 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 block2: 0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73 block3: 0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B