Thursday, July 29, 2010

NJR-Team

Everything about technology

Little Man Computer(LMC)

Posted by admin On September - 10 - 2009

Hello, today while answering questions on yahoo@answers , i saw a question about LMC. I didnt know anything about that thing but i found out fast enough.

LMC is a instructional model of a computer, it’s used to teach students about basic features of a modern computer.

it looks like a good thing to learn before assembly.


So i went on that page http://www.atkinson.yorku.ca/~sychen/research/LMC/LittleMan.html
and i started coding.

LMC is not hard it had a set of 10 instruction

INP = prompt the user to a value to put in the accumulator
OUT = output the value of the accumulator
LDA = load in the acumulator the data at the specified memory
STA = store the value of the accumulator at a specified memory
ADD = add a specified value to the accumulator
SUB = sub a specified value to the accumulator
BRZ = goto specified label if the value inside the accumulator is 0
BRP = goto to specified label if the value inside the accumulator is 0 or greater
BRA = declare a label
DAT = declare a variable
HLT = end program

after 30 min i had answer the guy question : how to do a multiplication in LMC
here i give you the code

INP
STA NUMBER1
INP
STA NUMBER2
SUB NUMBER1
BRP NO2GREATER
LDA NUMBER1
STA FACTOR
LDA NUMBER2
STA MULTIPLIER
LDA ZERO
BRZ LOOKIFZERO
NO2GREATER LDA NUMBER2
STA FACTOR
LDA NUMBER1
STA MULTIPLIER
LDA ZERO
BRZ LOOKIFZERO
LOOKIFZERO LDA NUMBER1
BRZ ISZERO
LDA NUMBER2
BRZ ISZERO
LDA ZERO
BRZ LOOPTOP
ISZERO OUT ZERO
HLT
LOOPTOP LDA RESULT
ADD FACTOR
STA RESULT
LDA MULTIPLIER
SUB ONE
BRZ LOOPEND
STA MULTIPLIER
BRP LOOPTOP
LOOPEND LDA RESULT
OUT
HLT
BRA NO2GREATER
BRA LOOKIFZERO
BRA ISZERO
BRA LOOPTOP
BRA LOOPEND
NUMBER1 DAT
NUMBER2 DAT
FACTOR DAT
MULTIPLIER DAT
RESULT DAT 000
ONE DAT 001
ZERO DAT 000

Updated : there was a mistake, i did not post the latests version  so it did not work correctly, i was storing a value instead of loading it.  Now it’s fixed, note this code does not support negative number but if someone modify it to support it  it would be nice to post it.

hope it was usefull to someone

2 Responses

  1. jt Said,

    this is mine as numeric codes

    901 320 321 901 323 222 323 713 520 121
    320 523 605 520 902 524 320 321 323 0
    0 0 1 0 0

    note in this version you actually get an answer output because it works. apparently you didn’t notice yours doesn’t

    Posted on December 24th, 2009 at 10:46 am

  2. NunezVeronica30 Said,

    Set your life time more simple get the home loans and everything you require.

    Posted on July 1st, 2010 at 7:32 pm

Add A Comment