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
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...
3) Consider the following IA32 assembly language code fragment. Assume that a, b and c are...
3) Consider the following IA32 assembly language code fragment. Assume that a, b and c are integer variables declared in the data segment. movl a, %eax movl b, %ebx cmpl %ebx, %eax jge L1 movl %eax, %ecx jmp L2 L1: movl %ebx, %ecx L2: movl %ecx, c Write the C code which is equivalent to the above assembly language code. You don't need to include the variable declarations, a function or anything like that, just show the 1 to 4...
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...
Construct an assembly language program fragment equivalent to the following C/C++ statement: if (M <= N...
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.
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...
ASSEMBLY LANGUAGE PROGRAMMING Q:Write a complete assembly program that inputs a small signed integer n, whose...
ASSEMBLY LANGUAGE PROGRAMMING Q:Write a complete assembly program that inputs a small signed integer n, whose value can fit within 8 bits, and outputs the value of the expression n2 – n + 6.
Complete the corresponding assembly language fragments by selecting the correct instruction, register, or value: (Choices in...
Complete the corresponding assembly language fragments by selecting the correct instruction, register, or value: (Choices in bold) a) Consider the following fragment of C code: if(a == b) {        x += 10;        A[50] = A[50] +x; } else {         y += 10;         A[50] = A[50] + y; } Assume that variables a, b, x and y are assigned to $s0, $s1, $s2 and $s3 respectively and the base address for array A is in $s4. Only...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT