0

I have the following error with NASM and ld:

tamal@baba-desktop:~/Desktop$ nasm -f elf basic.asm
tamal@baba-desktop:~/Desktop$ gcc basic.o -o basic
basic.o: In function `main':
basic.asm:(.text+0x27): relocation truncated to fit: R_386_16 against `.text'
basic.o: In function `main.keyword': 
basic.asm:(.text+0x30): relocation truncated to fit: R_386_16 against `.text' 
basic.asm:(.text+0x34): relocation truncated to fit: R_386_16 against `.text'
basic.asm:(.text+0x43): relocation truncated to fit: R_386_16 against `.text'
basic.asm:(.text+0x52): relocation truncated to fit: R_386_16 against `.text'
basic.asm:(.text+0x61): relocation truncated to fit: R_386_16 against `.text'
basic.asm:(.text+0x70): relocation truncated to fit: R_386_16 against `.text'
basic.asm:(.text+0x7f): relocation truncated to fit: R_386_16 against `.text'
basic.asm:(.text+0x8e): relocation truncated to fit: R_386_16 against `.text' 
basic.asm:(.text+0x9d): relocation truncated to fit: R_386_16 against `.text'
basic.asm:(.text+0xac): additional relocation overflows omitted from the output
collect2: ld returned 1 exit status

A part of the code is this:

section .text
   global main               

main:
    call get_token              

    cmp ax, STRING              
    je .keyword             

    cmp ax, VARIABLE            
    je near assign              

    cmp ax, STRING_VAR          
    je near assign

    cmp ax, LABEL               
    je main 

    mov si, err_syntax          
    jmp error


 .keyword:
    mov si, token               
    mov di, alert_cmd
    call os_string_compare
    jc near do_alert

    mov di, askfile_cmd
    call os_string_compare
    jc near do_askfile

    mov di, break_cmd
    call os_string_compare
    jc near do_break

    mov di, case_cmd
    call os_string_compare
    jc near do_case

    mov di, call_cmd
    call os_string_compare
    jc near do_call

    .......
    .......
Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
  • 1
    You've left out relevant parts of your code. If we assume that `token` and `alert_cmd` are labels, then you would need a 32-bit or 64-bit register to hold the addresses of those labels. `si` and `di` are 16-bit registers. – Michael Mar 12 '16 at 10:41
  • The intended use of the code is different in the duplicate I found (that one is making a boot sector, I think), but Michael Petch has a long answer there which I skimmed. The error is the same, for the same reason: using a label as a 16bit immediate, but linking as if it was 32bit code. – Peter Cordes Mar 12 '16 at 19:58

0 Answers0