0

I'm personally attempting to learn the little man computer.

I found a problem:

  1. Write an LMC (Little Man Computer) program to do the following task.

    if (value == 0) { some_statements; } next_statement;

My current answer:

    00 901  IN (value)
    01 399 STORE
    02 808 TEST
    03 901  IN (value)
    04 808 TEST
    05 000 STOP 

I don't believe this is right... can anyone please assist me? any instructional information would be appreciated or direction. Thank you.

1 Answers1

0

All the computer does is follow a stream of codes, like add, subtract, store, etc...

One of the codes allows you to jump past other code. This is how the computer handles conditionals at the most basic level. The BRZ code will branch to a specified line of code if your accumulator is set to 0.

10 Input to accumulater
20 BRZ 60                    < go to line 60 if accumulator is 0
30 do something //skip me
40 do something //skip me
50 HALT
60 do something else
70 do something else
80 BRZ 30

If the accumulator wasn't 0, it would just follow along and do lines 30 and 40 and then terminate at line 50.

Eric
  • 601
  • 7
  • 22