Skip to content

Instantly share code, notes, and snippets.

@rubyist
Last active December 30, 2015 20:49
Show Gist options
  • Save rubyist/7882973 to your computer and use it in GitHub Desktop.
Save rubyist/7882973 to your computer and use it in GitHub Desktop.
@R2 // A = 2
M=0 // Memory[2] = 0
(LOOP)
@R1 // A = 1
M=M-1 // Memory[1] = Memory[1] - 1
D=M // D = Memory[1]
@END
D;JLT // Jump to @END if D < 0
@R0 // A = 0
D=M // D = Memory[0]
@R2 // A = 2
M=D+M // Memory[2] = D + Memory[2]
@LOOP // Loop
0;JMP
(END)
@END
0;JMP
@lithium
Copy link

lithium commented Dec 9, 2013

heh this is what it would look like in redscript:

multiply:  // result = r0 * r1
    result = 0
loop:
    r1 -= 1
    if r1 < 0:
        jmp end
    result += r0
    jmp loop

r0: .data 0
r1: .data 0
result: .data 0

end: nop

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