Perform the following on the register R0 with the data 10101100:
(a) Logical Left Shift
(b) Logical Right Shift
(c) Arithmetic Left Shift
(d) Arithmetic Right Shift
(e) Rotate Left without Carry
(f) Rotate Right without Carry
(g) Rotate Left with Carry
(h) Rotate Right with Carry
Let's analyze each operation step-by-step, starting with the initial data:
**Initial data in R0:** 1010 1100 (binary)
**In decimal:** 172
---
### (a) Logical Left Shift
- Shifts all bits to the left by 1.
- The least significant bit (LSB) becomes 0.
- The most significant bit (MSB) is shifted out and lost.
**Result:**
Original: 1 0 1 0 1 1 0 0
Shifted: 0 1 0 1 1 0 0 0
**Binary:** `01011100`
**Decimal:** 124
---
### (b) Logical Right Shift
- Shifts all bits to the right by 1.
- The MSB is filled with 0 (logical shift).
- The least significant bit (LSB) is shifted out.
**Result:**
Original: 1 0 1 0 1 1 0 0
Shifted: 0 1 0 1 0 1 1 0
**Binary:** `01010110`
**Decimal:** 86
---
### (c) Arithmetic Left Shift
- Same as logical left shift: bits shifted left, MSB shifted out, LSB becomes 0.
- Since it's a left shift, the operation behaves the same as logical left shift.
**Result:**
`01011100` (binary)
**Decimal:** 124
---
### (d) Arithmetic Right Shift
- Shifts bits to the right by 1.
- The MSB is preserved (replicated) to maintain the sign for signed numbers.
**Original MSB:** 1 (indicating negative in signed 8-bit)
**Result:**
Original: 1 0 1 0 1 1 0 0
Shifted: 1 1 0 1 0 1 1 0
**Binary:** `11010110`
**Decimal:** -42 (if interpreted as signed 8-bit)
---
### (e) Rotate Left without Carry
- Rotate bits to the left by 1.
- The MSB moves to the LSB position.
**Original:** 1 0 1 0 1 1 0 0
**Result:**
Rotate left:
MSB (1) moves to LSB:
New: 0 1 0 1 1 0 0 1
**Binary:** `01011001`
**Decimal:** 89
---
### (f) Rotate Right without Carry
- Rotate bits to the right by 1.
- The LSB moves to the MSB position.
**Original:** 1 0 1 0 1 1 0 0
**Result:**
LSB (0) moves to MSB:
New: 0 1 0 1 0 1 1 0
**Binary:** `01010110`
**Decimal:** 86
---
### (g) Rotate Left with Carry
- Assume initial carry is 0.
- Rotate bits left; the bit shifted out into carry becomes the new carry.
- The previous carry enters at the LSB position.
**Initial Carry:** 0
**Result:**
Bits rotated left:
MSB (1) moves into carry, carry (0) goes into LSB
New carry: 1 (MSB of original)
New data: 0 1 0 1 1 0 0 0
**Binary:** `01011000`
**Carry out:** 1
---
### (h) Rotate Right with Carry
- Assume initial carry is 0.
- Rotate bits right; the bit shifted out into carry becomes the new carry.
- The previous carry enters at the MSB position.
**Initial Carry:** 0
**Result:**
LSB (0) moves into carry, carry (0) into MSB
New carry: 0 (LSB of original)
New data: 1 0 1 0 1 1 0 0
**Binary:** `01011000` (same as in (g) with initial carry 0)
**Carry out:** 0
---
**Summary:** ** Initial data in R0:** 1010 1100 (binary)
| Operation | Result (binary) | Decimal | Notes |
|----------------------------------|-----------------|---------|----------------------------------------|
| (a) Logical Left Shift | 01011100 | 124 | Bits shifted left, fill with 0 |
| (b) Logical Right Shift | 01010110 | 86 | Bits shifted right, fill with 0 |
| (c) Arithmetic Left Shift | 01011100 | 124 | Same as logical left shift |
| (d) Arithmetic Right Shift | 11010110 | -42 | Sign bit preserved |
| (e) Rotate Left without Carry | 01011001 | 89 | MSB rotated to LSB |
| (f) Rotate Right without Carry | 01010110 | 86 | LSB rotated to MSB |
| (g) Rotate Left with Carry | 01011000 | 88 | Carry out: 1 |
| (h) Rotate Right with Carry | 01011000 | 88 | Carry out: 0 |
---
1. Registers R1 and R2 of a computer contain the decimal values 1200 and 4600. What is the
effective address of the memory operand in each of the following instructions?
(a) Load 20(R1), R5
(b) Move #3000, R5
(c) Store R5, 30(R1, R2)
(d) Add -(R2), R5
(e) Subtract (R1)+, R5
Let's analyze each instruction step-by-step, considering the contents of registers R1 and R2, and the
addressing modes.
Given:
- R1 = 1200 (decimal)
- R2 = 4600 (decimal)
---
### (a) Load 20(R1), R5
**Addressing mode:** Base + displacement
- Base register: R1 = 1200
- Displacement: 20
**Effective address:**
\[ \text{Effective address} = R1 + 20 = 1200 + 20 = \boxed{1220} \]
---
### (b) Move #3000, R5
**Addressing mode:** Immediate value (the "#" indicates immediate data)
- The data is the value 3000, not an address.
**Effective address:**
Since it's immediate data, it doesn't refer to memory address but the value itself:
\[ \boxed{\text{Immediate value } 3000} \]
---
### (c) Store R5, 30(R1, R2)
**Addressing mode:** Indexed with multiple registers (base + index + displacement)
- R1 = 1200
- R2 = 4600
- Displacement: 30
**Effective address:**
\[ \text{Effective address} = R1 + R2 + 30 = 1200 + 4600 + 30 = \boxed{5830} \]
---
### (d) Add -(R2), R5
**Addressing mode:** Pre-decrement (the minus sign indicates pre-decrement)
- Before the operation, R2 is 4600.
- R2 is decremented before memory access.
Assuming the decrement is by 1 (common in such addressing modes), but since no specific size is
given, typically it's by the size of the operand (say, 4 bytes). But unless specified, we assume
decrement by 1.
**Effective address:**
\[ R2_{new} = R2 - 1 = 4600 - 1 = 4599 \]
**Memory to be accessed at address:** 4599.
---
### (e) Subtract (R1)+, R5
**Addressing mode:** Post-increment (the plus sign indicates post-increment)
- The address used: current R1 = 1200
- After the operation, R1 is incremented by the size of the operand (say, 4 bytes).
**Effective address:**
\[ \text{Address} = R1 = 1200 \]
**Post-operation, R1:**
\[ R1_{new} = R1 + 4 = 1204 \]
## **Summary of effective addresses:**
| Instruction | Effective Address |
|---------------|---------------------|
| (a) Load 20(R1), R5 | **1220** |
| (b) Move #3000, R5 | Immediate value 3000 (not an address) |
| (c) Store R5, 30(R1, R2) | **5830** |
| (d) Add -(R2), R5 | Address **4599** (after decrement) |
| (e) Subtract (R1)+, R5 | Address **1200** (before increment) |
2. Register R5 is used in a program to point to the top of a stack. Write a sequence of
instructions using the Index, Auto-increment and Auto-decrement addressing modes to
perform each of the following tasks:
(a) Pop the top two items off the stack, add them and then push the result onto the stack.
(b) Copy the fifth item from the top into the register R3.
(c) Remove the top items from the stack.
; (a) Pop two, add, push result
MOV @+R5, R1
MOV @+R5, R2
ADD R1, R2, R3
MOV R3, @-R5
; (b) Copy fifth item from top into R3
MOV 4(R5), R3
; (c) Remove top 3 items
ADD R5, #3, R5