In: Computer Science
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 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).