Hi, I'm trying to write Borland Turbo C++ 3.0 compatible code to detect if the current CPU is a 486 or newer (to be able to distinguish against 386 or older).
In https://www.rcollins.org/ddj/Sep96/Sep96.html I find the relevant assembly code, but given that Turbo C++ 3.0 is such an old compiler, I can't get listings three and four to work. (PUSHFD, POPFD and EAX/EBX/ECX registers are not recognized)
I was thinking to encapsulate the problem by authoring a function get_EFLAGS(), which would just return the EFLAGS register in a 32-bit variable.
Based on these two links that I found:
- https://faydoc.tripod.com/cpu/pushfd.htm
- https://stackoverflow.com/questions...operand-size-in-the-x86-64-amd64-architecture
I got an impression that I might be able to execute PUSHFD, and access EAX/EBX/ECX registers via an operand-size prefix?
So my attempt was something like this:
But this doesn't quite work, and I'm not sure how to troubleshoot. It returns a 00000000h value always.
My thinking was that if I got this get_EFLAGS() to work, and then a similar set_EFLAGS() function, I could then use those to recreate the high level test logic for listings 1-4 in the linked DDJ article above. Any tips on how to implement such functions from Turbo C++ 3.0 real mode would be much appreciated. Thanks!
In https://www.rcollins.org/ddj/Sep96/Sep96.html I find the relevant assembly code, but given that Turbo C++ 3.0 is such an old compiler, I can't get listings three and four to work. (PUSHFD, POPFD and EAX/EBX/ECX registers are not recognized)
I was thinking to encapsulate the problem by authoring a function get_EFLAGS(), which would just return the EFLAGS register in a 32-bit variable.
Based on these two links that I found:
- https://faydoc.tripod.com/cpu/pushfd.htm
- https://stackoverflow.com/questions...operand-size-in-the-x86-64-amd64-architecture
I got an impression that I might be able to execute PUSHFD, and access EAX/EBX/ECX registers via an operand-size prefix?
So my attempt was something like this:
Code:
unsigned long get_EFLAGS()
{
asm {
db 0x67
pushf // Would a prefix 67h convert a pushf to a pushfd?
db 0x67
pop ax // Would a prefix 67h convert a pop ax to a pop eax?
mov dx, ax // Turbo C++ 3.0 return 32-bit quantities in DX:AX, so save low part in DX.
db 0x67 // Use prefix 67h to convert a 'shr ax, 16' to a 'shr eax, 16'?
db 0xC1
db 0xE8
db 0x10 // shr ax, 16
ret
}
}
But this doesn't quite work, and I'm not sure how to troubleshoot. It returns a 00000000h value always.
My thinking was that if I got this get_EFLAGS() to work, and then a similar set_EFLAGS() function, I could then use those to recreate the high level test logic for listings 1-4 in the linked DDJ article above. Any tips on how to implement such functions from Turbo C++ 3.0 real mode would be much appreciated. Thanks!