Created
December 11, 2017 17:29
-
-
Save 9nut/814b6bd8fc4148000214d7fa6981f524 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Example for the following 8-bit machine simulator | |
; http://schweigi.github.io/assembler-simulator/index.html | |
; Enumerate numbers from zero to [C] | |
start: | |
MOV C, 10 ; C = 10 | |
MOV D, 232 ; D = 232 ; D is set to output memory location | |
CALL counter ; enumerate from 0 to C, output to *D | |
HLT ; Stop execution | |
counter: ; counter(C:max, D:*output) | |
PUSH A ; int A | |
PUSH B ; int B | |
MOV B, 0 ; B = 0 | |
.loop: ; while | |
MOV A, B ; A = B | |
ADD A, '0' ; A = A + '0' ; ASCII printable | |
MOV [D], A ; *D = A ; Write to output | |
INC B ; B++ | |
INC D ; D++ | |
CMP B, C ; if (B != C) | |
JNZ .loop ; continue | |
POP B ; forget B | |
POP A ; forget A | |
RET |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment