View previous topic :: View next topic |
Author |
Message |
deama1234 Master Cheater Reputation: 3
Joined: 20 Dec 2014 Posts: 328
|
Posted: Wed Mar 04, 2015 3:27 pm Post subject: How to push and pop xmm registers? |
|
|
I can't seem to find a way to push and pop them like with the standard "eax,ecx..." registers. Any of you guys know how?
|
|
Back to top |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Wed Mar 04, 2015 8:50 pm Post subject: |
|
|
Just trying to save the previous value to restore it later?
Code: | alloc(backup,16)
registersymbol(backup)
movdqu dqword [backup],xmm0 // save it
movdqu xmm0,dqword [backup] // restore it |
|
|
Back to top |
|
|
deama1234 Master Cheater Reputation: 3
Joined: 20 Dec 2014 Posts: 328
|
Posted: Thu Mar 05, 2015 11:17 am Post subject: |
|
|
Oh, I thought it was gonna be something like:
|
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Thu Mar 05, 2015 2:16 pm Post subject: |
|
|
when you are 100% sure that game code uses only lower half of xmm register (you see movss or movsd or movd or movq or ...., not movaps, not movapd, not .....), you can use this:
Code: | movlhps xmm0,xmm0 // Moves low quadword of xmm0 to high quadword of xmm0
movlhps xmm1,xmm1 // Moves low quadword of xmm1 to high quadword of xmm1
// "push"
do stuff on xmm0 and xmm1. some calculations, compares, etc
movhlps xmm0,xmm0 // Moves high quadword of xmm0 to low quadword of xmm0
movhlps xmm1,xmm1 // Moves high quadword of xmm1 to low quadword of xmm1
// "pop" |
(there are MOVLHPS and MOVHLPS)
_________________
Last edited by mgr.inz.Player on Fri Mar 06, 2015 5:48 pm; edited 1 time in total |
|
Back to top |
|
|
STN I post too much Reputation: 42
Joined: 09 Nov 2005 Posts: 2672
|
Posted: Thu Mar 05, 2015 3:17 pm Post subject: |
|
|
deama1234 wrote: | Oh, I thought it was gonna be something like:
|
This is not possible because
a)xmm registers set are 128-bit registers (that is pretty huge) and push/pop can only handle 32bit values. There are the instructions pushq/popq for handling 64bit registers (rax, rcx etc) with some limitations (can't handle immediate 64bit values).
b)Most importantly, you know you can't use push to save FPU stack registers even in 32bit (st0, st1 etc) but need specific instruction set called the fpu instruction set to handle them. Same way, you will need special instruction set (THE SSE instruction set) to handle xmm registers.
That is the best i could explain in laymen terms.
Lastly, i guess you could use the FXSAVE and FXRSTOR instructions set but that is a bit extreme and has some limitations (http://x86.renejeschke.de/html/file_module_x86_id_128.html).
PS: To expand on Zanzer's answer, if you can't be arsed to allocate memory and define a symbol (its a hassle) use this.
//For saving of just one xmm register e.g xmm0
sub esp, 16 // allocate space on stack
movdqu dqword [esp], xmm0
//Pop back the value from stack to xmm0
movdqu xmm0, dqword [esp]
add esp, 16 // re-align the stack
Ot if you are manipulating multiple xmm registers, just reserve appropriate space on stack and re-align once you are done (pop or restore emulation) or set up a stack frame.
_________________
|
|
Back to top |
|
|
deama1234 Master Cheater Reputation: 3
Joined: 20 Dec 2014 Posts: 328
|
Posted: Fri Mar 06, 2015 4:01 pm Post subject: |
|
|
Thanks guys!
|
|
Back to top |
|
|
|