My Computer Forum Computer Science Forum

Go Back   My Computer Forum > Computer Science Forum > Programming

Programming Programming Languages, Interpreters, and Compilers - Assembly, Declarative, Machine, Object Oriented, Iterative


Reply
 
LinkBack Thread Tools Display Modes
August 23rd, 2010, 12:29 PM   #1
 
Joined: Aug 2010
Posts: 1
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
jonbrutal is offline  
 

My Computer Forum is free to register and we welcome everyone!

August 26th, 2010, 09:21 AM   #2
Retired
 
Joined: Jul 2010
Posts: 23
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
shynthriir is offline  
April 21st, 2012, 04:40 AM   #3
 
Joined: Apr 2012
Posts: 1
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)
toodooloo is offline  
Reply

  My Computer Forum > Computer Science Forum > Programming

Tags
computer, language, man



Thread Tools
Display Modes






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