My Computer Forum

My Computer Forum (http://mycomputerforum.com/)
-   Programming (http://mycomputerforum.com/programming/)
-   -   Little Man Computer language (http://mycomputerforum.com/programming/2714-little-man-computer-language.html)

jonbrutal August 23rd, 2010 11:29 AM

Little Man Computer language
 
Hi everyone,

Need help with this LMC programming question, am really stuck.Thank you for all your help & support.

Based on the LMC concepts and workings that you learned, write an assembly program that

i)Takes in and compares two numbers
ii)Output zero if the numbers are same.
iii)Output the positive difference when not same


Appreciate all your kind help & support.



Thank you & regards

shynthriir August 26th, 2010 08:21 AM

Re: Little Man Computer language
 
Never programmed in assembly before, but after some playing around, this seems to work:

RAM ADDRESS - INSTRUCTION

00 - 901 (INP)
01 - 399 (STA -> 99)
02 - 901 (INP)
03 - 398 (STA -> 98)
04 - 599 (LDA -> 99)
05 - 298 (SUB -> 98)
06 - 397 (STA -> 97)
07 - 810 (BRP)
08 - 297 (SUB -> 97)
09 - 297 (SUB -> 97)
10 - 902 (OUT)
11 - 000 (HLT)

There's a handy javascript tool which will emulate the instructions too! http://matt.krutar.org/LMC4/

Basicly it goes like this:
1) Load each input, storing them seperately
2) Load one of the inputs (though looking back, this isn't needed)
3) Subtract the other input
4) If result is greater than 0, jump to the out statement
5) Otherwise, subtract it from itself twice [-n - -n = 0; 0 - -n = n]
6) Output the result

toodooloo April 21st, 2012 03:40 AM

Re: Little Man Computer language
 
I need help too!
how would you add up a series of numbers, and when you enter 0 that is when you stop (you know all the numbers have been added in)
how would you do this in Little man (lmc)


All times are GMT -8. The time now is 10:01 AM.

Copyright © 2019 My Computer Forum Forum. All rights reserved.