Question

In: Computer Science

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

Solutions

Expert Solution

Complete the following AVR assembly language code to divide 24-bit two's complement value by two that is stored in registers r6:r5:r4:

Answer:

ASR r6

ROR r5

ROR r4

Description:

• ASR: Arithmetic Shift Right

ASR Rd - The asr instruction shifts all the bits of the register Rd one place to the right side. Bit 7 will be held constant and bit 0 will be loaded into Carry flag.

• ROR - Rotate Right through Carry

ROR Rd - The ror instruction shifts all the bits of the register Rd one place to the right side. Carry flag will be shifted at bit 7 and bit 0 will be shifted at Carry flag.

Example:

• Consider the following example where we want to divide (-4) by two.

• 24-bit signed or 2's complement value: 1111 1111 1111 1111 1111 1100 (-4).

r6 = 1111 1111 (most significant byte)

r5 = 1111 1111

r4 = 1111 1100

ASR r6 ; Arithmetic Shift Right the r6 register. Now r6 = 1111 1111 with Carry = 1

ROR r5 ; Rotate Right through Carry r5 register. Now r5 = 1111 1111 with Carry = 1

ROR r4 ; Rotate Right through Carry r4 register. Now r4 = 1111 1110  with Carry = 0

• r6:r5:r4 = 1111 1111 1111 1111 1111 1110 (-2)

• So, we get the division of (-4) by two as (-2).


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
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 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...
Write an x86 assembly language program that performs equivalently to the C++ source code file shown...
Write an x86 assembly language program that performs equivalently to the C++ source code file shown below.Please note that commented out behavior must be implemented in x86 assembly language. There is no standard, portable way to perform some of these actions in C++. #include void main() { // Use registers for these in your x86 assembly language program // Only use the .data segment for string (character array) variables int eax; int esi; int ecx; int edi; // Loop the...
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.
My question below Write a complete program that performs encryption/decryption of a text file. Encryption means...
My question below Write a complete program that performs encryption/decryption of a text file. Encryption means you need to scramble the words of a file to become secure. Decryption means you need to apply some rules to an encrypted file in order to find the original file with its original content. An example of encryption is to replace each letter in a file with its consecutive letter in the alphabet. Therefore, ‘a’ is replaced by ‘b’, ‘b’ is replaced by...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT