Question

In: Computer Science

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

Solutions

Expert Solution

Complete the provided following AVR assembly code to multiply the 2's complement 32-bit quantity number by two which is stored in the register r18:r19:r20:r21:

Answer:

LSL r21

ROL r20

ROL r19

ROL r18

Description:

• ROL: Rotate Left trough Carry

Format: ROL Rd

The rol - Rotate Left trough Carry instruction shifts all the bits of the provided register Rd one place to the left side. The carry flag will be loaded at bit 0 and bit 7 will be loaded at Carry flag.

• LSL: Logical Shift Left

Format: LSL Rd

The lsl - Logical Shift Left instruction logically shifts all the bits of the provided register Rd one place to the left side. Bit 0 will be cleared i.e. 0 and bit 7 will be placed at Carry flag.

Example:

• Lets take an example in which want to multiply (-4) value.

• So, the 32-bit 2's complement representation of -4 is: 1111 1111 1111 1111 1111 1111 1111 1100

r21 = 1111 1100

r20 = 1111 1111

r19 = 1111 1111

r18 = 1111 1111 (Most Significant Byte)

LSL r21 ; Logical Shift Left r21 register. Register r21 = 1111 1000 with carry flag = 1.

ROL r20 ; Rotate Left trough Carry r20 register. Register r20 = 1111 1111 with carry flag = 1.

ROL r19   ; Rotate Left trough Carry r19 register. Register r19 = 1111 1111 with carry flag = 1.

ROL r18 ; Rotate Left trough Carry r18 register. Register r18 = 1111 1111 with carry flag = 1.

• Thus, r18:r19:r20:r21 = 1111 1111 1111 1111 1111 1111 1111 1000 (-8).

• So, the result of the above code is the multiplication result of (-4) * 2 = (-8).


Related Solutions

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
The following code fragment is expressed in arm assembly code.Fill in the blanks, so that...
The following code fragment is expressed in arm assembly code. Fill in the blanks, so that it is equivalent to the following C code.int counter;int x = 5;int y = 6;for (counter =10; counter >0;counter--)IF(X==Y)Y = Y + 1 ;ELSEY = Y + 2}Fill in the blanks in the following code:MOV__________ ;loop counter into r0-ten times round the loopMOV__________ ;Value of y loaded into r1MOV__________ ;Value of x loaded into r2Next CMP ____________ ;assume r1 contains y and r2 contains...
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 <...
The following code fragment is expressed in arm assembly code. Fill in the blanks, so that...
The following code fragment is expressed in arm assembly code. Fill in the blanks, so that it is equivalent to the following C code. int counter; int x = 5; int y = 6; for (counter =10; counter >0;counter--) IF(X==Y) Y = Y + 1 ; ELSE Y = Y + 2} Fill in the blanks in the following code: MOV__________ ;loop counter into r0-ten times round the loop MOV__________ ;Value of y loaded into r1 MOV__________ ;Value of x...
Please complete in MASM (x86 assembly language). Use the code below to get started. Use a...
Please complete in MASM (x86 assembly language). Use the code below to get started. Use a loop with indirect or indexed addressing to reverse the elements of an integer array in place. Do not copy the elements to any other array. Use the SIZEOF, TYPE, and LENGTHOF operators to make the program as flexible as possible if the array size and type should be changed in the future. .386 .model flat,stdcall .stack 4096 ExitProcess PROTO,dwExitCode:DWORD .data    ; define your...
Given the below pseudocode, write the proper code that implements it using MARIE's assembly language:               ...
Given the below pseudocode, write the proper code that implements it using MARIE's assembly language:                    Input a number and store it in X; if X > 1 then    Y := X + X;    X := 0; endif; Y := Y + 1; Output the value of Y; N.B: You should include the MARIE code in your Answer, with an explanation of each instruction in your code beside it. Example:              Subt One         /Subtract 1 from AC Add a...
Write an MSP430 assembly language program that implements the following 2 algorithms: 2) a macro called...
Write an MSP430 assembly language program that implements the following 2 algorithms: 2) a macro called "vdot" that calculates the "dot product" of two vectors "a" and "b", implemented as “arrays” (following the “C” language convention), of 3 elements. the macro should receive 2 pointers to the first element of each vector and return the result in R13.
Write a program named subtract.asm that does the following using LC3 assembly language: Print a prompt...
Write a program named subtract.asm that does the following using LC3 assembly language: Print a prompt "PRESS TWO KEYS: " Note that the prompt MUST LOOK EXACTLY like the above, with a colon and a space after the word KEYS with no newline. Get a two key press from the user. Subtract the second characters ASCII code from the first characters ASCII code. If the result is positive, print the word POSITIVE. Turn in subtract.asm to the appropriate submission point...
Use the Python programming language to complete below (I need the New Answer for this, and...
Use the Python programming language to complete below (I need the New Answer for this, and please provide the screenshot of the source code. Thank you!): A website requests an user to input his account password. Write a program to examize the validity of the password. The valid password must consists of: At least 1 letter in [a-z] At least 1 number in [0-9] At least a letter in [A-Z] (capital) At least one special letter in [$#@] At least...
Use the Python programming language to complete below (I need the New Answer for this, and...
Use the Python programming language to complete below (I need the New Answer for this, and please provide the screenshot of the source code. Thank you!): Write a function to seek for all even numbers and odd numbers in the middle of two number A and B. Print even and odd numbers in 1 and 2020 (including both these two numbers)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT