Skip to content

Instantly share code, notes, and snippets.

@jake-walker
Last active March 21, 2017 12:32
Show Gist options
  • Save jake-walker/3390fa2eb9c02ec46e3a6a7feac553ab to your computer and use it in GitHub Desktop.
Save jake-walker/3390fa2eb9c02ec46e3a6a7feac553ab to your computer and use it in GitHub Desktop.
Little Man Computer Multiply, Devide and Average
LDA zero
STA iterations
STA total
STA tmp
STA count
looptop INP
BRZ startd
STA tmp
LDA total
ADD tmp
STA total
LDA iterations
ADD one
STA iterations
BRA looptop
HLT
startd LDA total
STA num1
LDA iterations
STA num2
LDA zero
STA count
devideloop LDA num1
SUB num2
STA num1
LDA count
ADD one
STA count
LDA num1
BRZ finished
BRA devideloop
HLT
finished LDA count
OUT
HLT
zero DAT 0
one DAT 1
iterations DAT
tmp DAT
total DAT
num1 DAT
num2 DAT
count DAT
INP
STA num1
INP
STA num2
LDA zero
STA count
looptop LDA num1
SUB num2
STA num1
LDA count
ADD one
STA count
LDA num1
BRZ finished
BRA looptop
HLT
finished LDA count
OUT
HLT
zero DAT 0
one DAT 1
num1 DAT
num2 DAT
count DAT
INP
STA num1
INP
STA num2
STA count
LDA zero
STA output
looptop LDA count
BRZ finished
SUB one
STA count
LDA output
ADD num2
STA output
BRA looptop
finished LDA output
OUT
HLT
zero DAT 0
one DAT 1
count DAT
num1 DAT
num2 DAT
output DAT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment