> Why is EBX special, while EAX is not? They are both general purpose registers. . .
Tim,
Back in the stone age of 16 bits, AX, BX, CX and DX were general purpose.
But BX could be used as an index register as well, like SI and DI. In 32 bit EAX, EBX, ECX and EDX are functionally the same, so this convention of preserving EBX is more or less out of habit.
Peter.
------------------
Announcement
Collapse
No announcement yet.
CPU Register EBX
Collapse
X
-
Guest repliedI do not want to use ESI or EDI, just EAX EBX ECX and EDX.
So when I have basic statements in the same sub as asm statements I will push and pop EBX, just to be safe.
Very interesting. Thanks guys!
Tim
------------------
Leave a comment:
-
Actually, the register preservation requirements for EBX/ESI/EDI only apply to assembler code which precedes BASIC statements within a sub/function. PowerBASIC assumes that it can use these 3 registers to store data from one statement to the next. If there are no more statements, it's of no consequence. PowerBASIC must preserve registers between sub/function calls, and does so automatically. Of course, ESP and EBP must always be preserved.
One note... never change a segment register. Win32 in unforgiving.
Bob Zale
PowerBASIC Inc.
------------------
Leave a comment:
-
The PB DLL Manual states that the value in the EBX register must be preserved, however the example code in the manual shows it being loaded with a value and not preserved as in: <snip>
A side note, default compiler setting of:
#REGISTER DEFAULT
can lead to some very interesting results when inline assembly code is used, but anyone sharp enough to do inline assembly would already know that. It might be a good idea to place a warning in the help file and/or manual.
"Further, float register variables may never be referenced by name from inline assembler code, as the compiler can not always track the register locations with absolute certainty."
And in more detail in the REGISTER VARIABLE section of Appendix C:
"You must use care with inline assembler floating point opcodes in functions that enable register variables. Float register variables may occupy up to four of the coprocessor registers, so you must limit your use of the x87 registers to the remaining four. Further, float register variables may never be referenced by name from inline assembler code, as the compiler can not always track the register locations with absolute certainty."
------------------
Lance
PowerBASIC Support
mailto:[email protected][email protected]</A>
Leave a comment:
-
Tim,
Its Windows convention to preserve EBX, ESI & EDI but you can freely use
EAX ECX & EDX without needing to preserve them.
From what I can tell coding inline asm in PB, it still handles the stack
preservation automatically where u must do the preservations manually in
MASM for example.
You normally leave the base pointer (EBP) and the stack pointer (ESP)
alone unless you are performing manual stack manipulation. FS & GS are
not normally used in win32 but apparently the OS uses them from time to
time.
Regards,
[email protected]
------------------
Leave a comment:
-
CPU Register EBX
The PB DLL Manual states that the value in the EBX register must be preserved, however the example code in the manual shows it being loaded with a value and not preserved as in:
SUB KerPlunk
ASM mov EAX, 5
! mov EBX, &HFF
! add EAX, EBX
END SUB
My questions are:
Why is EBX special, while EAX is not? They are both general purpose registers. . .
Is PB doing something special with EBX?
When the above sub is exited is EBX restored to the value it had before the sub was called?
A side note, default compiler setting of:
#REGISTER DEFAULT
can lead to some very interesting results when inline assembly code is used, but anyone sharp enough to do inline assembly would already know that. It might be a good idea to place a warning in the help file and/or manual.
Tim
[This message has been edited by Tim Wisseman (edited June 21, 2000).]Tags: None
Leave a comment: