flat assembler
Message board for the users of flat assembler.
Index
> Main > 16 bit data vs. 32 bit address |
Author |
|
Madis731 29 Sep 2005, 14:44
hi,
I've got a problem with fasm Crying or Very sad I'm using 32bit code and I got a label some where (lets name it _label). Now I want to save the address of that label like this (in a 16bit variable): dw _label Why isn't that working: Fasm spits out an error ("error: invalid use of symbol.")? How can I fix that? Can I use something like: sw _label >> 16 when I want to get the upper 16 bits of the address? I'm really sorry if that's already explained in the manual, but I just couldn't find it. _label >> 16 looks like this in FASM: Code: _label shr 16 ;pronounced SHift Right The addresses in 32-bit are always 32-bit too so taking 16 bits from it doesn't make sense. But if you'd really like to do that then: Code: ;some code _label: ;do some stuff mov eax,_label ;or you could do: lea eax,[_label] shr eax,16 ;16 upper bits of eax are now in ax and you can access it like this: mov word[data_area],ax ;-OR- cmp ax,word[binary_data] ;etc. Hope it helped... |
|||
29 Sep 2005, 14:44 |
|
bluecode 29 Sep 2005, 19:13
Quote: The addresses in 32-bit are always 32-bit too so taking 16 bits from it doesn't make sense That does make sense, eg. for a descriptor in the gdt you got two different 16bit fields that take one half of a 32bit address. That's a deisgn flaw in the i386 I know. |
|||
29 Sep 2005, 19:13 |
|
revolution 30 Sep 2005, 00:54
Actually it depends on your output format. If you use binary format then what you have above will work fine if _label is < 64K, if you use PE format (or any relocatable format) then you can't use a symbol like that because FASM can't make a 16 bit relocatable value for a 32 bit address.
|
|||
30 Sep 2005, 00:54 |
|
bluecode 30 Sep 2005, 11:22
I'm using elf. But why can (imho) nasm then do that?
As I already said, I need the address split up in two 16Bit parts (for gdt/idt entries), so it should work for _label > 2^16! Is it just a missing feature in fasm? |
|||
30 Sep 2005, 11:22 |
|
Tomasz Grysztar 30 Sep 2005, 11:38
The "invalid use of symbol" means you are using some relocatable format, perhaps object file. Neither ELF nor COFF has any relocation type that would allow splitting 32-bit address into two separate values. I see two possible reasons for your problem: either you are writing some code with absolute addresses in mind, but are using relocatable format - in such case either use some format that doesn't have relocations (like binary), or use "org" to change addressing to absolute (but make sure you know what you're doing). Second possible case is that you're using relocatable (object) format because you need your code to be relocatable/linkable - in such case you have to split the 32-bit address into parts at the run-time, because only at run-time the whole 32-bit address (after being relocated) will be known.
|
|||
30 Sep 2005, 11:38 |
|
bluecode 30 Sep 2005, 12:43
hi,
if I use org, is it also possible to switch back to relocateable address, that means only turning on absolute addressing for some labels? Thanks for your replies! |
|||
30 Sep 2005, 12:43 |
|
Tomasz Grysztar 30 Sep 2005, 12:59
You can do something like:
Code: macro startorg addr { org_delta = $ - addr org addr } macro endorg { org $ + org_delta } startorg 1000h ; code/data that will be placed at absolute address 1000h endorg |
|||
30 Sep 2005, 12:59 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.