flat assembler
Message board for the users of flat assembler.

Index > Main > invalid use of symbol (???)

Author
Thread Post new topic Reply to topic
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 14 May 2011, 21:58

??? Shocked
Code:
format ms coff

mov eax,toto-1 ; ok,does compile

toto:
    
Code:
format ms coff

mov eax,1-toto ;<--- does not compile (invalid use of symbol)

toto:
    
with "toto-1", no problem, it does compile
but,
with "1-toto", it does not compile ... "invalid use of symbol" Shocked

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 14 May 2011, 21:58
View user's profile Send private message Send e-mail Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 15 May 2011, 14:08
Seems COFF doesn't have "-value" relocation. Use two instructions. And yes, better error message is really needed
Post 15 May 2011, 14:08
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 15 May 2011, 15:10

1
- 0x00000002 = 1+(0-0x00000002) = 1 + 0xFFFFFFFE

If "FASM" knows the value of "A",
then it can easily compute "1-A ".
it's not a matter about the format coff, but a matter about fasm compiler.
I really don't see where is the problem!
Code:
format MS COFF

mov eax,   A_2      ; ok

mov eax, - A_2      ; does not compile

;Yet, "-A2" is simply equal to "neg A2" !!!

A_2:
    


_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 15 May 2011, 15:10
View user's profile Send private message Send e-mail Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 15 May 2011, 16:25
fasm only knows that A_2 is at some distance of an unknown base address.

Lets suppose A_2 is at distance zero of base address (something that happens if you place the "A_2:" just below "format MS COFF", check with a hex editor using the non negative address), what value would you expect fasm to place in the imm32 part of the instruction so that the linker can latter fix by adding the link-time base address? (remember, if the link-time address is in the [0..2^31 - 1] range then eax must be loaded with a negative value at run-time, and if the address is in the [2^31-..2^32 - 1] range then eax should have a positive value at run-time)

[edit]These are the relocation types available:

Intel 386 Processors
IMAGE_REL_I386_ABSOLUTE 0x0000 The relocation is ignored.
IMAGE_REL_I386_DIR16 0x0001 Not supported.
IMAGE_REL_I386_REL16 0x0002 Not supported.
IMAGE_REL_I386_DIR32 0x0006 The target’s 32-bit VA.
IMAGE_REL_I386_DIR32NB 0x0007 The target’s 32-bit RVA.
IMAGE_REL_I386_SEG12 0x0009 Not supported.
IMAGE_REL_I386_SECTION 0x000A The 16-bit section index of the section that contains the target. This is used to support debugging information.
IMAGE_REL_I386_SECREL 0x000B The 32-bit offset of the target from the beginning of its section. This is used to support debugging information and static thread local storage.
IMAGE_REL_I386_TOKEN 0x000C The CLR token.
IMAGE_REL_I386_SECREL7 0x000D A 7-bit offset from the base of the section that contains the target.
IMAGE_REL_I386_REL32 0x0014 The 32-bit relative displacement of the target. This supports the x86 relative branch and call instructions.[/edit]
Post 15 May 2011, 16:25
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 15 May 2011, 19:24

Thank you Loco,
ok, I really begin to understand. Thank you for taking the time to explain.
The coff format is more complicated than I thought.
I'll buy a good book about this topic.
It is time for me to get to the bottom of things and understand it in depth!

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 15 May 2011, 19:24
View user's profile Send private message Send e-mail Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 15 May 2011, 20:48

here's a better error message for this case.
(that "invalid use of symbol")
Code:
;EXPRCALC.INC
;------------
invalid_sub:
        cmp     [error_line],0
      jne     sub_values
  mov     eax,[current_line]
  mov     [error_line],eax
    mov     [error],invalid_subtraction
 jmp     sub_values

;ERRORS.INC
;----------
invalid_subtraction:
    push    _invalid_subtraction
        jmp     error_with_source

;MESSAGES.INC
;------------
_invalid_subtraction  db '  invalid subtraction',0

    

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 15 May 2011, 20:48
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.