0% found this document useful (0 votes)
12 views3 pages

Assembly Language Homework Solutions

The document contains homework assignments related to Assembly language programming for the Little Man Computer. It includes code examples, explanations of specific statements, and questions regarding the output and concepts such as opcode and operand. The document also covers addressing modes like direct, indirect, and immediate.

Uploaded by

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

Assembly Language Homework Solutions

The document contains homework assignments related to Assembly language programming for the Little Man Computer. It includes code examples, explanations of specific statements, and questions regarding the output and concepts such as opcode and operand. The document also covers addressing modes like direct, indirect, and immediate.

Uploaded by

luky luca
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Homework 4 Assembly language

Unit 3 Software development

Answers
1. The following program is written for the Little Man Computer.
The user enters the values 3, 5, 6.
INP
STA p
INP
STA q
INP
STA r
LDA p
ADD r
SUB q
OUT
HLT
p DAT
q DAT
r DAT

(a) What is the effect of the statement STA p in the second line of the program? [1]
Stores the value 3 in the variable p

(b) What does the statement SUB q do? [1]


Subtracts the value in variable q (in this example 5) from the contents of the
accumulator

(c) What mathematical expression does the program calculate? [1]


p+r–q

(d) What is the output of the program? [1]


Answer: 4

1
Homework 4 Assembly language
Unit 3 Software development

2. The following program is written for the Little Man Computer. The user enters the value 3.
INP
STA a
start LDA a
OUT
SUB one
STA a
BRZ finish
BRA start
finish LDA a
SUB a
OUT
HLT
a DAT
one DAT 1

(a) What does the statement BRZ finish do? [2]


Branches to statement labelled finish if value in accumulator is 0.

(b) What does the statement one DAT 1 do? [1]


It stores the value 1 in variable one.

(c) What is the output of the program? [2]


Answer:
3
2
1
0

(d) Some of the statements are not needed. Rewrite the assembly language program in
as few statements as possible. [4]

INP
start OUT
SUB one
BRZ finish
BRA start
finish OUT
HLT
one DAT 1

2
Homework 4 Assembly language
Unit 3 Software development

3. (a) Explain what is meant by the terms opcode and operand. [2]
Opcode – the operation to be performed
Operand – the value or address of the value to be operated on

(b) Explain what is meant by each of the following addressing modes:


(i) Direct [1]
The operand is the address of the value to be operated on/used in calculation
(ii) Indirect [1]
The operand is the location of the address of the value to be operated on/used in
calculation
(iii) Immediate [1]
The operand is the value to be operated on/used in calculation

[Total 18 marks]

Common questions

Powered by AI

The program outputs the sequence 3, 2, 1, 0. It repeatedly decrements the input using the 'SUB one' instruction until the accumulator reaches zero, controlled by the 'BRZ finish' instruction, hence producing a countdown from the input .

A simplified loop program can be constructed by minimizing redundancy. The described optimization removes unnecessary store instructions, retaining only the core input, output, decrement, and branch logic for efficient execution .

Addressing modes add flexibility by allowing different ways to specify data within instructions. Direct addressing accesses data at a specific location, indirect uses a pointer to an address, and immediate embeds actual data within the instruction. These modes adjust how instructions interact with memory and data .

The program calculates the mathematical expression p + r - q using the inputs 3 for p, 5 for q, and 6 for r. This results in the calculation 3 + 6 - 5, with the output being 4 .

The 'SUB q' instruction subtracts the value stored in variable 'q' from the contents of the accumulator. In the example, it subtracts 5 (value in q) from the accumulator, which is part of evaluating the expression p + r - q .

The program sequentially reads inputs into specific memory locations and performs calculations using stored values. For example, the program stores inputs in 'p', 'q', and 'r', and calculates p + r - q, resulting in the output of 4 when executed as described .

The instruction 'STA p' stores the value that has been input into the accumulator into the variable named 'p'. In the context provided, it stores the value 3 in variable 'p' .

Efficiency is improved by removing superfluous instructions that do not contribute to the end goal. For instance, unnecessary stores or redundant calculations can be omitted. In the provided program, simplifying the sequence results in fewer instructions without altering the output, demonstrating a streamlined computational process .

In assembly language, the opcode defines the operation to be executed, such as load, store, or add. The operand can be the data or address on which the operation is performed, directing the operation's execution by identifying necessary resources .

The 'BRZ finish' instruction causes the program to branch to the label 'finish' if the accumulator contains zero. This serves as a loop control mechanism, determining when the program should stop executing repetitive instructions and proceed to final operations .

You might also like