Consider a computer that has a number of registers such that the three registers R0 = 1500, R1 = 4500, and R2 = 1000. Show the effective address of memory and the registers’ contents in each of the following instructions (assume that all numbers are decimal). (a) ADD (R0)+, R2 (b) SUBTRACT - (R1), R2 (c) MOVE 500(R0), R2 (d) LOAD #5000, R2 (e) STORE R0, 100(R2)

Answered on

(a) ADD (R0)+, R2 In this instruction, the content of register R0 points to a memory location. The effective address of the memory is 1500, which is the current content of R0. After the memory operand is accessed, R0 will be incremented by the size of the operand. The content from this memory location will be added to the content of R2.

Effective address of memory = 1500 (from R0 before incrementing) Updated content of R0 = 1500 + size of operand Final content of R2 = original content of R2 + value from memory address 1500

(b) SUBTRACT -(R1), R2 Here, R1 is first decremented by the size of the operand and then used to access the memory. The effective address of the memory is then R1 after it is decremented, and the content of this memory location is subtracted from the content of R2.

Effective address of memory = 4500 – size of operand (after R1 is decremented) Updated content of R1 = 4500 – size of operand Final content of R2 = original content of R2 – value from effective memory address

(c) MOVE 500(R0), R2 This instruction tells us to move the content from memory, pointed by the sum of the content of R0 and the immediate value 500, to R2. The effective address of the memory is the sum of R0 and 500.

Effective address of memory = 1500 + 500 = 2000 Content of R2 after the instruction = value from memory address 2000

(d) LOAD #5000, R2 The LOAD instruction with a "#" sign means an immediate value (not a memory address) is loaded directly into the register. Thus, R2 is loaded with the value 5000.

Effective address of memory: N/A (immediate value, no memory address) Content of R2 after instruction = 5000

(e) STORE R0, 100(R2) In this instruction, the content of R0 is stored into the memory location pointed by the sum of the content of R2 and the immediate value 100. The effective address where R0's content will be stored is R2 + 100.

Effective address of memory = original content of R2 (prior to any instruction changes) + 100 Content of R0 = 1500 (it doesn't change as it's being stored)

Please note, the actual memory values used by the instructions are not provided. The registers just point to those values. To give actual final contents of R2 or any changes to memory, we would need the original values which are being accessed.

Extra: Understanding how different addressing modes work is fundamental in computer architecture and assembly language programming. Various instructions use different addressing modes to access data either in registers or in memory. Here's a quick overview of the most relevant concepts:

- Register Direct Addressing: The instruction specifies the register containing the data or the operand. - Immediate Addressing: An operand within the instruction itself is to be used (denoted typically with a # sign). - Direct (or Absolute) Addressing: The instruction contains the direct memory address of the operand. - Indirect Addressing: The instruction specifies a register which contains the address of the operand in memory. Often denoted with parenthesis, e.g., (R0). - Indexed Addressing: The operand's effective address is the sum of an index value and the contents of a specified register.

Understanding these concepts allows one to grasp how instructions interact with the CPU's registers and the computer's memory to perform operations in an assembly language program. This knowledge is critical when working at a low level of software development and hardware interface.

Related Questions