flat assembler
Message board for the users of flat assembler.

Index > Main > Access upper 32 bits of a 64-bit register from 32-bit code?

Author
Thread Post new topic Reply to topic
chriscurl



Joined: 20 May 2020
Posts: 6
chriscurl 18 Jun 2020, 13:06
It would be really great if, in 32-bit programs, one could access the upper half of the registers. I don't need or want 64-bit addresses, but I would love to be able to use the upper (unused) half of the 64-bit registers. If we could do that, that would give us more 32-bit registers.

Is there a way to access the upper 32 bits of the 64-bit registers directly in a 32-bit program? I am pretty confident the answer is "no", but I thought I'd at least ask.

Something along these lines ...

mov eax, rch ; get the upper 32 bts from rcx into eax

Thanks, Chris
Post 18 Jun 2020, 13:06
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20449
Location: In your JS exploiting you and your system
revolution 18 Jun 2020, 13:08
No. There is no encoding that can allow it. The REX prefix is only in 64-bit code.
Post 18 Jun 2020, 13:08
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20449
Location: In your JS exploiting you and your system
revolution 18 Jun 2020, 13:48
BTW: Even if you could read/write the upper halves of the registers, it wouldn't help much. Because as soon as you write a new value to the lower half, the upper half is set to all zeros.
Code:
mov rch, 1 ; using your rch example above
mov ecx, -1 ; also sets the upper half to zeros
mov eax, rch ; eax == 0    


Last edited by revolution on 18 Jun 2020, 22:25; edited 1 time in total
Post 18 Jun 2020, 13:48
View user's profile Send private message Visit poster's website Reply with quote
pabloreda



Joined: 24 Jan 2007
Posts: 116
Location: Argentina
pabloreda 18 Jun 2020, 14:06
You can use in pairs, store 2 32 bits values, for example

Code:
mov ebx,-3
mov ecx,23

; store in rbx the numbers 23|-3
and rbx,$ffffffff
shl rcx,32
or rbx,rcx

;extract in rbx,rcx the numbers
mov rcx,rbx
shr rcx,32
shl rbx,32
shr rbx,32
    


I guess this work
Post 18 Jun 2020, 14:06
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20449
Location: In your JS exploiting you and your system
revolution 19 Jun 2020, 06:15
pabloreda: In 32-bit code you can't access rbx or rcx.
Post 19 Jun 2020, 06:15
View user's profile Send private message Visit poster's website Reply with quote
chriscurl



Joined: 20 May 2020
Posts: 6
chriscurl 19 Jun 2020, 20:42
That was what I figured ... too bad. All those wasted registers just sitting there not being used! Sad Maybe the best reason out there for migrating to 64 bit code.
Post 19 Jun 2020, 20:42
View user's profile Send private message Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie 24 Jul 2020, 00:57
chriscurl wrote:

Something along these lines ...

mov eax, rch ; get the upper 32 bts from rcx into eax

Thanks, Chris


SHLD rax,rcx,32
should do the job. Upperhalf of RCX will be shifted/copied to lower-half of RAX (EAX). Warning: Upper half of RAX will not be cleared.
Post 24 Jul 2020, 00:57
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20449
Location: In your JS exploiting you and your system
revolution 24 Jul 2020, 04:37
fasmnewbie wrote:
SHLD rax,rcx,32
should do the job. Upperhalf of RCX will be shifted/copied to lower-half of RAX (EAX). Warning: Upper half of RAX will not be cleared.
RAX is not accessible from 32-bit code. The upper half of all registers can't be accessed.
Post 24 Jul 2020, 04:37
View user's profile Send private message Visit poster's website 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.