Hello, World!!
Hello, World!!
Hello, World!!
Remember syscalls? Earlier, we used them to call an exit. Now let's try another!
This time, instead of getting a pointer to the string Hello World
, we're going to print it to standard output (stdout).
Have another look at the syscall table. Can you find sys_write
, and use to to print the string Hello World!
to stdout?
Note: stdout's file descriptor is 1
.
Hints
- This is a combination of the last several levels
- Refer to
System Calls
, but usesys_write
instead ofsys_exit
and update the arguments accordingly - Refer to
Hello, World!
on how to get a string reference into a register (i.e.,call
/pop
) - Don't forget to read the boilerplate comments - they indicate which registers to use
Now we're starting to get our hands dirty. We can utilize some of the functions within the Linux Syscall Table to start executing our own self-contained code.
To complete this exercise, first I had to look up the sys_write
system call.
So according to this, I need to put a value of 1
in the rax
register, send 1
to the rdi
register (since 1 is STDOUT), the address location of the string I want to send in rsi
, and the size of the string in rdx
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
Note: I wrote all of the code in one little block and didn't realize there were lines starting with "TODO" that showed explicitly what to do. I just merged my own comments with the TODO lines.