0% found this document useful (0 votes)
1K views10 pages

Chapter 6 Answers

The document discusses assembly language programming questions and answers from a coursebook and worksheet. It provides the binary operations for several assembly language instructions, examples of tracing an assembly language program, and answers questions about instruction opcodes, operands, and addressing modes. It also includes sample accumulator and memory address values for tasks demonstrating loading and storing data.

Uploaded by

John Holt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views10 pages

Chapter 6 Answers

The document discusses assembly language programming questions and answers from a coursebook and worksheet. It provides the binary operations for several assembly language instructions, examples of tracing an assembly language program, and answers questions about instruction opcodes, operands, and addressing modes. It also includes sample accumulator and memory address values for tasks demonstrating loading and storing data.

Uploaded by

John Holt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Chapter 6: Assembly language

programming: Answers to coursebook


questions and to Worksheet questions
Syllabus section covered: 4.2

From the coursebook


Task 6.01
The ASCII code for denary zero is 0110000. This is the binary equivalent of denary 48. Subtracting 48 leaves zero.
Note that the instruction has a denary value as the operand but this will be converted to a binary value before it is
subtracted.

Task 6.02
For the LDI instruction the original operand is an address, the contents of that address are another address, and
the contents of this second address are to be loaded into the accumulator. The overall process is:
ACC ← [[[CIR(15:0)]]]
However, the instruction must use the MAR when accessing a memory address so the steps could be as follows:
MAR ← [CIR(15:0)]
ACC ← [[MAR]]
MAR ← [ACC]
ACC ← [[MAR]]

Extension question 6.01


1011 1110
+ 0100 0100

Flags: N V C
(1) 0000 0010 001
The addition is handled correctly with no negative or overflow flag set so the processor can ignore the carry bit.

© Cambridge University Press 2019


Question 6.01
Notes for following through:
The program counter (PC) holds the address of the next instruction. It is set to 100 ready for the start when the
instruction LDD 201 is executed. The PC increments each time initially but has to be changed to the appropriate
address during the execution of the jump instruction, after which it reverts to incrementing. The instruction in
location 105 is never executed in this program fragment.
Notes with regard to memory content changes:
A program would not be expected to alter the contents of memory locations storing the program instructions so
locations 100–107 remain unchanged. Only a STO instruction puts data into memory, so the only change in 200 to
207 would be in 206, arising from the STO 206 instruction at the end of the program.

Task 6.03
ACC MAX TOTAL COUNT
00110011
00000011 3
00000000 0 0
00110111
00000111
00000111 7
00000000
00000001 1
00111000
00001000
00001111 15
00000001
00000010 2
00111001
00001001
00011000 24
00000010
00000011 3

Note that the binary codes need to be displayed for the accumulator to show how the input value is first stored as
an ASCII code then converted to binary. For convenience the other values are recorded as denary values.

© Cambridge University Press 2019


Exam-style Questions
1 a i

(1 for each arrow)


ii 110 as shown. (1)
b i

(1 for each arrow)


ii 112 as shown. (1)
c i

(3 for the four arrows, 1 for first one correct, 2 for first two correct)
ii 104 as shown. (1)
2 a Comments, directives and system calls are three strong answers (1 each)
The answer ‘macro calls’ also works because a macro call has to be replaced by the macro code. For the
purpose part of the question, learners could explain that a comment is there to assist the programmer when
reading the program.

© Cambridge University Press 2019


A directive is just that: it tells the assembler to do something perhaps associated with how the program
should be loaded into memory. A system call’s purpose is to get the operating system to do something, for
example provide access to a hardware component. (1 for any sensible statement)

b Memory addresses
Accumulator
201 202 203 204
0 10 0 204 5
10 4 11
11 9
5
4
9

(4 for accumulator values, 2 for the memory address values)


3 a 1 mark each for any of the following. (max 4)
The program is intended to initially take a single character (1) as input from the keyboard (1). It then
takes another character (1) that should be a single number (1), which is to be used to identify how many
times the initially input character is output. It should be noted that the program lacks suitable checks that
the second input is a value in the range 0 to 9. If 0 is input as the second character, the program stops
immediately (1).
b 1 mark each for any of the following. (max 3)
The program repetitively outputs the first character that was input (1), which could be any printing
character (1). The character is output at least once (1) and up to a maximum of nine times (1).
c Label Address
CHARACTER 1010
START 0100
OUTPUT 0111

The addresses are given as 4-bit binary values for illustration of this simple example.
4 This is Question 9 in 9608 Paper 11 June 2016. At the time of writing the published mark scheme is available
on the Cambridge International School Support Hub (requires registration). The Examiners Report for the June
2016 series is also available there and this may contain comments specific to this question.

The following are what the author of this chapter in the Teacher Resource would suggest as reasonable
answers with alternatives suggested where appropriate.
a i Accumulator: 0 1 0 0 0 1 0 1

The LDX instruction has an operand, which is an address. The value in the Index Register has to be added
to this value to get the address where the datum to be loaded is stored. So, the index register contains
00001000, which is the binary representation of denary 8. The value in address 68 must be loaded into
the accumulator.
ii Index Register 0 0 0 0 0 1 1 1

© Cambridge University Press 2019


b Note that the trace table supplied is slightly unusual in that it includes a column for instruction addresses.
This column must record the sequence of their use and must not include any not used which is the case
for address 58. Instructions such as the one at 55 which results in no value changes have to be included in
the table alongside a blank row.

Instruction Memory addresses


ACC IX Output
address 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

Cambridge International AS & A Level Computer Science 9608 paper 11 Q9a June 2016

Worksheet 6.1: for testing basic understanding


1 B and D
Option A is wrong because only one opcode is allowed and there is not necessarily an operand. Note that
using a symbolic address (providing the name of a label) as an operand is not a mnemonic, so option C is
incorrect.
2 An assembly language program has to be translated by an assembler. Most of the program will consist of B
that have to be translated into F. Other content in the program includes A which have to be removed. Also C
for constants or G for addresses must be converted to binary code. Any D included cause the assembler to
take appropriate action. Any E have to be replaced by their defining code.

© Cambridge University Press 2019


3

Note that, the operand is usually an address, but it may also be the abbreviation for a register or a value. If it
is a value, it is preceded by #, B or & depending on whether the value is given in denary, binary or
hexadecimal, respectively. The addressing mode is all about where the value comes from that is to be used by
the operation defined by the opcode.
4 LDD and LDR are examples of assembly language mnemonics for the opcodes of instructions of the C type.
The machine code equivalent of these opcodes will in part have A defining the F but will have E to define the
D or B and the B or D involved.
Here, the knowledge needed is that the opcode of an instruction will define the operation to be performed,
the addressing mode to be used and the register to be used.

© Cambridge University Press 2019


6 a

© Cambridge University Press 2019


7 Memory address Memory contents
100 LDD 200
101 ADD 201
102 ADD 203
103 INC ACC
104 CMP 202
105 JPE 107
106 INC ACC
107 STO 204
108 END

200 0000 0100


201 0000 0001
202 0000 1001
203 0000 0011
204 0000 0111

Program counter Accumulator


Before the first instruction is executed 100 0000 0000
After the first instruction has been executed 101 0000 0100
After the next instruction has been executed 102 0000 0101
And so on ... 103 0000 1000
104 0000 1001
105 0000 1001
106 0000 1001
107 0000 1001
0000 1001 is stored in 2004 108 0000 1001
Which remains stored after the program ends 109 0000 1001

Worksheet 6.2: more challenging questions


1 a 10, unless ADD and INC could use the same operation.
Note that this is not the same as categorising instructions when, for example, data movement
instructions form one category.
b Load, store, add, increment, decrement, jump, compare, input, output, end program.
c Load.
d LDM and LDR.

© Cambridge University Press 2019


e IN, OUT and END do not have an operand. In direct addressing the operand is a direct value, for example,
LDM #n.
f There are two bytes for the operand, that is, 16 bits giving 216 different addresses. This is 65 536.
2
Memory addresses
Accumulator
201 202 203 204
0 10 65 204 5
56 66 65
66
65

Note that as in Worksheet 6.1 the values stored are given in denary for convenience. In an alternative solution
it could be decided to convert the values and then use binary code for the entries in the trace tables.
However, the important part of the exercise is to follow the assembly code instructions.

3 Memory
Accumulator address Output
205
67 201 C
200 202 K
201 203 B
75 204 X
201
202
66
202
203
88
203
204
65

© Cambridge University Press 2019


4

© Cambridge University Press 2019

You might also like