flat assembler
Message board for the users of flat assembler.
Index
> Main > 32 bits pointers in 64 bits mode |
Author |
|
pabloreda 08 May 2012, 00:23
Hi
I need a 32 bits pointers to code and to data in 64 bits mode for a compiler. I read http://www.codeproject.com/Articles/28818/32-bit-pointers-in-a-64-bit-world but perhaps someone here have a better idea. I need 32 bits adress because with this I can compile the same code without modification. thanks Pablo |
|||
08 May 2012, 00:23 |
|
pabloreda 10 May 2012, 14:29
thanks revolution,
my english is bad bad, i try to explain more. In my compiler I have pointer to code and pointer to data. then Code: #var 23 I traslate to Code: var dd 23 define a variable with the value 23 Code: #var2 'var I traslate to Code: var2 dd var and with the address to code are the same history Code: #codes 'tocode Code: codes dd tocode well, I need keep the size of pointers in 32bits because I like to compile the same code in 32 bits and 64 bits. because, for example, I add 4 to address for get the next value, and if I change this size need change the pointers aritmethics in the program. I read about RIP relative but a address to code in a variable can be called from many places. I hope this explanation are better. thanks again Pablo |
|||
10 May 2012, 14:29 |
|
revolution 10 May 2012, 14:43
Do you mean this?
Code: align 4 var dd 12345 var2 dd var/4 mov esi,[var2] ;var2 contains a 1/4th pointer to var. rsi is zero extended from esi mov eax,[rsi*4] ;get the value of var |
|||
10 May 2012, 14:43 |
|
pabloreda 10 May 2012, 20:22
I have this
Code: use32 vectorlist dd rut1,rut2 rut1: mov eax,1 ret rut2: mov eax,2 ret main: mov ebx,vectorlist mov eax,[ebx+4] call eax ret I need this Code: use64 vectorlist dd rut1,rut2 ; qd ??? rut1: mov rax,1 ret rut2: mov rax,2 ret main: mov rbx,vectorlist mov rax,[rbx+4] ; +8 ?? call rax ret this work ? Code: use64 vectorlist dd rut1-inicode,rut2-inicode inicode: rut1: mov rax,1 ret rut2: mov rax,2 ret main: mov rbx,vectorlist movsx rax,dword [rbx+4] add rax,inicode call rax ret |
|||
10 May 2012, 20:22 |
|
LocoDelAssembly 10 May 2012, 20:50
Don't use sign extension, the upper 2GB of the 32-bit address space would map to kernel memory that way.
Code: use64 vectorlist dd rut1-inicode,rut2-inicode inicode: rut1: mov eax,1 ; Instead of rax since the CPU will clear the upper 32-bits automatically ret rut2: mov eax,2 ; Instead of rax since the CPU will clear the upper 32-bits automatically ret main: mov eax, [vectorlist+4] add rax, inicode call rax ret BTW, have you considered the possibility of forcing memory allocation to be always below 4G? That would require very little effort to implement 64-bit addressing arithmetic with 32-bit pointers (but this might not be a viable option for you) |
|||
10 May 2012, 20:50 |
|
pabloreda 10 May 2012, 21:02
thank for the tips Loco
more easy for my to talk (sorry english readers) Genero el codigo para compilar en FASM puedo decirle que el .exe se cargar en memoria abajo de 4G? esa decision no la toma el SO? No utilizo asignacion de Memoria ni garbage collector. asi que creo que como decis, no es viable esa opcion. hay alguna posibilidad de utilizar los segmentos en 64 bits ? ya que con esto lo solucionaria.. |
|||
10 May 2012, 21:02 |
|
LocoDelAssembly 10 May 2012, 21:48
I'll have to reply in English sorry (PM me if you don't understand the answer)
So the first two questions are whether you can tell the OS to load the executable below 4G or not. If you avoid relocations (something that is the default in fasm for executable formats), the OS will be forced to load everything at the same location as indicated in compile-time (but not the DLLs/shared libs you use, those can still be loaded anywhere). I believe that with "ELF64 executable" this is also the case. On the other hand, if you need your executables relocatable for ASLR compatibility (or you even need to create DLLs/shared libs), then you have to stick with the more laborious pointer arithmetic. The third question is if there is a chance of using segmentation in 64-bit. I'll let wikipedia answer that for me. |
|||
10 May 2012, 21:48 |
|
pabloreda 10 May 2012, 22:12
thank a lot!!
|
|||
10 May 2012, 22:12 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.