Hi,
My name is Ala'a and I'm new in this forum, as well as new to fasm.
I'm trying to learn assembly macroinstructions by doing small examples. the following example does not do what I expected (which is print hello world!). instead it prints random characters on the console.
upon trying to understand the macro expansion of 'string' and 'write' it seems that the second line of the 'string' which has equ, does not evaluate to the length of string. instead the hello.length equ $-hello and this is substituted in the write macro leading to incorrect string length (I used Fresh-IDE CTRL-U feature to inspect the output).
macro string name, quoted {
name db quoted , 0
name#.length equ $ - name
}
define sys_write 1
define stdout 1
macro write fd*, string* {
mov rax, sys_write
mov rdi, fd
mov rsi, string
mov rdx, string#.length
syscall
}
macro print string* {
write stdout, string
}
define sys_exit 60
define success 0
macro exit status=success {
mov rax, sys_exit
mov rdi, status
syscall
}
format elf64 executable
segment readable writeable
string hello, "Hello World!"
segment executable readable
entry $
print hello
exit
I'm working on Linuxmint 19.1, 64bit, kernel 4.18.0-17-generic.
I tried to read the manual several times, but I think I'm skimming on something important on the order of preprocessing or something else.
thanks for your help.