Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #21769
| From | "Rod Pemberton" <do_not_have@notemailnotq.cpm> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... |
| Date | 2013-04-21 01:27 -0400 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <kkvt6o$sh8$1@speranza.aioe.org> (permalink) |
| References | <eb60b3e1-b203-4589-a1be-e80a161005ea@googlegroups.com> |
"AKE" <assadebrahim2000@gmail.com> wrote in message news:eb60b3e1-b203-4589-a1be-e80a161005ea@googlegroups.com... > This is a question around getting better technique (in Forth) > but also about working with the Forth assembler. > > I've been playing around with W32 Forth's built-in x86 assembler > that uses code ... next, end-code. > > Win32F uses ebx as the TOS register, keeps eax and ecx as > unrestricted registers. A little poking of the other registers > suggest that edx, edi, esi registers are restricted, i.e. they > must be restored to their original values before the code ... > end-code block returns to Forth > > The restricted registers are fine since most opcodes do not > clobber all four general purpose registers... except the cpuid > opcode (in 486 and above) does. > > [ The cpuid instruction with eax=0 puts a byte value in eax, and > *three* packed strings into ebx, ecx, edx respectively (4 bytes > in each string). Unpacking the three strings (in the correct > order) is supposed to give either "GenuineIntel" or > "AuthenticAMD" according to chipset. ] > > Usually, since there would be an un-clobbered and un-restricted > register free, I could just move other values about a bit like a > shell game. > > But with 'cpuid' clobbering all 4 GP registers, *and* with EDX, > ESI and EDI being *restricted* registers that must be restored > before returning to Forth, it seems one has to come up with some > other way. > > I've got working code using the forward portion of the memory > stack as a temporary register, and this works. But I am > interested in whether there are better / perhaps more > conventional ways to do this? > > Any insights / tips would be appreciated. > Let's look at the register usage: X yes - no ? unknown eax in-use - clobbered X ebx in-use X clobbered X ecx in-use - clobbered X edx in-use X clobbered X esi in-use X clobbered ? edi in-use X clobbered ? ebp in-use ? clobbered ? esp in-use ? clobbered ? It's likely esp is in-use, but ebp may or may not be. Typically, both are used for C stack call frames, however, if Win32Forth is coded in assembly, ebp may be free. The fact that you clobber and fail to restore ebp's value in your snipped sample code seems to confirm that it's free. Or, perhaps, that's a coding error? EDX, EDI, ESI are not used much by the x86 instructions. If they're "restricted", that means Win32Forth is using them for something like EBX being used for TOS. Since it's likely ESP and EBP are in-use, I'd have to question why Win32Forth is using so many registers, i.e., only two that are "free" or can be "clobbered". Do you know anything more about Win32Forth's it's machine model? In a situation like this, PUSHA and POPA comes to mind, especially for 16-bit and 32-bit code where they aren't obsoleted instructions. Also, you may want to use CLI and STI. The CLI and STI will prevent interrupts. Although uncommon, it is possible for interrupt routines to mess up registers. Of course, from your snipped sample code, it appears you found a solution already. You saved TOS simply by pushing ebx. So, I'm really not sure why you do something different for edx. Can't you just push and pop edx also? If stack pushes or PUSHA are unsuitable, then you can move or push to memory. Of course, you need some locations you can allocate and free. AIUI, for Forth, that's usually dictionary space or PAD. Rod Pemberton
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar
Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... AKE <assadebrahim2000@gmail.com> - 2013-04-19 18:21 -0700
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... "Rod Pemberton" <do_not_have@notemailnotq.cpm> - 2013-04-21 01:27 -0400
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... AKE <assadebrahim2000@gmail.com> - 2013-04-21 04:57 -0700
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... "Rod Pemberton" <do_not_have@notemailnotq.cpm> - 2013-04-21 11:39 -0400
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... Alex McDonald <blog@rivadpm.com> - 2013-04-21 09:53 -0700
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... AKE <assadebrahim2000@gmail.com> - 2013-04-21 14:47 -0700
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... Alex McDonald <blog@rivadpm.com> - 2013-04-22 02:17 -0700
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... Coos Haak <chforth@hccnet.nl> - 2013-04-21 17:34 +0200
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... Coos Haak <chforth@hccnet.nl> - 2013-04-21 17:42 +0200
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-04-21 12:37 -0500
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... Alex McDonald <blog@rivadpm.com> - 2013-04-21 10:53 -0700
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-04-22 03:24 -0500
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... Alex McDonald <blog@rivadpm.com> - 2013-04-22 02:49 -0700
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-04-22 10:06 +0000
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-04-22 07:35 -0500
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-04-22 13:12 +0000
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-04-22 10:01 -0500
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... Alex McDonald <blog@rivadpm.com> - 2013-04-22 08:33 -0700
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-04-22 11:34 -0500
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... Alex McDonald <blog@rivadpm.com> - 2013-04-23 03:27 -0700
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... "Rod Pemberton" <do_not_have@notemailnotq.cpm> - 2013-04-23 17:42 -0400
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-04-24 03:00 -0500
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... AKE <assadebrahim2000@gmail.com> - 2013-04-21 14:43 -0700
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... Alex McDonald <blog@rivadpm.com> - 2013-04-22 02:21 -0700
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... Alex McDonald <blog@rivadpm.com> - 2013-04-22 08:36 -0700
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... Alex McDonald <blog@rivadpm.com> - 2013-04-22 08:39 -0700
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... AKE <assadebrahim2000@gmail.com> - 2013-04-22 13:55 -0700
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... AKE <assadebrahim2000@gmail.com> - 2013-04-21 14:39 -0700
Re: Stack Interface between x86 Assembler & Forth -- technique when running out of unprotected registers... albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-04-21 21:00 +0000
csiph-web