Created
November 20, 2017 03:43
-
-
Save marcobeltempo/cd03a52fd54fc53f0259159554302848 to your computer and use it in GitHub Desktop.
9 count loop - aarch64 assembler
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 /* starting value for the loop index; note that this is a symbol (constant), not a variable */ | |
max = 31 /* loop exits when the index hits this number (loop condition is i<max) */ | |
ten = 10 | |
_start: | |
mov x19, start | |
mov x22, ten | |
loop: | |
adr x1, msg | |
mov x2, len | |
mov x0, 1 | |
mov x8, 64 | |
svc 0 | |
adr x23, msg | |
add x19, x19, 1 | |
udiv x20, x19, x22 | |
msub x21, x22, x20, x19 | |
cmp x20, 0 | |
beq skip | |
add x20, x20, '0' | |
strb w20, [x23,6] | |
skip: | |
add x21, x21, '0' | |
strb w21, [x23,7] | |
cmp x19, max | |
bne loop | |
mov x0, 0 | |
mov x8, 93 | |
svc 0 | |
.data | |
msg: .ascii "Loop: 0\n" | |
len = . - msg |
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
aarch_30_loop: file format elf64-littleaarch64 | |
Disassembly of section .text: | |
00000000004000b0 <_start>: | |
4000b0: d2800013 mov x19, #0x0 // #0 | |
4000b4: d2800156 mov x22, #0xa // #10 | |
00000000004000b8 <loop>: | |
4000b8: 10080281 adr x1, 410108 <msg> | |
4000bc: d2800122 mov x2, #0x9 // #9 | |
4000c0: d2800020 mov x0, #0x1 // #1 | |
4000c4: d2800808 mov x8, #0x40 // #64 | |
4000c8: d4000001 svc #0x0 | |
4000cc: 100801f7 adr x23, 410108 <msg> | |
4000d0: 91000673 add x19, x19, #0x1 | |
4000d4: 9ad60a74 udiv x20, x19, x22 | |
4000d8: 9b14ced5 msub x21, x22, x20, x19 | |
4000dc: f100029f cmp x20, #0x0 | |
4000e0: 54000060 b.eq 4000ec <skip> | |
4000e4: 9100c294 add x20, x20, #0x30 | |
4000e8: 39001af4 strb w20, [x23,#6] | |
00000000004000ec <skip>: | |
4000ec: 9100c2b5 add x21, x21, #0x30 | |
4000f0: 39001ef5 strb w21, [x23,#7] | |
4000f4: f1007e7f cmp x19, #0x1f | |
4000f8: 54fffe01 b.ne 4000b8 <loop> | |
4000fc: d2800000 mov x0, #0x0 // #0 | |
400100: d2800ba8 mov x8, #0x5d // #93 | |
400104: d4000001 svc #0x0 |
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 /* starting value for the loop index; note that this is a symbol (constant), not a variable */ | |
max = 10 /* loop exits when the index hits this number (loop condition is i<max) */ | |
ten = 10 | |
_start: | |
mov x19, start | |
mov x22, ten | |
loop: | |
adr x1, msg | |
mov x2, len | |
mov x0, 1 | |
mov x8, 64 | |
svc 0 | |
adr x23, msg | |
add x19, x19, 1 | |
udiv x20, x19, x22 | |
msub x21, x22, x20, x19 | |
cmp x20, 0 | |
beq skip | |
add x20, x20, '0' | |
strb w20, [x23,6] | |
skip: | |
add x21, x21, '0' | |
strb w21, [x23,7] | |
cmp x19, max | |
bne loop | |
mov x0, 0 | |
mov x8, 93 | |
svc 0 | |
.data | |
msg: .ascii "Loop: 0\n" | |
len = . - msg |
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
aarch_9_loop: file format elf64-littleaarch64 | |
Disassembly of section .text: | |
00000000004000b0 <_start>: | |
4000b0: d2800013 mov x19, #0x0 // #0 | |
4000b4: d2800156 mov x22, #0xa // #10 | |
00000000004000b8 <loop>: | |
4000b8: 10080281 adr x1, 410108 <msg> | |
4000bc: d2800122 mov x2, #0x9 // #9 | |
4000c0: d2800020 mov x0, #0x1 // #1 | |
4000c4: d2800808 mov x8, #0x40 // #64 | |
4000c8: d4000001 svc #0x0 | |
4000cc: 100801f7 adr x23, 410108 <msg> | |
4000d0: 91000673 add x19, x19, #0x1 | |
4000d4: 9ad60a74 udiv x20, x19, x22 | |
4000d8: 9b14ced5 msub x21, x22, x20, x19 | |
4000dc: f100029f cmp x20, #0x0 | |
4000e0: 54000060 b.eq 4000ec <skip> | |
4000e4: 9100c294 add x20, x20, #0x30 | |
4000e8: 39001af4 strb w20, [x23,#6] | |
00000000004000ec <skip>: | |
4000ec: 9100c2b5 add x21, x21, #0x30 | |
4000f0: 39001ef5 strb w21, [x23,#7] | |
4000f4: f1002a7f cmp x19, #0xa | |
4000f8: 54fffe01 b.ne 4000b8 <loop> | |
4000fc: d2800000 mov x0, #0x0 // #0 | |
400100: d2800ba8 mov x8, #0x5d // #93 | |
400104: d4000001 svc #0x0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment