I am using GNU Assembler and I am trying to learn aarch64 assembly by making a simple calculator, I cannot store the result value inside a data called results
.global main
.section .data
debug_msg1: .asciz "True"
debug_msg1_len = . - debug_msg1
format:
.ascii "results is %d\n"
format_len = 10
message_0:
.asciz "Hello, World!\n"
message_0_len = . - message_0
message_1:
.asciz "Enter mode +,-,*,/: "
message_1_len = . - message_1
message_2:
.asciz "enter the first num: "
message_2_len = . - message_2
message_3:
.asciz "enter the second num: "
message_3_len = . - message_3
message_4:
.asciz "results is "
message_4_len = . - message_4
.section .bss
num1: .skip 10
num2: .skip 10
operator: .skip 1
.lcomm results, 10
.section .text
main:
ldr x1, =message_0
ldr x2, =message_0_len
bl print
ldr x1, =message_1
ldr x2, =message_1_len
bl print
ldr x1, =operator
ldr x2, =10
bl input
ldr x1, =message_2
ldr x2, =message_2_len
bl print
ldr x1, =num1
ldr x2, =10
bl input
ldr x1, =message_3
ldr x2, =message_3_len
bl print
ldr x1, =num2
ldr x2, =10
bl input
ldr x1, =operator
ldr x2, =20
bl print
ldrb w0, [x1]
sub w0, w0, 0x0
ldr x1, =num1
ldrb w3, [x1]
sub w3, w3, '0'
ldr x1, =num2
ldrb w4, [x1]
sub w4, w4, '0'
cmp w0, #'+'
beq add
bl exit
print:
mov x0, 1
mov w8, 64
svc #0
ret
input:
mov x0, 0
mov w8, #63
svc #0
ret
add:
ldr x1, =results
add w3, w3, w4
str w3, [x1]
sub sp, sp, #16
ldr x0, =format
ldr x2, =10
bl printf
add sp, sp, #16
bl exit
exit:
mov w8, #93
mov x0, #0
svc #0
true:
ldr x1, =debug_msg1
ldr x2, =debug_msg1_len
bl print
ret
exit_err:
mov w8, #93
mov x0, #1
svc #0
What I have tried:
- using different registers
- different data types for results