Created
December 11, 2017 08:47
-
-
Save 9nut/803aa74a8963c38bf216133001f553d0 to your computer and use it in GitHub Desktop.
This file contains 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
; Examples for this simulator | |
; http://schweigi.github.io/assembler-simulator/index.html | |
; sum up numbers in the range from-to | |
JMP start | |
from: DB 1 | |
to: DB 22 | |
sum: DB 0 | |
start: | |
MOV C, [from] ; Point to var | |
MOV D, [to] | |
CALL sumup | |
MOV D, 234 ; Point to output | |
MOV C, [sum] | |
CALL iprint | |
HLT ; Stop execution | |
sumup: | |
PUSH A | |
PUSH B | |
MOV B, 0 | |
MOV A, C | |
.loop: | |
ADD B, A | |
INC A | |
CMP A, D | |
JNA .loop | |
MOV [sum], B | |
POP B | |
POP A | |
RET | |
iprint: | |
PUSH A | |
PUSH B | |
MOV A, C | |
.l1: | |
MOV B, A ; start with current numerator | |
DIV 10 ; decimal printout, so divide by 10 | |
PUSH A ; save the divisor | |
MUL 10 ; get the nearest multiple of 10 | |
SUB B, A ; modulo value will be [0-9] | |
ADD B, '0' ; turn it to ascii | |
MOV [D], B ; print it | |
DEC D ; next print location | |
POP A ; restore divisor | |
CMP A, 0 ; if it's zero, we're done | |
JNZ .l1 | |
POP B | |
POP A | |
RET | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment