Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

QUESTION 3:

Write and run LMC code that would input 2 numbers (Let say, A and B) and then you will
add OR multiply the numbers depending on your input signal (1 or 2). If you input a 1,
LMC will ADD the 2 numbers (A+B) but if you input a 2, LMC will MULTIPLY the 2
numbers (A*B).
Run in the simulator and check your codes. Then you need to make a video to explain your
answer.

00 INP - the value from the "in box" copied onto the accumulator.
01 STA 23- the contents of the accumulator stored to address 23.
02 INP - the value from the "in box" copied onto the accumulator.
03 STA 24- the contents of the accumulator stored to address 24.
04 SUB 23- the contents address 23 substract from the accumulator.
05 BRP 11 - program set counter to address 11 because the content of accumulator are
zero/positive.
06 LDA 23-the contents of address 23 loaded onto the accumulator.
07 LDA 23- the contents of address 23 loaded onto the accumulator.
08 ADD 24- the contents of address 24 added to the accumulator.
09 OUT the value is copied from accumulator.
10 BRA 22 - the program set the counter to address 22.
11 LDA 24- the contents of address 24 loaded onto the accumulator.
12 LDA 24- the contents of address 24 loaded onto the accumulator.
13 BRZ 20- the program counter set to address 20 because the contents of accumulator are
zero.
14 SUB 25- the contents address 25 substract from the accumulator.
15 STA 24- the contents of the accumulator stored to address 24
16 LDA 26- the contents of address 26 loaded onto the accumulator.
17 ADD 23- the contents of address 23 added to the accumulator.
18 STA 26- Store the contents of the accumulator to address xx.
19 BRA 12- the program set the counter to address 12.
20 LDA 26--the contents of address 26 loaded onto the accumulator
21 OUT- the value is copied from accumulator.
22 HLT- Stop the LMC simulator executing the program.
23 DAT 00 - Reserve as data the memory address reached when this instruction is compiled.
The instruction is compiled an reserved as data memory address.
24 DAT 00

25 DAT 01
26 DAT 00

INP
STAfirst
INP
STAsecond
SUBfirst
BRPsecondBig
LDAfirst
LDAfirst
ADDsecond
OUT
BRAendProgram
secondBigLDAsecond
LOOPLDAsecond
BRZENDTHIS
SUBONE
STAsecond
LDAANS
ADDfirst
STAANS
BRALOOP
ENDTHISLDAANS
OUT
endProgramHLT
firstDAT
secondDAT
ONEDAT1
ANSDAT

You might also like