Lab 3 - Aarch64 assembly challenge
Introduction
This week, I tried to overcome the aarch64 compiler challenge at Lab3. The task is very simple, it is just creating multiply table from 1 to 12 with aarch64 assembly compiler.
Before creating the code, I made it with C language.
.text
.globl _start
min=1
max=13
_start:
mov x19, min // i = 1
Outer loop start:
initially I set x15, x16 to 10 and 100 respectively to calculate tens and hundreds place. Once I calculate tens place of index in outer loop I converted it to ASCII type and then add it to 'msg'
outer_loop:
mov x15, 10
mov x16, 100
cmp x0, 13 // if i < 13
b.ge end // break
udiv x12, x19, x15
add x12, x12, '0'
adr x1, msg
mov x0, 1
strb w12, [x1, 1]
mov x20, 1 // z = 1
inner_loop:
cmp x1, 13 // if z < 13
b.ge outer_loop_end // break
mul x13, x20, x19 // x2 = i * z
// hundred place
udiv x21, x13, x16
add x21, x21, '0'
strb w21, [x1, 9]
//tens place
udiv x22, x13, x15
add x22, x22, '0'
strb w22, [x1, 10]
//unit place
msub x23, x22, x15, x13
msub x23, x21, x16, x13
strb w23, [x1, 11]
add x20, x20, 1 // z++
add x20, x20, '0'
strb w20, [x1, 6]
udiv x24, x20, x15
add x24, x24, '0'
strb w24, [x1, 5]
b inner_loop
After inner loop outer loop end start so that It increase outer loop index.
outer_loop_end:
add x19, x19, 1 // i++
udiv x25, x19, x15
add x25, x25, '0'
strb w25, [x1]
b outer_loop
End of the code and msg format section:
end:
mov x0, 0
mov x8, 93
svc 0
.data
msg: .ascii " # x # = #\n"
len= . - msg
댓글
댓글 쓰기