So I decided to learn a little bit about assembly. I want to write a program that simply adds two integers and outputs the value to stdout. I cannot get it done. I read somewhere that I am not able to load integer values, that is why I read strings and remove the '0'
.
When I try to build the object file, I get following error:
warning: byte data exceeds bounds [-w+number-overflow]
invalid combination of opcode and operands
I am not sure what does it mean. Unluckily, the documentation seems to be very scattered around the web :(
section .text
global _main ;must be declared for linker (ld)
_main: ;tells linker entry point
mov AH,'8' ; read first integer
sub AH, '0'
mov CH, '10' ; read second integer
sub CH, '0'
add AH, CH
add AH, '0'
mov RDX, 4
mov RSI, AH ;message to write
mov RDI, 1 ;file descriptor (stdout)
mov RAX, 0x02000004 ;system call number (sys_write)
syscall ;call kernel
mov RAX, 0x02000001 ;system call number (sys_exit)
syscall ;call kernel
I am using macOS BigSur and compile the code with following command:
nasm -fmacho64 file_name.asm