Tip:
Highlight text to annotate it
X
Hello and welcome. This is tutorial 2. Here we'll be looking
at Load Register and C Library functions. The C library is a way to extend your assembly
program, namely to get keyboard input and to print values to the screen.
Load Register: Load Register is a lot like MOV, which we
covered in tutorial 1. I said last time that it was a "special move"
command. It will place a byte, word, half word, signed byte or signed half word into
the register. A byte is 8bits, a signed byte has the most
significant bit reserved for negative/positive numbers. Negative will have a 1 and positive
will have a 0, therefore the overall addressable byte width is 7 bits.
Let's go back to test.s, which looks something like this. We now update the code to output the number
to the screen. code:
.Lout: @ literal - reserved amount of memory - convention is to declare at top.
.asciz "%d\n" @ascii zero-terminated string - %d means decimal and "\n" means newline
ldr r0, =.Lout @ load literal into register 0.
mov r1, #10 @ mov r1 to the immediate decimal 10
bl printf @ branch with link - call printf C library function and return.
BL will put the next instruction into R14 (or the Link Register), so that the program
will return. Otherwise the computation would end with the C Library call.
Next
time we'll talk about the max limit for the registers and how to overcome this
using arithmetic functions, Load Register and printf.
Hopefully this is helpful.