Question

In: Computer Science

4. Explain what is happening on each line of the following AVR assembly code. If you...

4. Explain what is happening on each line of the following AVR assembly code. If you were to execute this code what would be the final decimal values in R20, R21 and SREG registers?
BCLR 0
BCLR 1
BCLR 2
BCLR 3
BCLR 4
BCLR 5
BCLR 6
BCLR 7
LDI ​R19, 0x02
LDI​R20, 0x74
LDI​R21, 0x04
LDI​R22, 0x22
ADD​R20, R22
SUB​R22, R21
ADD​R20, R21
MOV​R20, R21
JMP​DONE
ADD​R21, R20
SUB​R21, R22
DONE:​SUB​R20, R21

-embedded system-

Solutions

Expert Solution

Answer

BCLR 0 => Clearing 0th bit in SREG register (carry flag)

BCLR 1 => Clearing 1st bit in SREG register (Zero flag)

BCLR 2 => Clearing 2nd bit in SREG register (Negative flag)

BCLR 3 => Clearing 3rd bit in SREG register (Overflow flag)

BCLR 4 => Clearing 4th bit in SREG register (Sign flag)

BCLR 5 => Clearing 5th bit in SREG register (Half carru flag)

BCLR 6 => Clearing 6th bit in SREG register (Copy storage flag)

BCLR 7 => Clearing 7th bit in SREG register (Disables interrupt)

LDI ​R19, 0x02 => Loads value 0x02 in R19 => R19 = 0x02

LDI ​R20, 0x74 => Loads value 0x74 in R20 => R20 = 0x74

LDI​ R21, 0x04 => Loads value 0x04 in R21 => R21 = 0x04

LDI​ R22, 0x22 => Loads value 0x22 in R22 => R22 = 0x22

ADD​ R20, R22 => Add R20 and R22 and Store it into R20 => R20 = 0x74+0x22 = 0x96

SUB​ R22, R21 => Subtract R21 from R22 and store it into R22 => R22 = 0x22 - 0x04 = 0x1E

ADD​ R20, R21 => Add R20 and R21 and Store it into R20 => R20 = 0x96+0x04 = 0x9A

MOV ​R20, R21 => Move R21 value to R20 => R20 = 0x04

JMP​ DONE => Unconditional Jump

ADD ​R21, R20 => Skipped

SUB​ R21, R22 => Skipped

DONE:​ SUB​ R20, R21 => Subtract R21 from R20 and store it into R20 => R20 = 0x04 - 0x04 = 0x00

=> Enables Zero Flag in SREG register

Final Values :

R20 = 0x00
R21 = 0x04

SREG = 0x02


Related Solutions

analyze the assembly code and explain what each line is doing 000000000000063a <main>: 63a: 55 push...
analyze the assembly code and explain what each line is doing 000000000000063a <main>: 63a: 55 push ebp 63b: 48 89 e5 mov ebp,esp 63e: 48 83 ec 10 sub esp,0x10 642: c7 45 fc 00 00 00 00 mov DWORD PTR [ebp-0x4],0x0 649: eb 16 jmp 661 <main+0x27> 64b: 83 7d fc 09 cmp DWORD PTR [ebp-0x4],0x9 64f: 75 0c jne 65d <main+0x23> 651: 48 8d 3d 9c 00 00 00 lea edi,[eip+0x9c] # 6f4 <_IO_stdin_used+0x4> 658: e8 b3 fe...
Can you please explain in detail what each line of code stands for in the Main...
Can you please explain in detail what each line of code stands for in the Main method import java.util.Scanner; public class CashRegister { private static Scanner scanner = new Scanner(System.in); private static int dollarBills[] = {1, 2, 5, 10, 20, 50, 100}; private static int cents[] = {25, 10, 5, 1}; public static void main(String[] args) { double totalAmount = 0; int count = 0; for (int i = 0; i < dollarBills.length; i++) { count = getBillCount("How many $"...
HCS12 Assembly code please. Translate the following code into assembly. Allocate each variable on the stack....
HCS12 Assembly code please. Translate the following code into assembly. Allocate each variable on the stack. Simulate your program and screenshot the final value of the variables in memory. { char A,B,C; int F; A = 2; B = 6; C = - 10; F = (A + B)*C; C = F +10 }
The language is Assembly Language. Thank you! Assignment 3: Run the following code. Record what each...
The language is Assembly Language. Thank you! Assignment 3: Run the following code. Record what each of the flag changes are for each command. INCLUDE Irvine32.inc .data .code main PROC mov al,255 add al,1 call DumpRegs sub al,1 call DumpRegs sub al,1 call DumpRegs exit main ENDP END main
Provide Atmel AVR assembly language statements to implement the following pseudocodes. You can assume that all...
Provide Atmel AVR assembly language statements to implement the following pseudocodes. You can assume that all the variables A, B, C, D correspond to CPU general purpose registers as follows: A →R0, B→R1, C→R2, D→R3. You can also use additional registers from R4- R31 as needed. You must not use any variant of the multiplication instructions. Your assembly code segments should be properly commented. (a) if D < 0 C = A+B else C = A-B (b) if D <...
What is happening to the Georgian real exchange rate in each of the following situations? Explain....
What is happening to the Georgian real exchange rate in each of the following situations? Explain. a) Georgian nominal exchange rate is unchanged, but prices rise faster in Georgia than abroad. b) Georgian nominal exchange rate declines, and prices are unchanged in Georgia and abroad. c) Georgian nominal exchange rate declines, and prices rise faster abroad than in Georgia. d) Prices in Georgia decline and purchasing power parity holds. e) Prices abroad increase and purchasing power parity holds.
4.Translate the following C code to MIPS assembly code. Assume that the value of i is...
4.Translate the following C code to MIPS assembly code. Assume that the value of i is in register $t0, and $s0 holds the base address of the integer MemArray if (i > 10) MemArray[i] = 0; else MemArray[i] = -MemArray[i]; 6.Translate the following C code to MIPS assembly code. Use a minimum number of instructions. Assume that the values of a, b, i, and j are in registers $s0, $s1, $t0, and $t1, respectively. Also, assume that register $s2 holds...
Can you please explain to me what is happening in the line Update PRODUCT 11QER/31, P_QTYOH...
Can you please explain to me what is happening in the line Update PRODUCT 11QER/31, P_QTYOH from 47 to 46 like why 47 to 46 and no other number? in the code Lock INVOICE Insert row 10983 into INVOICE Unlock INVOICE Lock LINE Insert row 10983, 1 into LINE Unlock LINE Lock PRODUCT Update PRODUCT 11QER/31, P_QTYOH from 47 to 46 Unlock PRODUCT Lock CUSTOMER Update CUSTOMER 10010, CUS_BALANCE from 345.67 TO 464.47 Update CUSTOMER 10010, CUS_DATELSTPUR from 11-May-2016 to...
explain the code for a beginner in c what each line do Question 3. In the...
explain the code for a beginner in c what each line do Question 3. In the following code, answer these questions: Analyze the code and how it works? How can we know if this code has been overwritten? Justify how? #include <stdlib.h> #include <unistd.h> #include <stdio.h> int main(int argc, char **argv) { int changed = 0; char buff[8]; while (changed == 0){ gets(buff); if (changed !=0){ break;} else{     printf("Enter again: ");     continue; } }      printf("the 'changed' variable...
The following are to be completed using MIPS Assembly code. A.   Using syscall #4, display a...
The following are to be completed using MIPS Assembly code. A.   Using syscall #4, display a prompt for the user to enter a number. Then using syscall #5, get a decimal number from the user and save it to data memory (not into a register). After you have stored the number, display it back to the user as a 32-bit binary value. B.   Prompt the user to enter a decimal number and save it to data memory. Using addition and/or...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT