AssemblY language
Activity 1. Pair work
Task– 3:
Task– 5(extra task):
1.45M

Assembly language

1. AssemblY language

analyze a simple program in assembly language
ASSEMBLY LANGUAGE

2.

LMC online is a simulator for getting to
know the low-level programming
language Assembler.
PROGRAMMING IN LITTLE MAN
COMPUTER (LMC)
1 - space for a typing program
2 - button for compiling the program
3 - button RUN the whole program, STEP
- line by line
4 - registers of CPU
5 - the memory location
6 - input data
7 - output data

3.

LMC CONTAINS A SET OF
COMMANDS CALLED MNEMONICS.

4. Activity 1. Pair work

Complete Task 1 – Task 3 in pairs and check
other pairs work.
Descriptors:
• correctly uses instructions of LMC
• correctly output result

5.

Task-1.
Write a program that outputs the negative of a positive number.
So if 7 is entered -7 is output.
INP
STA A
SUB A
SUB A
OUT
A DAT
Descriptors:
• correctly uses instructions of LMC
• correctly output result

6.

Task-2.
1.A+B+C
2.A+C-B (A inputted first, B inputted second, C inputted third)
3.A-B+C
Descriptors:
• correctly uses instructions of LMC
• correctly output result

7. Task– 3:

Doubling the input numbers
Enter three numbers.
For each number, output its
double.
Example:
Input: 4, 1, 5
Output: 8, 2, 10

8.

BRANCHING ALGORITHMS IN ASSEMBLY
LANGUAGE

9.

10.

11.

Now, let's use the LMC to determine the bigger of two numbers; the output must
be the bigger number regardless of its order of input. This is the code and trace
table:
Code:
INP
STA A
INP
STA B
LDA A
SUB B
BRP POSITIVE
LDA B
OUT
HLT
POSITIVE LDA A
HLT
A
DAT
B
DAT
Trace table:
Code Line
A
B
Acc
INP
STA A
INP
STA B
LDA A
SUB B
LDA B
OUT
HLT
4
4
4
4
4
4
4
4
4
6
6
6
6
6
6
6
4
4
6
6
4
-2
6
6
-
Condition Output
A-B<0
BRP plays the major role here: it branches out the execution to a
sub-route, defined as POSITIVE, if A-B turns out to be positive.
Otherwise, the execution continues along the main route.
6

12. Task– 5(extra task):

TASK– 5(EXTRA TASK):
Write a LMC program that outputs the largest of three input values
The program takes three inputs (stored in A, B, and C).
It compares A with B.
If A is larger or equal, it compares A with C.
If not, it compares B with C.
The largest value is loaded into the accumulator and then
output.

13.

Example Answer:
INP
STA A
INP
STA B
INP
STA C
LDA A
SUB B
BRP A_IS_LARGER
LDA B
BRP B_IS_LARGER
A_IS_LARGER LDA C
SUB A
BRP C_IS_LARGER
LDA A
BRA OUTPUT
B_IS_LARGER LDA C
SUB B
BRP C_IS_LARGER
LDA B
BRA OUTPUT
C_IS_LARGER LDA C
BRA OUTPUT
OUTPUT OUT
HLT
A
DAT
B
DAT
C
DAT

14.

Let's go through an example where C is the largest value. Fill the trace table. We’ll assume the input
values are:
•A = 4 B = 7 C = 10
INP
STA A
INP
STA B
INP
STA C
LDA A
SUB B
BRP A_IS_LARGER
LDA B
BRP B_IS_LARGER
A_IS_LARGER LDA C
SUB A
BRP C_IS_LARGER
LDA A
BRA OUTPUT
B_IS_LARGER LDA C
SUB B
BRP C_IS_LARGER
LDA B
BRA OUTPUT
C_IS_LARGER LDA C
BRA OUTPUT
OUTPUT OUT
HLT
A
DAT
B
DAT
C
DAT
CODE LINE
A
B
C
ACC
CONDITION
OUTPUT

15.

What is the output of the code? What does it do?
Fill the trace table to know the purpose of the code:
INP
STA A
INP
STA B
SUB A
BRZ line1
LDA A
OUT
LDA B
OUT
HLT
line1 ADD A
ADD A
OUT
A DAT
B DAT
Code
Line
A
B
Acc
Condition
Output

16.

Example of the trace table with loop
algorithm
LOOP
END
N
ONE
INP
STA N
LDA N
OUT
SUB ONE
STA N
BRZ END
BRA LOOP
HLT
DAT
DAT 1
Code Line
INP
STA N
LDA N
OUT
SUB ONE
STA N
BRZ END
BRA LOOP
LDA N
OUT
SUB ONE
STA N
BRZ END
BRA LOOP
LDA N
OUT
SUB ONE
STA N
BRZ END
HLT
Program counts down from any input number
N
3
3
3
3
2
2
2
2
2
2
1
1
1
1
1
1
0
0
0
0
Acc
3
3
3
3
2
2
2
2
2
2
1
1
1
1
1
1
0
0
0
-
Condition
Output
3
Not zero, continue
2
Not zero, continue
1
Zero, end program

17.

LOOP
CONT
END
A
B
Q
ZERO
ONE
INP
STA A
INP
STA B
LDA ZERO
STA Q
LDA A
SUB B
BRP CONT
BRA END
STA A
LDA Q
ADD ONE
STA Q
BRA LOOP
LDA Q
OUT
HLT
DAT
DAT
DAT
DAT 0
DAT 1
Analyze what this code will do?
Answer: output the quotient of two input values
CODE LINE
A
B
Q
ACC
CONDITION
OUTPUT

18.

Analyze what this code will do?
LOOP
CONT
END
A
B
INP
STA A
INP
STA B
LDA A
SUB B
BRP CONT
BRA END
STA A
BRA LOOP
LDA A
OUT
HLT
DAT
DAT
Answer: output the reminder of division of two
input values
CODE LINE
A
B
ACC
CONDITION
OUTPUT

19.

EXAM STYLE QUESTIONS
English     Русский Правила