4.2 Assembly Language (3)

Resources | Revision Questions | Computer Science

Login to see all questions

Click on a question to view the answer

1.

Consider a simple assembly language instruction set with the following addressing modes: register addressing, direct addressing, and indirect addressing. Write assembly code to perform the following operations:

  • Add the contents of register R1 to the contents of memory location 1000 and store the result in register R2.
  • Load the value stored at memory location 2000 into register R3.
  • Add the value stored at memory location 3000 to the value stored at memory location 2000 and store the result in register R4.
  • Load the value at the address stored in register R5 into register R6.
Assume R1, R2, R3, R4, R5, and R6 are registers. Provide the assembly code for each operation, clearly indicating the addressing mode used.
2.

The following assembly program calculates the sum of two numbers. The numbers are stored in memory locations 'num1' and 'num2'. Trace the execution, showing the register contents and memory contents at each step. Assume the program uses a single accumulator register (ACC) and a temporary register (TEMP). Assume the program starts with ACC = 0, TEMP = 0, num1 = 12, and num2 = 8.

    LOAD num1, ACC  ; Load the value from memory location num1 into ACC
    LOAD num2, TEMP  ; Load the value from memory location num2 into TEMP
    ADD ACC, TEMP   ; Add the value in TEMP to ACC
    STORE ACC, RESULT ; Store the value in ACC to memory location RESULT
  
3.

Explain how the choice of addressing mode can impact the efficiency of a program. Discuss scenarios where one addressing mode would be preferred over another, considering factors such as speed, memory usage, and code size. Provide specific examples to illustrate your points.