Here is your edited version: We have a plan. Today is Assembly Day 4, and we're going to learn how to convert a number into a string and print it. This is not as simple as it sounds in assembly, especially on ARM64, which is the chip architecture we're using.
The reason we convert numbers to strings is so we can print and read them, since numbers are stored as binary and need to become ASCII characters to be printed out. I did some prep and have a file ready for us that does this number-to-string job. In assembly, we define a function with a label.
This function takes three registers as input, one for the number, one for the buffer, and one for the buffer size, and overwrites some of these inputs with the result. We also clobber a bunch of registers, which just means we're overwriting them, and that can get confusing. We saw in a previous lesson that STP handles pointers, ADD just adds, and labels are used as jump points in the code for loops and branches.
Labels starting with numbers are a bad idea, so it's better to use names like loop1 or break. Some of the labels in our code seem unused, but then we found out they're needed for jumps. We also learned that CBNZ is a conditional branch that checks if a register is not zero, and NZ means not zero.
UDIV is the unsigned divide instruction, which makes sense because we divide the value by 10 to peel off digits. It’s all about taking a number like 1000, pulling out each digit one at a time, and turning those into their ASCII versions so they can be printed. We even saw how to use a string literal in assembly, which was cool.
Some things, like STRB, are still a bit murky but we're making progress. I feel like I just started to really understand assembly, it’s starting to click.