Skip to content

Instantly share code, notes, and snippets.

@marcobeltempo
Created November 26, 2017 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcobeltempo/95c58668894a97c082fe1200989a0646 to your computer and use it in GitHub Desktop.
Save marcobeltempo/95c58668894a97c082fe1200989a0646 to your computer and use it in GitHub Desktop.
aarch_9_loop
.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
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