Little Man Computer (LMC) Example Programs
Вставка
- Опубліковано 9 вер 2024
- Here are a few little simple programs for Little Man Computer.
They use the simulator from www.PeterHigginson.co.uk/LMC.
Follow along with them if you are not confident, or if you are more confident pause when the task is displayed, try to create a solution them compare your solution to mine. There are many ways to solve a problem with code, mine will not be the only way but I try to keep things simple and flowing.
Thank you so much for this , honestly !!
this saved me ty
thanks mate
Ask the user for two numbers. Print out the answer to first number minus the second
number, followed by the answer to the second number minus the first number.
Example test data Expected output
7, 3 4, -4
That problem should be in the videos.
Inp
Sta n1
Inp
Sta n2
Lda n1
Sub n2
Out
Lda n2
Sub n1
Out
Hlt
n1 dat
n2 dat
just had a curious thought on the last example where instead of multiplying two numbers, what if u were to divide one number by the other
any idea what that you look like??
What mic do you use? It sounds great.
Use Audacity to remove background noise
Hello, how can i reverse the order of an array on LMC?
For example: [1,2,3,4,5] to [5,4,3,2,1]
Thank you, your quick response will be highly appreciated!!
Can u give explanation on how the reverse sequence is generated? Please
Write a LMC program that can convert an n-bit binary number into a decimal number. Display the natural number as
output before halting the program.
The first input determines the value for n. It is assumed this value will be equal to four, or greater.
For example, if the first input is eight (8) then eight subsequent inputs are requested.
If the subsequent inputs number were 1, 0, 0, 1, 0, 0, 0, 0 then the output would be 9.
n input values are provided by the user, one for each bit:
The first of these is the least-significant bit.
The n’th input is the most-significant bit.
please solve it
😂I’m not going to do your homework for you. Ha ha ha. This is the method. The first number needs to be stored to help you with a loop counter. Then you need a variable that starts at one. Each loop you add it to itself. Do 1 then 2 then 4 then 8 etc. also each time around the loop you take in a number. If it is one then add on the variable from before and store as a total. At the end output the total.
11:05 what would the code look like if it asks for 3 numbers instead of 2 numbers and outputs the largest number?
"Ask the user to enter two numbers. C is a counter and N is a number. Output the first C multiplies of N, starting with 0. So, if C is 5 and N is 3, the output is 0, 3, 6, 9, 12". pls help :(
Hi Iain,
Would you be able to write a program which would allow the user to input three numbers and then for the program to display the numbers input largest to smallest please!
“”Enter three numbers and output them in ascending order””. Please help🥹🥹🥹🥹you can immediately write an answer here, I beg you, it is very necessary???!!!
Descending order here:
INP
STA first
INP
STA second
INP
STA third
SUB first
BRP branch1
LDA first
STA temp
LDA third
STA first
LDA temp
STA third
branch1 LDA third
SUB second
BRP branch2
LDA second
STA temp
LDA third
STA second
LDA temp
STA third
branch2 LDA third
OUT
LDA first
SUB second
BRP branch3
LDA second
OUT
LDA first
OUT
HLT
branch3 LDA first
OUT
LDA second
OUT
HLT
first DAT
second DAT
third DAT
temp DAT
@@iainprice8205In line 7, if subtracting first from third produces a negative value (third>first), brp condition isnt satisfied, the program control skips brp and continues downwards. Could you please explain what happens when program control reaches line 14 (STA third). Where does it go next?
Would appreciate a reply greatly.
@@jewaljiji5425 the first section is checking the first and third number. If the branch is not taken you then look at the second and third to determine the order.
@@iainprice8205 could you specify how the program control travels