Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using AVR Assembly Language: A.) Add and subtract two numbers showing result in

ID: 3842256 • Letter: U

Question

Using AVR Assembly Language:

A.) Add and subtract two numbers showing result in a register.
B.) Multiply two numbers showing result in a register.
C.) Negate a register and set bits in a register.
D.) Clear a register.
E.) Transfer a number from a register to an SRAM location.
F.) Transfer a number from an SRAM location to a register.
G.) Copy one register to another.
H.) Conditionally branch to another part of the code.
I.) Unconditionally branch or jump to another part of the code.
J.) Set and Clear the carry bit in the status register.
K.) Swap the two nibbles of an 8-bit register.

Explanation / Answer

A.)

.DEF A = R16        ;Set “A” to Register 16 (R16)

.DEF B = R18        ;Set “B” to Register 18 (R18)  

      LDI A,1        ;Store value of one in R16

      LDI B,1       ;Store value of 48 in R18

      ADD A,B        ;Add the value stored in B to the value stored in A (A=A+B).

B.)

.DEF ANSL = R0            ;To hold low-byte of answer    

.DEF ANSH = R1            ;To hold high-byte of answer

.DEF    A = R16           ;To hold multiplicand

.DEF    B = R18           ;To hold multiplier

        LDI A,42          ;Load multiplicand into A

        LDI B,10          ;Load multiplier into B

        MUL A,B           ;Multiply contents of A and B and Result 420 left in ANSL and ANSH

C.)

.DEF    A = R16           ;To hold multiplicand

        LDI A,42          ;Load multiplicand into A

        NEG A           ;Change A = 0 - A

D.)

.DEF N = R0         ;Define “N” as Register Zero

      CLR N          ;CLear Register N to all zeros

E.) Transfer a number from a register to an SRAM location.

Ld R5, X           ;R5 = mem[X]

F.) Transfer a number from an SRAM location to a register.

ST X, R5           ;mem[X] = R5
G.) Copy one register to another.

MOV R19, R20                        ;R19 = R20
H.) Conditionally branch to another part of the code.

BRGE LABEL                ;if regA>RegB, goto LABEL
I.) Unconditionally branch or jump to another part of the code.

JMP LABEL                  ;Goto LABEL
J.) Set and Clear the carry bit in the status register.

ADD R0, R0     ;Add R0 to itself

CLC                  ; Clear carry flag
K.) Swap the two nibbles of an 8-bit register.

INC R1                         ; Increment R1

SWAP R1         ; Swap high and low nibble of R1

INC R1                         ; Increment high nibble of R1

SWAP R1         ; Swap back

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote