Created
January 30, 2017 06:49
-
-
Save blotta/e91a02bbf191d029973a46d468c9af8c 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
.text | |
.globl _start | |
start = 0 | |
max = 31 | |
_start: | |
mov x28,start /* loop index */ | |
loop: | |
/* Print msg */ | |
mov x2, len /* message length (bytes) */ | |
adr x1, msg /* message location (memory address) */ | |
mov x0, 1 /* file descriptor: 1 is stdout */ | |
mov x8, 64 /* write is syscall #64 */ | |
svc 0 /* invoke syscall */ | |
/* division */ | |
mov x19, #10 /* r19 holds value of 10 */ | |
udiv x20, x28, x19 /* x20 (quo) = x28 (li) / x19 (div) */ | |
msub x21, x19, x20, x28 /* x21(rmdr) = x28(li) - ( x20(quo) * x19(div) ) */ | |
/* print leading digit */ | |
cmp x20, #0 /* 0 - quotient */ | |
b.eq lsd /* if values are equal, jump to lsd (least significant digit) */ | |
mov x2, len2 | |
adr x1, digit | |
add x20, x20, #48 | |
str x20, [x1] | |
mov x0, 1 | |
mov x8, 64 | |
svc 0 | |
lsd: | |
/* Print following digit */ | |
mov x2, len2 /* Length */ | |
adr x1, digit /* x1 holds address of digit */ | |
add x21, x21, #48 /* ascii conversion */ | |
str x21, [x1] /* store ascii value on digit adr */ | |
mov x0, 1 | |
mov x8, 64 | |
svc 0 | |
/* Print newline */ | |
mov x2, len1 /* message length (bytes) */ | |
adr x1, nl /* message location (memory address) */ | |
mov x0, 1 /* file descriptor: 1 is stdout */ | |
mov x8, 64 /* write is syscall #64 */ | |
svc 0 /* invoke syscall */ | |
/* loop condition */ | |
add x19,x28,1 | |
mov x28,x19 /* inc by adding 1 to counter */ | |
cmp x28,max /* max - counter */ | |
b.ne loop /* jump to loop if negative */ | |
/* exit */ | |
mov x0, 0 /* status -> 0 */ | |
mov x8, 93 /* exit is syscall #93 */ | |
svc 0 /* invoke syscall */ | |
.data | |
msg: .ascii "Loop: " | |
len= . - msg | |
nl: .ascii "\n" | |
len1= . - nl | |
digit: .ascii " " | |
len2= . - digit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment