a Consider the following program execute one instruction at
a. Consider the following program, execute one instruction at a time and list content of the R20 register. ldi r20, 0xBA Isr r20 lsr r20 lsr r20 lsr r20 lsr r20
Solution
(a)
ldi r 20, 0xBA ; Load Immediate BA (binary = 10111010) in r20
lsr r20 ; Logical Shift Right- Shifts all bits in Rd one place to the right. Bit 7 is cleared. Bit 0 is loaded into the C flag. This operation effectively divides an unsigned value by two. Thus r20 value
after instruction operation
lsr r20 ;
after instruction operation
lsr r20 ;
after instruction operation
lsr r20 ;
after instruction operation
lsr r20 ;
after instruction operation
(b) Program
convert decimal number in hex; Decimal 255 = hex FF
ldi r 20, 0xFF ; Load immediate FF (Decimal 255)
Loop:
SUBI r20, 04H ; Subtract imediate by 04 ie r20 = r20 - 04
rjump Loop ; jump to Loop
This will give result 255, 251, 247, 243...... (all numbers in decimal)
| 1 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | C =0 |
