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.
Mnemonic | Name | Description | Op Code |
INP | INPUT | Retrieve user input and stores it in the accumulator. | 901 |
OUT | OUTPUT | Output the value stored in the accumulator. | 902 |
LDA | LOAD | Load the Accumulator with the contents of the memory address given. | 5xx |
STA | STORE | Store the value in the Accumulator in the memory address given. | 3xx |
ADD | ADD | Add the contents of the memory address to the Accumulator | 1xx |
SUB | SUBTRACT | Subtract the contents of the memory address from the Accumulator | 2xx |
BRP | BRANCH IF POSITIVE | Branch/Jump to the address given if the Accumulator is zero or positive. | 8xx |
BRZ | BRANCH IF ZERO | Branch/Jump to the address given if the Accumulator is zero. | 7xx |
BRA | BRANCH ALWAYS | Branch/Jump to the address given. | 6xx |
HLT | HALT | Stop the code | 000 |
DAT | DATA LOCATION | Used to associate a label to a free memory address. An optional value can also be used to be stored at the memory address. |
Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area