Page 2 of 2
Re: Switching tasks and global protection fault
Posted: Thu Jul 09, 2020 6:03 am
by mrjbom
Octocontrabass wrote:mrjbom wrote:Code: Select all
pop dword [esp + 48] ;pop cs
pop word [esp + 32] ;pop eip
Functions clobber the arguments you push onto the stack. Use "add esp, 8" or "pop eax; pop eax" to clean up the stack after the function call.
Why should I use add esp, 8? Shouldn't I use add esp, 6? After all, eip and cs take up 6 bytes.
Re: Switching tasks and global protection fault
Posted: Thu Jul 09, 2020 6:11 am
by nexos
CS and EIP are 32 bits, just like every other register on IA32.
Re: Switching tasks and global protection fault
Posted: Thu Jul 09, 2020 6:19 am
by mrjbom
nexos wrote:CS and EIP are 32 bits, just like every other register on IA32.
Here it is, thanks for the information, I did not expect.
Re: Switching tasks and global protection fault
Posted: Thu Jul 09, 2020 7:09 am
by bzt
mrjbom wrote:Here it is, thanks for the information, I did not expect.
Plus, all values on the stack must be aligned. You could use a MOV with unaligned SP relative addresses, but PUSH/POP can't operate otherwise. This becomes problematic a bit when you start pushing SIMD registers which are larger than 4 bytes and require larger alignments as well. You have to be careful in your Assembly code (the C compiler aligns values properly for you, but in Assembly it's up to you).
Cheers,
bzt
Re: Switching tasks and global protection fault
Posted: Thu Jul 09, 2020 8:00 am
by mrjbom
bzt wrote:mrjbom wrote:Here it is, thanks for the information, I did not expect.
Plus, all values on the stack must be aligned. You could use a MOV with unaligned SP relative addresses, but PUSH/POP can't operate otherwise. This becomes problematic a bit when you start pushing SIMD registers which are larger than 4 bytes and require larger alignments as well. You have to be careful in your Assembly code (the C compiler aligns values properly for you, but in Assembly it's up to you).
Cheers,
bzt
Yes, I understand that it is better to use push/pop than to manage the stack manually.