SlideShare a Scribd company logo
1 of 10
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,0 x72,0x73
block3: 0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B
__MACOSX/._the_proj_main.asm

More Related Content

More from GrazynaBroyles24

5.4 - Commercial Air Travel during the 1950’s – 1960’sIn this .docx
5.4 - Commercial Air Travel during the 1950’s – 1960’sIn this .docx5.4 - Commercial Air Travel during the 1950’s – 1960’sIn this .docx
5.4 - Commercial Air Travel during the 1950’s – 1960’sIn this .docxGrazynaBroyles24
 
500 wordsAPA FormatScenarioYou are a probation officer a.docx
500 wordsAPA FormatScenarioYou are a probation officer a.docx500 wordsAPA FormatScenarioYou are a probation officer a.docx
500 wordsAPA FormatScenarioYou are a probation officer a.docxGrazynaBroyles24
 
500 words- no references. Must be original, no plagiarism.docx
500 words- no references. Must be original, no plagiarism.docx500 words- no references. Must be original, no plagiarism.docx
500 words- no references. Must be original, no plagiarism.docxGrazynaBroyles24
 
5.5 - Beginnings of the Space ProgramIn this discussion activi.docx
5.5 - Beginnings of the Space ProgramIn this discussion activi.docx5.5 - Beginnings of the Space ProgramIn this discussion activi.docx
5.5 - Beginnings of the Space ProgramIn this discussion activi.docxGrazynaBroyles24
 
5.3 - Discussion Ethical issuesReview the pros and cons of glob.docx
5.3 - Discussion Ethical issuesReview the pros and cons of glob.docx5.3 - Discussion Ethical issuesReview the pros and cons of glob.docx
5.3 - Discussion Ethical issuesReview the pros and cons of glob.docxGrazynaBroyles24
 
500 words APA formatHow much impact do managers actually have on a.docx
500 words APA formatHow much impact do managers actually have on a.docx500 words APA formatHow much impact do managers actually have on a.docx
500 words APA formatHow much impact do managers actually have on a.docxGrazynaBroyles24
 
5.2Complete one of the following options for your Week 5 Assignm.docx
5.2Complete one of the following options for your Week 5 Assignm.docx5.2Complete one of the following options for your Week 5 Assignm.docx
5.2Complete one of the following options for your Week 5 Assignm.docxGrazynaBroyles24
 
5.1 DBDisparities exist among racial and ethnic groups with rega.docx
5.1 DBDisparities exist among racial and ethnic groups with rega.docx5.1 DBDisparities exist among racial and ethnic groups with rega.docx
5.1 DBDisparities exist among racial and ethnic groups with rega.docxGrazynaBroyles24
 
5. What are the most common types of computer-based information syst.docx
5. What are the most common types of computer-based information syst.docx5. What are the most common types of computer-based information syst.docx
5. What are the most common types of computer-based information syst.docxGrazynaBroyles24
 
5.2 - Postwar Commercial AviationIn this discussion activity, .docx
5.2 - Postwar Commercial AviationIn this discussion activity, .docx5.2 - Postwar Commercial AviationIn this discussion activity, .docx
5.2 - Postwar Commercial AviationIn this discussion activity, .docxGrazynaBroyles24
 
5-6 paragraphsYou and Officer Landonio are on patrol. Yo.docx
5-6 paragraphsYou and Officer Landonio are on patrol. Yo.docx5-6 paragraphsYou and Officer Landonio are on patrol. Yo.docx
5-6 paragraphsYou and Officer Landonio are on patrol. Yo.docxGrazynaBroyles24
 
5-6 paragraphs Interagency is relatively recent as a term, y.docx
5-6 paragraphs Interagency is relatively recent as a term, y.docx5-6 paragraphs Interagency is relatively recent as a term, y.docx
5-6 paragraphs Interagency is relatively recent as a term, y.docxGrazynaBroyles24
 
5-6 paragraphsTerrorism in the United States has a history d.docx
5-6 paragraphsTerrorism in the United States has a history d.docx5-6 paragraphsTerrorism in the United States has a history d.docx
5-6 paragraphsTerrorism in the United States has a history d.docxGrazynaBroyles24
 
5-6 paragraphsAPA styleIn 2010, plans were announced for the.docx
5-6 paragraphsAPA styleIn 2010, plans were announced for the.docx5-6 paragraphsAPA styleIn 2010, plans were announced for the.docx
5-6 paragraphsAPA styleIn 2010, plans were announced for the.docxGrazynaBroyles24
 
5-7 paragraphs How do you think cooperation and cross-jurisdicti.docx
5-7 paragraphs How do you think cooperation and cross-jurisdicti.docx5-7 paragraphs How do you think cooperation and cross-jurisdicti.docx
5-7 paragraphs How do you think cooperation and cross-jurisdicti.docxGrazynaBroyles24
 
5-1 Discussion Oil SpillsOn April 20, 2010, there was an explosio.docx
5-1 Discussion Oil SpillsOn April 20, 2010, there was an explosio.docx5-1 Discussion Oil SpillsOn April 20, 2010, there was an explosio.docx
5-1 Discussion Oil SpillsOn April 20, 2010, there was an explosio.docxGrazynaBroyles24
 
5 Pages 1.Briefly define the concept of Black Nationalism.  .docx
5 Pages 1.Briefly define the concept of Black Nationalism.  .docx5 Pages 1.Briefly define the concept of Black Nationalism.  .docx
5 Pages 1.Briefly define the concept of Black Nationalism.  .docxGrazynaBroyles24
 
5 page, (NO MORE, NO LESS) double space only, and 14pt font, assessi.docx
5 page, (NO MORE, NO LESS) double space only, and 14pt font, assessi.docx5 page, (NO MORE, NO LESS) double space only, and 14pt font, assessi.docx
5 page, (NO MORE, NO LESS) double space only, and 14pt font, assessi.docxGrazynaBroyles24
 
400–500 words including a chart (APA Format) Knowing that the co.docx
400–500 words including a chart (APA Format) Knowing that the co.docx400–500 words including a chart (APA Format) Knowing that the co.docx
400–500 words including a chart (APA Format) Knowing that the co.docxGrazynaBroyles24
 
400-600 wordsThe new detective you are assisting is interest.docx
400-600 wordsThe new detective you are assisting is interest.docx400-600 wordsThe new detective you are assisting is interest.docx
400-600 wordsThe new detective you are assisting is interest.docxGrazynaBroyles24
 

More from GrazynaBroyles24 (20)

5.4 - Commercial Air Travel during the 1950’s – 1960’sIn this .docx
5.4 - Commercial Air Travel during the 1950’s – 1960’sIn this .docx5.4 - Commercial Air Travel during the 1950’s – 1960’sIn this .docx
5.4 - Commercial Air Travel during the 1950’s – 1960’sIn this .docx
 
500 wordsAPA FormatScenarioYou are a probation officer a.docx
500 wordsAPA FormatScenarioYou are a probation officer a.docx500 wordsAPA FormatScenarioYou are a probation officer a.docx
500 wordsAPA FormatScenarioYou are a probation officer a.docx
 
500 words- no references. Must be original, no plagiarism.docx
500 words- no references. Must be original, no plagiarism.docx500 words- no references. Must be original, no plagiarism.docx
500 words- no references. Must be original, no plagiarism.docx
 
5.5 - Beginnings of the Space ProgramIn this discussion activi.docx
5.5 - Beginnings of the Space ProgramIn this discussion activi.docx5.5 - Beginnings of the Space ProgramIn this discussion activi.docx
5.5 - Beginnings of the Space ProgramIn this discussion activi.docx
 
5.3 - Discussion Ethical issuesReview the pros and cons of glob.docx
5.3 - Discussion Ethical issuesReview the pros and cons of glob.docx5.3 - Discussion Ethical issuesReview the pros and cons of glob.docx
5.3 - Discussion Ethical issuesReview the pros and cons of glob.docx
 
500 words APA formatHow much impact do managers actually have on a.docx
500 words APA formatHow much impact do managers actually have on a.docx500 words APA formatHow much impact do managers actually have on a.docx
500 words APA formatHow much impact do managers actually have on a.docx
 
5.2Complete one of the following options for your Week 5 Assignm.docx
5.2Complete one of the following options for your Week 5 Assignm.docx5.2Complete one of the following options for your Week 5 Assignm.docx
5.2Complete one of the following options for your Week 5 Assignm.docx
 
5.1 DBDisparities exist among racial and ethnic groups with rega.docx
5.1 DBDisparities exist among racial and ethnic groups with rega.docx5.1 DBDisparities exist among racial and ethnic groups with rega.docx
5.1 DBDisparities exist among racial and ethnic groups with rega.docx
 
5. What are the most common types of computer-based information syst.docx
5. What are the most common types of computer-based information syst.docx5. What are the most common types of computer-based information syst.docx
5. What are the most common types of computer-based information syst.docx
 
5.2 - Postwar Commercial AviationIn this discussion activity, .docx
5.2 - Postwar Commercial AviationIn this discussion activity, .docx5.2 - Postwar Commercial AviationIn this discussion activity, .docx
5.2 - Postwar Commercial AviationIn this discussion activity, .docx
 
5-6 paragraphsYou and Officer Landonio are on patrol. Yo.docx
5-6 paragraphsYou and Officer Landonio are on patrol. Yo.docx5-6 paragraphsYou and Officer Landonio are on patrol. Yo.docx
5-6 paragraphsYou and Officer Landonio are on patrol. Yo.docx
 
5-6 paragraphs Interagency is relatively recent as a term, y.docx
5-6 paragraphs Interagency is relatively recent as a term, y.docx5-6 paragraphs Interagency is relatively recent as a term, y.docx
5-6 paragraphs Interagency is relatively recent as a term, y.docx
 
5-6 paragraphsTerrorism in the United States has a history d.docx
5-6 paragraphsTerrorism in the United States has a history d.docx5-6 paragraphsTerrorism in the United States has a history d.docx
5-6 paragraphsTerrorism in the United States has a history d.docx
 
5-6 paragraphsAPA styleIn 2010, plans were announced for the.docx
5-6 paragraphsAPA styleIn 2010, plans were announced for the.docx5-6 paragraphsAPA styleIn 2010, plans were announced for the.docx
5-6 paragraphsAPA styleIn 2010, plans were announced for the.docx
 
5-7 paragraphs How do you think cooperation and cross-jurisdicti.docx
5-7 paragraphs How do you think cooperation and cross-jurisdicti.docx5-7 paragraphs How do you think cooperation and cross-jurisdicti.docx
5-7 paragraphs How do you think cooperation and cross-jurisdicti.docx
 
5-1 Discussion Oil SpillsOn April 20, 2010, there was an explosio.docx
5-1 Discussion Oil SpillsOn April 20, 2010, there was an explosio.docx5-1 Discussion Oil SpillsOn April 20, 2010, there was an explosio.docx
5-1 Discussion Oil SpillsOn April 20, 2010, there was an explosio.docx
 
5 Pages 1.Briefly define the concept of Black Nationalism.  .docx
5 Pages 1.Briefly define the concept of Black Nationalism.  .docx5 Pages 1.Briefly define the concept of Black Nationalism.  .docx
5 Pages 1.Briefly define the concept of Black Nationalism.  .docx
 
5 page, (NO MORE, NO LESS) double space only, and 14pt font, assessi.docx
5 page, (NO MORE, NO LESS) double space only, and 14pt font, assessi.docx5 page, (NO MORE, NO LESS) double space only, and 14pt font, assessi.docx
5 page, (NO MORE, NO LESS) double space only, and 14pt font, assessi.docx
 
400–500 words including a chart (APA Format) Knowing that the co.docx
400–500 words including a chart (APA Format) Knowing that the co.docx400–500 words including a chart (APA Format) Knowing that the co.docx
400–500 words including a chart (APA Format) Knowing that the co.docx
 
400-600 wordsThe new detective you are assisting is interest.docx
400-600 wordsThe new detective you are assisting is interest.docx400-600 wordsThe new detective you are assisting is interest.docx
400-600 wordsThe new detective you are assisting is interest.docx
 

the_proj_main.asm;; the_proj_main.asm;; Created 231

  • 1. 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
  • 2. .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
  • 3. .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
  • 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
  • 10. block2: 0x6C,0x6D,0x6E,0x6F,0x70,0x71,0 x72,0x73 block3: 0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B __MACOSX/._the_proj_main.asm