I'm currently working my way through learning writing my own programming language. Currently my language supports adding two numbers or subtracting and I want to now convert my AST into assembly. I'm running on a Linux machine in the x86_64 architecture and I've gone through the hello world tutorial with code that looks like:
section .data
string1 db "Hello World!",10,0
section .text
global _start
_start:
mov rax, 1
mov rdi, 1
mov rsi, string1
mov rdx, 13
syscall
mov rax, 60
mov rdi, 0
syscall
and I get what is happening here. Where I'm a little lost is in code like so:
section .text
global _start
_start:
mov rax, 1
mov rbx, 2
add rax, rbx
mov rsi, rbx
mov rax, 1
mov rdi, 1
mov rdx, 1
syscall
mov rax, 60
mov rdi, 0
syscall
As I understand what I've been reading, the above code should put the value 1
into the register rax
, 2
into the register rbx
, sum those registers and store it in rbx
. Then, the value of rbx
should be moved into rsi
which should be the buffer argument for the syscall
for write. Instead, nothing is printed to my console. If I put "3"
in the .data
section as a variable I can grab that and print it. So is it just the case that I cannot print an integer and it has to be stored in some data variable?