Author Topic: i m getting error while executing ld relocation truncated to fit  (Read 9788 times)

Offline kruthika

  • Jr. Member
  • *
  • Posts: 3
i m using ubuntu and while executing the following code for finding the smallest number in the array i m getting
n.o: In function `reading':
n.asm:(.text+0xae): relocation truncated to fit: R_X86_64_8 against `.bss'

when i executed ld function

Code: [Select]
section .bss
digit0: resb 1
digit1: resb 1
array: resb 10
small_num: resb 1
d: resb 1
section .data
msg1: db "enter 10 two-digit numbers:", 10
len1: equ $-msg1
msg2: db "smallest is:"
len2: equ $-msg2
temp: db 10

section .text
global _start

_start:

mov eax, 4
mov ebx, 1
mov ecx, msg1
mov edx, len1
int 80h

mov rbx, array

reading:push rbx

mov eax, 3
mov ebx, 0
mov ecx, digit1
mov edx, 1
int 80h

mov eax, 3
mov ebx, 0
mov ecx, digit0
mov edx, 1
int 80h

mov eax, 3
mov ebx, 0
mov ecx, d
mov edx, 1
int 80h

sub byte[digit1], 30h
sub byte[digit0], 30h

mov al, byte[digit1]
mov dl, 10
mul dl
add al, byte[digit0]

pop rbx
mov byte[rbx], al
add rbx, 1
dec byte[temp]

cmp byte[temp], 0
jg reading

mov rbx, array
mov byte[small_num], array

add byte[temp], 10
push rbx
smallest:pop rbx
mov al, byte[small_num]
mov bl, byte[rbx]
cmp al, bl
jb cont

change: mov byte[small_num], bl
add rbx, 1
dec byte[temp]
cmp byte[temp], 0
push rbx
jne smallest

jmp print

cont: add rbx, 1
dec byte[temp]
cmp byte[temp], 0
push rbx
jne smallest

print: mov eax, 4
mov ebx, 1
mov ecx, msg2
mov edx, len2
int 80h

movzx ax, byte[small_num]
mov bl, 10
div bl
mov byte[digit1], al
mov byte[digit0], ah
add byte[digit0], 30h
add byte[digit1], 30h

mov eax, 4
mov ebx, 1
mov ecx, digit1
mov edx, 1
int 80h

mov eax, 4
mov ebx, 1
mov ecx, digit0
mov edx, 1
int 80h

mov eax, 4
mov ebx, 1
mov ecx, 10
mov edx, 1
int 80h

mov eax, 1
mov ebx, 0
int 80h

please help me to find the error

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: i m getting error while executing ld relocation truncated to fit
« Reply #1 on: January 13, 2013, 07:37:42 AM »
Code: [Select]

mov rbx, array
mov byte[small_num], array
What are you intending to do here? You've asked to move the address of "array", a 64-bit quantity, into a byte. I think more likely you want to move the "[contents]" of array into the byte. Unfortunately(?), we can't move memory to memory (in general), so you'll have to do something like...
Code: [Select]

mov rbx, array
        mov al, [rbx]
mov [small_num], al
I don't have any experience with 64-bit code, and don't have a 64-bit ld to test it on, but I'm almost certain that's your problem.

You've got a strange mixture of 64-bit registers and the old 32-bit int 80h interface, but I understand it'll work. I think I understand now why you didn't want to push or pop in your last example. :)

Best,
Frank