Question: I am trying to program an assembly code in avr to store all numbers between 25-256. After that I want to go through every number
I am trying to program an assembly code in avr to store all numbers between 25-256. After that I want to go through every number and compare if it divisibly by 7 or by 3 or divisible by both 7 and 3 or not divisible by 3 or 7.
I want to store a sum of the 4 different occurrence in a register but I am stuck and don't know how to do the program correctly. I have included what I have coded so far and would value the help of fixing my code to preform the above description that I explained.
.org 0
LDI R23, 7 LDI R16, 0x18 LDI R24, 3 LDI R20, 7 LDI R22, 3 LOOP: st x+,r16 ; store indirect and post-increment x inc r16 ; increments the counter by 1 LDI R23, 0x07 LDI R24, 0x03 RJMP DIV7 cpi r16,0x20 ; have we reached beyond the range of numbers that we want to print? brne loop ; if we haven't, loop again DIV7: ADD R23, R20 CP R23, R16 BRLT DIV7 ;if Less Than ;if not equal and not more than loop again RJMP ADD7 DIV3: ADD R24, R22 CP R24, R16 BRLT DIV3 BRNE NOTEQ RJMP ADD3 NOTEQ: ST X+, r21 RJMP LOOP ADD7: RJMP DIV3 ST Y+, r26 BRNE DIV3 ADD3: RJMP DIV7 ST Z+, r25 BOTH: DEC R0
*note please stick with using the X, Y and Z registers, other then that you can change whatever fixes my code. Also just so you know I am compiling using AtmelStudio 7
Thank you so much in advanced
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
