Chapter 6 Assembly Language-PPandMS-1617
Chapter 6 Assembly Language-PPandMS-1617
9 The table shows assembly language instructions for a processor which has one general purpose
register, the Accumulator (ACC) and an index register (IX).
Instruction
Explanation
Op code Operand
LDD <address> Direct addressing. Load the contents of the given address to ACC.
LDX <address> Indexed addressing. Form the address from <address> + the contents of the
index register. Copy the contents of this calculated address to ACC.
STO <address> Store contents of ACC at the given address.
DEC <register> Subtract 1 from the contents of the register (ACC or IX).
JPE <address> Following a compare instruction, jump to <address> if the compare was True.
JPN <address> Following a compare instruction, jump to <address> if the compare was
False.
JMP <address> Jump to the given address.
OUT Output to screen the character whose ASCII value is stored in ACC.
(a) The diagram shows the current contents of a section of main memory and the index register:
60 0011 0010
61 0101 1101
62 0000 0100
63 1111 1001
64 0101 0101
65 1101 1111
66 0000 1101
67 0100 1101
68 0100 0101
69 0100 0011
...
1000 0110 1001
Index register: 0 0 0 0 1 0 0 0
(i) Show the contents of the Accumulator after the execution of the instruction:
LDX 60
Accumulator:
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
(ii) Show the contents of the index register after the execution of the instruction:
DEC IX
Index register:
[1]
(b) Complete the trace table on the opposite page for the following assembly language program.
50 LDD 100
51 ADD 102
52 STO 103
53 LDX 100
54 ADD 100
55 CMP 101
56 JPE 58
57 JPN 59
58 OUT
59 INC IX
60 LDX 98
61 ADD 101
62 OUT
63 END
...
100 20
101 100
102 1
103 0
IX (Index Register) 1
ASCII Code 118 119 120 121 122 123 124 125
Character v w x y z { | }
Trace table:
Memory address
Instruction Working ACC IX OUTPUT
address space 100 101 102 103
20 100 1 0 1
50
51
52
53
54
55
[7]
9 (a) (i) One mark for the contents of the accumulator and one mark for the reason. [2]
Reason:
Address is 60
Contents of the index register is 8
And 60 + 8 = 68 in denary gives the address
The contents of which is 0100 0101 in binary.
(b)
Memory address
Instruction Working OUTPUT
IX
address space ACC
100 101 102 103
20 100 1 0 1
50 20
51 21
52 21
53 100
54 120
55
56
57
59 2
60 20
61 120
62 'x'
63
5 The following table shows part of the instruction set for a processor. The processor has one
general purpose register, the Accumulator (ACC), and an Index Register (IX).
Instruction
Op code Op code Explanation
Operand
(mnemonic) (binary)
Direct addressing. Load the contents of
LDD <address> 0001 0011 the location at the given address to the
Accumulator (ACC).
Indirect addressing. The address to be used is
LDI <address> 0001 0100 at the given address. Load the contents of this
second address to ACC.
Indexed addressing. Form the address from
<address> + the contents of the Index
LDX <address> 0001 0101
Register. Copy the contents of this calculated
address to ACC.
Immediate addressing. Load the denary
LDM #n 0001 0010
number n to ACC.
Immediate addressing. Load denary number n
LDR #n 0001 0110
to the Index Register (IX).
Store the contents of ACC at the given
STO <address> 0000 0111
address.
The following diagram shows the contents of a section of main memory and the Index Register (IX).
(a) Show the contents of the Accumulator (ACC) after each instruction is executed.
IX 0 0 0 0 0 1 1 0
(b) Each machine code instruction is encoded as 16 bits (8-bit op code followed by an 8-bit
operand).
LDM #67
LDX #7
[3]
0 0 0 1 0 1 0 0 0 1 0 1 1 1 1 0
.......................................................................................................................................[2]
16 4D
Write the assembly language for this instruction with the operand in denary.
.......................................................................................................................................[2]
5(a)(iv) 86 1
0 0 0 1 0 0 1 0 0 1 0 0 0 0 1 1
0 0 0 1 0 1 0 1 0 0 0 0 0 1 1 1
5(c)(i) 14 5E 2
14 1
5E 1
LDR 1
#77 1
(c) An assembly language program can contain both macros and directives.
Macro ................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
Directive ............................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[3]
...........................................................................................................................................
.......................................................................................................................................[1]
(d) The following table shows part of the instruction set for a processor. The processor has one
general purpose register, the Accumulator (ACC), and an Index Register (IX).
Instruction
Op code Explanation
Operand
(mnemonic)
Direct addressing. Load the contents of the given address
LDD <address>
to ACC.
Relative addressing. Move to the address n locations from
LDV #n the address of the current instruction. Load the contents of
this address to ACC.
STO <address> Store the contents of ACC at the given address.
INC Increment the contents of ACC.
Output the character corresponding to the ASCII character
OUTCH
code in ACC.
Following a compare instruction, jump to <address> if the
JPE <address>
compare was True.
JMP <address> Jump to the given address.
CMP #n Compare the contents of ACC with number n.
Complete the trace table for the following assembly language program.
Label Instruction
StartProg: LDV #Offset
CMP Value
ASCII code table (selected codes only)
JPE EndProg
<Space> 2 A B Y
OUTCH
32 50 65 66 89
LDD Offset
INC
STO Offset
JMP StartProg
EndProg: END
Offset: 10
50
65
89
32
Value: 32
Trace table:
[5]
(e) The program given in part (d) is to be translated using a two-pass assembler. The program
has been copied here for you.
Label Instruction
StartProg: LDV #Offset
CMP Value
JPE EndProg
OUTCH
LDD Offset
INC
STO Offset
JMP StartProg
EndProg: END
Offset: 10
50
65
89
32
Value: 32
On the first pass, the assembly process adds entries to a symbol table.
The following symbol table shows the first five entries, part way through the first pass.
The circular labels show the order in which the assembler made the entries to the symbol
table.
Complete the symbol table. Use circular labels to show the order in which the assembler
makes the entries.
Symbol table
StartProg 1 0 2
Offset 3 UNKNOWN 4
Value 5
[6]
Macro
• A group of instructions given a name // subroutine
• A group of instructions that need to be executed several times within the same
program
• The statements are written once and called using the name whenever they need
to be executed
• Macro code is inserted into the source file at each place it is called
• By example
Directive
• An instruction that directs the assembler to do something
• A directive is not a program instruction
• It is information for the assembler
• By example
For example: State the start address for the program //tell the assembler to set aside
space for variables // include an external file etc.
Table entries:
1 Mark per bullet, max 4
• EndProg
• 2 × Unknown
• 9
• 14
• 8
Numbering:
1 Mark per bullet, max 2
7 9