As the question states, I want to print numbers, that are multiple digits, in aarch64.
Usually when solving proplems I python them first to see if they work, especially since I am very new to anything assembly. My pythonic solution was
number = 1234
while number != 0:
digit = 1234 % 10 # always gives me the last digit
print(digit, end='') # to print the digit and not the next line
number = number - digit # to remove the digit I just got so the last digit is 0
number = number / 10 # to remove said last digit and shorten number by 1
The way I tried to impement this in AARCH64:
printNumber:
mov x16, #10 /* apparently need this for udiv/msub */
udiv x14, x12, x16 /* x12 is the number I defined above, bc idk what registers are save to use (e.g. when syscall 64, print, happens, 0-8 are used) */
msub x13, x17, x16, x12 /* thanks to: https://stackoverflow.com/questions/35351470/obtaining-remainder-using-single-aarch64-instruction */
sub x12, x12, x13 /* x13 is what above is digit, x12 is number */
udiv x12, x12, x16
add x13, x13, #48 /* digit to string, possible error source 1 */
mov x0, #1 /* the print part */
mov x1, x13 /* the other part where I suspect a mistake */
mov x2, #1
mov w8, #64
svc #0
cmp x12, #0 /* the loop part */
beq exit /* genereric exit method I left out */
b printNumber
State of the code: It compiles and runs without problems, though it prints nothing, I cannot debug since I Program this with an actual aarch64 device and am not using an emulator (though I am sure there is a way I don't know off)
I hope it is clear what I am trying to do, I am aware of some issues, like I should be using the stack for some of those things, but I can get that to work I hope. I also hope it is visible that I put some effort into this and have tried to look for a solution like this, but can not find anyone who does it like this, or any other non-c-lib way that prints numbers (note that I don't need the number as str, I really only want to print it)