NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: cre8eve on September 11, 2014, 07:42:47 PM
-
Hey everyone :) I am trying to write numbers from one array to another, but I am stuck with the topic error.
I have
section .data
source: db '5', '6', '7', '8'
dest: db '0', '0', '0', '0'
section .text
...
mov rax, source ; copying the first number (5) into rax register
mov dest, rax ; ERROR: Mach-O 64-bit format does not support 32-bit absolute addresses
...
I compile it with -f macho64 option
How can I rewrite from one array to another? Any suggestions?
Thanks in advance.
-
Well... Finally... at the end of the day... I think (not sure of this) there's an error in Nasm's "-f macho64" output format. You may need to use (G)as, or perhaps try Yasm.
However, we can discuss what else is wrong with your code, and why it wouldn't have worked anyway.
section .data
source: db '5', '6', '7', '8'
dest: db '0', '0', '0', '0'
What you've got here is characters, not numbers. They're numbers, too, of course, but probably not the numbers you want.
section .text
...
mov rax, source ; copying the first number (5) into rax register
Comment does not match code. You've moved the address of your array into rax.
mov rax, [source]
This would move the first 64-bit number (8 bytes) into rax. rax would be 0x3030303038373635. I doubt this is what you want. To move a single byte into a register, try:
mov al, [source]
This is still going to be the character '5', not the number 5.
mov dest, rax ; ERROR: Mach-O 64-bit format does not support 32-bit absolute addresses
...
This attempts to move rax into the address of "dest" - an immediate value. Reminds me of the old Hendrix tune "If Six Were Nine". Simply isn't going to work - no such instruction.
mov [dest], rax
... would move rax - 64-bits, 8 bytes - into your buffer... which is only 4 bytes, causing an overflow. Probably what you want - to move just one byte (one character):
mov [dest], al
I don't know what to advise you, Cre8eve. You appear to be fairly new at this (no offense intended - none of us are born knowing this stuff) and as such, probably don't want to mess with a potentially buggy format. AFAIK, "-f macho32" (or just "-f macho") works. There may be a problem convincing a 64-bit ld that you want 32-bit code - there is in Linux. For Linux, we tell ld "-m elf_i386", but that isn't going to work for MacOS. "objdump -i" produces a list of supported formats - this may work for Mac, too(?). Then... if you attempt to link against C libraries, there may be an issue of incompatible libraries (there is in Linux)...
I wish I had a better answer for ya!
Best,
Frank
-
Put DEFAULT REL near the top of your source if you are using macho64: more info (http://forum.nasm.us/index.php?topic=1932.msg8737#msg8737)
I also reposted an older Mac OS X demo, which may help guide you: http://forum.nasm.us/index.php?topic=1972.0 (http://forum.nasm.us/index.php?topic=1972.0)