Question: Consider the AVR assembly code provided below. Read the code and use your knowledge of assembly instructions to answer the questions given at the bottom
Consider the AVR assembly code provided below. Read the code and use your knowledge of assembly
instructions to answer the questions given at the bottom of this page.
.EQU var1 = 0b11011010
.EQU var2 = 8
.DEF count = r17
.ORG 0x0000
init:
RJMP init
.ORG 0x0046
LDI XH, HIGH(resultA)
LDI XL, LOW(resultA)
LDI YH, HIGH(resultB)
LDI YL, LOW(resultB)
CLR r10
LDI r20, var1
LDI count, var2
loop:
skip:
CLC
ROR r20
BRCC skip
INC r1
ROL r10
done:
.DSEG
DEC count
BRNE loop
ST X, r10 ST Y+, r1
RJMP done
.ORG 0x03FE
resultA: .BYTE 1 resultB: .BYTE 1
Answer the following questions (assuming that the code has executed and reached the done label):
-
(a) What is the decimal value of the count register?
-
(b) In total, how many times is the instruction ROR r20 executed?
-
(c) What are the hexadecimal values of r27 and r26?
-
(d) What are the hexadecimal values of r29 and r28?
-
(e) What hexadecimal address does the assembler assign to the label resultB?
-
(f) What 8-bit binary value is stored in SRAM at the memory location specified by resultA?
-
(g) What decimal value is stored in SRAM at the memory location specified by resultB?
Now, suppose that the entire program is executed again, with one small difference. Assume that the first line of the program is replaced with: .EQU var1 = 0b10101010 Assuming that the code has executed and reached the done label:
-
(h) What 8-bit binary value is stored in SRAM at the memory location specified by resultA?
-
(i) What decimal value is stored in SRAM at the memory location specified by resultB?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
