R100P0610A01 - assembly/01
This is a part of R100P0917A00 .
Programs are pretty useless without libraries. I mean, I could figure out all of
the syscalls or whatever to open a window… but I’m not doing all that. So for
this one, I learned how to link my assembler up with the C standard library.
main.s
is dated September 7th, 2023 – about nine days before my birthday.
What a nerd.
Through a lot of headache and reverse engineering, I learned what PIE
meant,
and finally fixed the compilation. To compile, no extra flags are needed, as
using PIE
is the default. For example: gcc -o program main.s
.
.global main
.text
message:
.string "Hello, world!"
main:
lea message(%rip), %rdi ; use RIP relative addressing to put the message into rdi
call puts ; call puts
xor %rax, %rax ; set rax to zero (for exit)
ret ; return
Actually, I’m not “putting the message into rdi” here, I’m actually loading the pointer to the message into rdi. But that’s neither here nor there.