NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: unicornx on March 15, 2020, 02:20:40 AM
-
Hello, I have some errors then linking with ld:
I am writing a simple 16-bit real-mode demo code to print some char on screen, and assemble with nasm:
[org 0x7c00]
mov ah, 0x0e
mov al, "1"
int 0x10
mov al, the_secret ; just want to demo a wrong usage
int 0x10
mov al, "2"
int 0x10
mov al, [the_secret] ; correct usage
int 0x10
jmp $ ; infinite loop
the_secret:
db "X"
times 510-($-$$) db 0
dw 0xaa55
I use nasm -f bin bootsect.asm -o bootsect.bin
, and it's ok
Then I tried to use gdb to trace the code, so I tried following:
I removed first line [org 0x7c00]
due to nasm will report "error: unrecognised directive [org]"
So I use ld to assign the load address with "-Ttext=0x7c00", following are my commands:
$ nasm bootsect.asm -f elf -g -F dwarf -o bootsect.o
$ i386-elf-ld -Ttext=0x7c00 bootsect.o -o bootsect.elf
But ld reports error:
bootsect.o:bootsect.asm:6:(.text+0x7): relocation truncated to fit: R_386_8 against `.text'
Checked code and I see this code line causes the problem
mov al, the_secret
I know it is not good writing, but I would have to keep this code due to I just want to write a demo and I know it could pass build with "nasm -f bin". So my question is how to pass building with ld so I can use gdb to trace this demo? Thanks in adv.
-
"the_secret" is a memory address/offset, so will not fit in an 8-bit register. I'm surprised it assembled, sounds like a bug to me.
-
Do you mean it is a bug for nasm? I am using NASM version 2.11.08
-
It sounds like a nasm bug if it assembles a 16/32/64 bit number into an 8-bit register. It shouldn't be possible.