For this challenge you will write a program of Guess the number (Higher or Lower?) using LMC assembly language.
Your program will be used by two users (player A and player B) as follows:
- Ask player A to input a number between 1 and 100 (without player B looking at what player A is inputting)
- Ask player B to guess player A’s number. For each guess, the program will give feedback to the player as to whether their guess is too high or to low.
- Let player B carry on guessing till they guess the right number.
Below is the flowchart for this game designed to be implemented with a high level programming language such as Visual Basic. Note that if this flowchart was to be implemented in Python it would have to be changed slightly to replace the repeat until loop with a while loop as there is no repeat until loop in Python.
Little Man Computer
Your challenge is to redesign this algorithm for a low level assembly language (See LMC instruction set below). You will then be able to code this game using one of the following online LMC Simulators:
Note that these LMC similators only manipulate numbers so you will have to use the following values for your output messages:
- “Higher!” will output number 1
- “Lower!” will output number 0
- “You win!” will output number 9
LMC Instruction Set
Note that in the following table “xx” refers to a memory address (aka mailbox) in the RAM. The online LMC simulator has 100 different mailboxes in the RAM ranging from 00 to 99.
|Retrieve user input and stores it in the accumulator.
|Output the value stored in the accumulator.
|Load the Accumulator with the contents of the memory address given.
|Store the value in the Accumulator in the memory address given.
|Add the contents of the memory address to the Accumulator
|Subtract the contents of the memory address from the Accumulator
|BRANCH IF POSITIVE
|Branch/Jump to the address given if the Accumulator is zero or positive.
|BRANCH IF ZERO
|Branch/Jump to the address given if the Accumulator is zero.
|Branch/Jump to the address given.
|Stop the code
|Used to associate a label to a free memory address. An optional value can also be used to be stored at the memory address.