Author Topic: [Solved]Trouble linking simple program.  (Read 21247 times)

Offline rnodal

  • Jr. Member
  • *
  • Posts: 2
[Solved]Trouble linking simple program.
« on: December 03, 2010, 05:07:58 AM »
Hello all,

I'm having trouble linking the following code:
Code: [Select]
SECTION .data ; Section containing initialised data

WordString: dw 'CQ'
DoubleString: dd 'Stop'

SECTION .bss ; Section containing uninitialized data

SECTION .text ; Section containing code

global _start ; Linker needs this to find the entry point!

_start:
nop ; This no-op keeps gdb happy...

mov ax, WordString
mov edx, DoubleString

mov eax, 1 ; Code for Exit Syscall
mov ebx, 0 ; Return a code of zero
int 80H ; Make kernel call

The error that I get when trying to link follows:
Code: [Select]
nasm -f elf -g -F stabs sandbox.asm -l sandbox.lst
ld -o sandbox sandbox.o
sandbox.o:sandbox.asm:19: relocation truncated to fit: R_386_16 against `.data'
make: *** [sandbox] Error 1

I'm running this in Ubuntu 10.10 32bit.

Any input would be highly appreciated it.
I'm trying to learn assembly and the reason why this does not work is really bothering me.

Thanks,

-r
« Last Edit: January 06, 2011, 04:05:06 AM by rnodal »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Trouble linking simple program.
« Reply #1 on: December 03, 2010, 09:09:20 AM »
It isn't clear to me what you're trying to do. If:

Code: [Select]
mov ax, WordString

is supposed to move the "[contents]" of "WordString", "CQ", into ax, then you want:

Code: [Select]
mov ax, [WordString]

If it is intended to move the address of "WordString" into ax - which is what you've asked for - it won't fit (try eax). Essentially the same problem as:

http://forum.nasm.us/index.php?topic=940.0

Best,
Frank


Offline rnodal

  • Jr. Member
  • *
  • Posts: 2
Re: Trouble linking simple program.
« Reply #2 on: January 06, 2011, 04:04:38 AM »
Sorry for late reply.

The code was taken out a book and it was what the author was asking to try but your explanation clarified things for me.
Thank you very much for your time.

-r