Processor Fundamentals and Assembly Language: Question 5
Syllabus 4.2
A processor's instruction set includes the indirect-addressing instruction LDI <address>,
which loads into ACC the contents of the address that is itself stored at <address> (rather
than the contents of <address> directly, as LDD <address> would). It also includes OUT,
which sends the character whose ASCII value is currently held in ACC to the screen.
Some ASCII character codes: 65 represents the character 'A'.
The contents of main memory before the program runs are:
| Address | 70 | 80 |
|---|---|---|
| Data | 80 | 65 |
The program stored in memory is:
30 LDI 70
31 OUT
32 END
(a) Explain how the indirect addressing used by LDI 70 finds the value that is loaded into
ACC, referring to address 70 and address 80 in this scenario. [2]
(b) Trace the execution of this program, stating the value held in ACC after each instruction executes. [2]
(c) State the character that is output when this program runs, and identify which instruction is responsible for producing this output. [2]
Show worked solution Hide worked solution
Worked solution
Part (a): How indirect addressing works here
LDI 70 does not load the contents of address 70 directly into ACC. Instead, address 70 is
treated as holding a pointer: its contents (80) are themselves used as a second address. The
value actually loaded into ACC is the contents of this second address, address 80, which is
65. So LDI 70 follows the pointer stored at address 70 to reach address 80, and loads the value
found there.
[2 marks]: 1 for identifying that the contents of address 70 (80) are used as a second address rather than as the value itself, 1 for correctly identifying that the value loaded is the contents of address 80 (65).
Part (b): Tracing the program
LDI 70→ ACC = contents of the address stored at address 70 = contents of address 80 = 65.OUT→ ACC is unchanged at 65; the character with ASCII value 65 is sent to the screen.END→ ACC is unchanged at 65; the program stops.
[2 marks]: 1 for ACC = 65 after LDI 70, 1 for ACC remaining unchanged at 65 through OUT
and END.
Part (c): The output character
Since ACC holds 65 when OUT executes, and 65 represents the character ‘A’, the program outputs
‘A’. This output is produced by the OUT instruction at address 31. LDI 70 only loads the
value into ACC, and does not itself produce any output.
[2 marks]: 1 for the character ‘A’, 1 for identifying OUT as the instruction that produces
the output.
Final answers
- (a)
LDI 70uses the contents of address 70 (80) as a second address, then loads the contents of that second address (65) into ACC. - (b) ACC = 65 after
LDI 70; unchanged at 65 afterOUTandEND. - (c) The character ‘A’ is output, produced by the
OUTinstruction.