Question

In: Computer Science

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 < 3

C = A+B
elseif D < 5
C = A - B
else
C = A + 8*B

Solutions

Expert Solution

a.)

MOV R3,D    //moves the value from D to R3

MOV R0,A    //moves the value from A to R0

MOV R1,B    //moves the value from B to R1

MOV R2,C    //moves the value from C to R2

CMP R3,00   //compares R3 with 0

JMP less    // if less then go to "less" section

SUB R0,R1   //else R0=R0-R1

MOV R2,R0   //move the value from R0 to R2

less: ADD R0,R1        //add R0=R0+R1

        MOV R2,R0      //move the value from R0 to R2

b.)

MOV R3,D      //moves the value from D to R3

MOV R0,A      //moves the value from A to R0

MOV R1,B      //moves the value from B to R1

MOV R2,C      //moves the value from C to R2

CMP R3,3     // compare R3 with 3

JMP less3    //jump to "less3" if R3<3
 
CMP R3,5     //compare R3 with 5

JMP less5    //jump to "less3" if R3<5

MOV AX,8     //else move 8 into accumulator to perform multiplication

MUL R1       //multiply R1 with accumulator AX=AX*R1

MOV R1,AX    //move the value from AX to R1

ADD R0,R1     //add R0and R1 and store thr result in R0

MOV R2,R0     //finally move the value from R0 to R2

less3: ADD R0,R1

       MOV R2,R0

less5: SUB R0,R1

       MOV R2,R0

Related Solutions

Complete the AVR assembly language fragment below so that it does a multiply by 2 of...
Complete the AVR assembly language fragment below so that it does a multiply by 2 of the two's complement 32-bit quantity in registers r18:r19:r20:r21. (r18 is the most significant byte.) asrlsrlslaslrolrorr18r19r20r21  asrlsrlslaslrolrorr18r19r20r21 asrlsrlslaslrolrorr18r19r20r21  asrlsrlslaslrolrorr18r19r20r21 asrlsrlslaslrolrorr18r19r20r21  asrlsrlslaslrolrorr18r19r20r21 asrlsrlslaslrolrorr18r19r20r21  asrlsrlslaslrolrorr18r19r20r21
Complete the AVR assembly language fragment below so that it performs a division by 2 of...
Complete the AVR assembly language fragment below so that it performs a division by 2 of the 24-bit two's complement value in registers r6:r5:r4. (r6 is the most significant byte.) lslasllsrasrrolrorr4r5r6  lslasllsrasrrolrorr4r5r6 lslasllsrasrrolrorr4r5r6  lslasllsrasrrolrorr4r5r6 lslasllsrasrrolrorr4r5r6  lslasllsrasrrolrorr4r5r6
MIPS ASSEMBLY LANGUAGE (I'm using MARS) Can you provide me with the code of this, without...
MIPS ASSEMBLY LANGUAGE (I'm using MARS) Can you provide me with the code of this, without using DIV (4a-b)%[(2+c)/d] (a,b,c,d are user inputs)
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-
You can use any language. You have to provide all the data, output and input. You...
You can use any language. You have to provide all the data, output and input. You are to use Linked Lists to do this Program. The XYZ Widget store receives shipments of widgets at various costs. The store’s policy is to charge a 30% markup, and to sell widgets which were received earlier before widgets which were received later. This is called a FIFO policy. Write a program using linked lists that reads in three types of input data and...
For the PIC16F887, using the execution delay of instructions, write assembly language commands to implement a...
For the PIC16F887, using the execution delay of instructions, write assembly language commands to implement a delay of 3 seconds
Use MARS to write and simulate a MIPS assembly language program to implement the strlen function....
Use MARS to write and simulate a MIPS assembly language program to implement the strlen function. The program should ask for a user's input and print the length of the user's input. Write the main function to call strlen. The main function should: - Prompt the user for input - Pass that input to strlen using registers $a0. - Preserve (i.e. push onto the stack) any T registers that the main function uses. The strlen function should: - Preserve any...
Convert the following C++ statements to an ARM assembly language program: const int size = 10;...
Convert the following C++ statements to an ARM assembly language program: const int size = 10; int x[size] = {8, 2, 9, 6, 7, 0, 1, 3, 5, 4}; int y[size] = {399, -87, 12, 0, 42, -367, 57, 92, -1000, 25}; for i = 0; i < size; i++) if (x([ i ] > y[ i ]) z[ i ] = 0 else z[ i ] = 1;
Assembly Language Programming Construct an assembly language program fragment equivalent to the following C/C++ statement: if...
Assembly Language Programming Construct an assembly language program fragment equivalent to the following C/C++ statement: if (M <= N + 3 && (C == ‘N’ || C == ‘n’)) C = ‘0’; else C = ‘1’; Assume that M and N are 32-bit signed integer variables, and C is an 8-bit ASCII character variable. All variables are stored in memory, and all general-purpose registers are available for use.
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT