Skip to content

Instantly share code, notes, and snippets.

@deebs67
Last active December 31, 2023 21:54
Show Gist options
  • Save deebs67/99a86b31db0ce3792905f992dee0c1a2 to your computer and use it in GitHub Desktop.
Save deebs67/99a86b31db0ce3792905f992dee0c1a2 to your computer and use it in GitHub Desktop.
Programs for the 'Little Man Computer' (LMC)

The Little Man Computer (LMC)

Information about the LMC can be found at these links:

Wikipedia: https://en.wikipedia.org/wiki/Little_man_computer
Peter Higginson: https://peterhigginson.co.uk/LMC/help.html
Futurelearn: https://www.futurelearn.com/courses/how-computers-work/0/steps/49285
101 Computing: https://www.101computing.net/fibonacci-sequence-using-lmc/

Video tutorials:

Andy Dolinski: https://www.youtube.com/watch?v=kCyyZI1GgsQ and https://www.youtube.com/watch?v=sEFnRDgkaWA

LMC emulators/simulators are available here:

101 Computing: https://www.101computing.net/lmc-simulator/
Peter Higginson: https://peterhigginson.co.uk/LMC/ (this is the one which I used)

LMC programs which I have written for the 'Higginson' LMC:

Program00:

        LDA 99  
        ADD 98  
        OUT  
        HLT  
// Output the sum of the contents of memory addresses 99 and 98

Program01:

        LDA label1  
        ADD label2  
        OUT  
        HLT  
label1  DAT 15  
label2  DAT 34  
// Output the sum of the values at label1 and label2 (i.e. 15 and 34 respectively)  

Program02:

        INP
        SUB label1
        BRP ifgre
        LDA zero
        OUT 
        HLT
ifgre   LDA one
        OUT
        HLT
label1  DAT 34
one     DAT 1
zero    DAT 0
// Output a 1 if the entered value is greater than or equal to 34, 0 otherwise

Program03:

        INP
        STA firstn
        INP
        ADD firstn
        SUB label1
        BRP ifgre
        LDA zero
        OUT 
        HLT
ifgre   LDA one
        OUT
        HLT
label1  DAT 34
firstn  DAT
one     DAT 1
zero    DAT 0
// Output a 1 if the two entered values sum to be greater than or equal to 34, 0 otherwise

Program04:

        INP
        STA firstn
        INP
        SUB firstn
        OUT // O/P result
        SUB thresh 
        BRP ifgre
        LDA false
        BRA exit
ifgre   LDA true // If>34
exit    OTC
        HLT
thresh  DAT 34
firstn  DAT
true    DAT 84
false   DAT 70
// Subtract the first input number from the second, and output the result. Then output a T if the result is >=thresh(34), F otherwise

Program05:

        INP
        BRP wrt
        LDA false //write F
        OTC
        HLT
wrt     LDA true //write T
        OTC 
        HLT
true    DAT 084
false   DAT 070
// Read the input. Write T to output if the input is non-negative, F otherwise

Ideas for further programs to write:

@JohnsonMwauza633
Copy link

can i get a program for multiplying three number? kindly.

@Tsavaliya
Copy link

can i get a program for:
Ask the user to input two numbers. If the first number is greater than the second, output 1; if the second number is greater than the first, output -1, and if the two numbers are the same, output 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment