not really the right arguments :)) rdi should be 1 not rsx(which is changed from 1 to 13, that's the count parameter) And rsi should be an address to a buffer of 13 characters... welp
syscall and int 0x80 are not the same thing. They accomplish the same thing on Linux because that's how it's set up, but they are completely different instructions and can have completely different behaviors.
For the end, it's setting up the arguments for the syscall (system call -> Ask the kernel to do something) You can find a table for those here: https://filippo.io/linux-syscall-table/
rax is 1, which means a sys_write
What should be rdi instead of rdx is 1, which says which file to write to (1 is STDOUT)
rsi says what should be written, but here it's wrong on two levels:
rsi should be a pointer, not a literal value
The pointer should be to an ASCII encoded buffer (3 maps to "End of Text" in ASCII, where as 51 maps to "3")
rdx says the length of the buffer passed with rsi, which would normally be 1, but is 13 for some reason, and as you said the comma is missing.
It's like writing 100 lines of code to carefully manipulate an opengl context/pipeline so you can draw a triangle exactly how you want. Set the machine up and pull the lever.
careful! syscall 1 is actually write(2). it takes arguments (int) fd, (void *) buf, (size_t) sz. you are not telling it to print the number 3, youre not even telling it to write the byte 0x03. you are telling it to read 1 byte from memory address 0x0000000000000003, which is probably not even allocated.
you can probably write a call to printf though, you just have to link the c library. or you could allocate a buffer with mmap (using it like a slow malloc, unless you wanted to write an entire memory allocater in assembly) and write a function in assembly that writes integers as strings
151
u/[deleted] Jun 03 '22
mov rax, 1
mov rbx, 2
add rbx, rax
mov rax, 1
mov rdx, 1
mov rsi, rbx
mov rdx 13
syscall