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 dependin on your input !sinal" (# or 2)$ %& you input a '#, LMC will A the 2 numbers (A*B) but i& you input a '2, LMC will M+L%-L. the 2 numbers (A/B)$ Run in the simulator and chec0 your codes$ hen you need to ma0e a 1ideo to eplain your answer$
33 %4- 5 the 1alue &rom the 6in bo6 copied onto the accumulator$ 3# 7A 285 the contents o& the accumulator stored to address 28$ 32 %4- 5 the 1alue &rom the 6in bo6 copied onto the accumulator$ 38 7A 295 the contents o& the accumulator stored to address 29$ 39 7+B 285 the contents address 28 substract from the accumulator$ 3: BR- ## 5 proram set counter to address ## because the content o& accumulator are ;ero
LA 285 the contents o& address 28 loaded onto the accumulator$ 3? A 295 the contents o& address 29 added to the accumulator$ 3@ O+ the 1alue is copied &rom accumulator$ #3 BRA 22 5 the proram set the counter to address 22$ ## LA 295 the contents o& address 29 loaded onto the accumulator$ #2 LA 295 the contents o& address 29 loaded onto the accumulator$ #8 BR 235 the proram counter set to address 23 because the contents o& accumulator are ;ero$ #9 7+B 2:5 the contents address 2: substract from the accumulator$ #: 7A 295 the contents o& the accumulator stored to address 29 #= LA 2=5 the contents o& address 2= loaded onto the accumulator$ #> A 285 the contents o& address 28 added to the accumulator$ #? 7A 2=5 Store the contents o& the accumulator to address $ #@ BRA #25 the proram set the counter to address #2$ 23 LA 2=55the contents o& address 2= loaded onto the accumulator 2# O+5 the 1alue is copied &rom accumulator$ 22 L5 Stop the LMC simulator eecutin the proram$ 28 A 33 5 Reser1e as data the memory address reached when this instruction is compiled$ he instruction is compiled an reser1ed as data memory address$ 29 A 33
2: A 3# 2= A 33
INP STA first INP STA second SUB first BRP secondBig LDA first LDA first ADD second OUT BRA endProgram secondBig LDA second LOOP
LDA second BRZ ENDTHIS SUB ONE STA second LDA ANS ADD first STA ANS BRA LOOP
ENDTHIS LDA ANS
OUT
endProgram HLT first
DAT
second
DAT
ONE
DAT 1
ANS
DAT