Machine Forth primitives for x86 
Author Message
 Machine Forth primitives for x86

Recently, I have been dabbling in Intel assembly language.  I came up
with the following primitives for Machine Forth.  I have not tested
these, so they are probably horribly broken and/or don't work.  Also, I
used a free assembler called NASM. ( http://www.*-*-*.com/ )
I am an assembly newbie, so if you know a better and/or working way to
do these, please tell me.

Machine Forth primitives for x86
All cycle times are for 486
EAX=Top of stack
EBX=Address register
EBP=Data stack pointer
ESI=Temp register

00 else: 3 cycles
jmp <label> (3)

01 T=0: 2 cycles if no jump, 4 if jump
cmp eax,0x80000000 (1)
jb <label> (1 if no jump, 3 if jump)

02 call: 3 cycles
call <label> (3)

03 C=0: 2 cycles if no jump, 4 if jump
cmp eax,0x80000000 (1)
jae <label> (1 if no jump, 3 if jump)

06 ret: 1 cycle
retn (1)


pop esi (4)
mov [ebp],eax (1)
sub ebp,4 (1)
mov eax,[esi] (1)
add esi,4 (1)
push esi (1)


mov [ebp],eax (1)
sub ebp,4 (1)
mov eax,[ebx] (1)
add ebx,4 (1)

0A #: 3 cycles
mov [ebp],eax (1)
sub ebp,4 (1)
mov eax,<immed> (1)


mov [ebp],eax (1)
sub ebp,4 (1)
mov eax,[ebx] (1)

0C !r+: 9 cycles
pop esi (4)
mov [esi],eax (1)
mov eax,[ebp] (1)
add ebp,4 (1)
add esi,4 (1)
push esi (1)

0D !a+: 4 cycles
mov [ebx],eax (1)
mov eax,[ebp] (1)
add ebp,4 (1)
add ebx,4 (1)

0F !a: 3 cycles
mov [ebx],eax (1)
mov eax,[ebp] (1)
add ebp,4 (1)

10 com: 1 cycle
neg eax (1)

11 2*: 3 cycles
sal eax (3)

12 2/: 3 cycles
sar eax (3)

13 +*: 4 cycles
test eax,1 (1)
jz <end> (1 if no jump, 3 if jump)
add ebp,4 (1)
add eax,[ebp] (1)

14 -or: 3 cycles
add ebp,4 (1)
xor eax,[ebp] (2)

15 and: 2 cycles
add ebp,4 (1)
and eax,[ebp] (1)

17 +: 3 cycles
add ebp,4 (1)
add eax,[ebp] (2)

18 pop: 6 cycles
mov [ebp],eax (1)
sub ebp,4 (1)
pop eax (4)


mov [ebp],eax (1)
sub ebp,4 (1)
mov eax,ebx (1)

1A dup: 2 cycles
mov [ebp],eax (1)
sub ebp,4 (1)

1B over: 3 cycles
mov [ebp],eax (1)
sub ebp,4 (1)
mov eax,[ebp+8] (1)

1C push: 3 cycles
push eax (1)
add ebp,4 (1)
mov eax,[ebp] (1)

1D a!: 3 cycles
mov ebx,eax (1)
add ebp,4 (1)
mov eax,[ebp] (1)

1F drop: 2 cycles
add ebp,4 (1)
mov eax,[ebp] (1)

Sent via Deja.com http://www.*-*-*.com/
Share what you know. Learn what you don't.



Thu, 15 Nov 2001 03:00:00 GMT  
 Machine Forth primitives for x86
I think it would be easier to make EBX the TOS. Then we have


CODE  !   [EBX] POP  EBX  POP  etc

Then you can use EAX for your NEXT, mechanism. Depending on your
threading mechanism. I believe someone has noted on this thread
that on pentium-class machines one can schedule the instructions
so that indirect threading is faster than direct or subroutine
threading. (That is, what would be extra overhead on 286-486 cpu's
executes in 0 time because of the superscalar architechture.)

--
Julian V. Noble

"Elegance is for tailors!"    -- Ludwig Boltzmann



Mon, 19 Nov 2001 03:00:00 GMT  
 Machine Forth primitives for x86


Quote:
> I think it would be easier to make EBX the TOS. Then we have


> CODE  !   [EBX] POP  EBX  POP  etc

> Then you can use EAX for your NEXT, mechanism. Depending on your
> threading mechanism. I believe someone has noted on this thread
> that on pentium-class machines one can schedule the instructions
> so that indirect threading is faster than direct or subroutine
> threading. (That is, what would be extra overhead on 286-486 cpu's
> executes in 0 time because of the superscalar architechture.)

In Machine Forth, you have the A register, which contains addresses for
fetches and stores.  I put the A register in EBX.  TOS is in EAX,
because you don't need to access memory from a pointer in TOS.  Also,
Machine Forth generally uses subroutine-threaded code with inlining of
primitives, so you're not going to be using LODSD.  There's a better
description somewhere on Jeff Fox's page.

I know that on Pentiums ITC is faster than DTC, but I seriously doubt
that it is faster than STC w/primitive inlining.  (If ITC really is
faster, I need to get a Mac. :)

I am also pretty sure that the primitives T=0 and C=0 are broken.  If
anyone knows how to make them work, please tell me.

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.



Mon, 19 Nov 2001 03:00:00 GMT  
 Machine Forth primitives for x86

Quote:
James Hague  writes:

> >I think it would be easier to make EBX the TOS. Then we have


> >CODE  !   [EBX] POP  EBX  POP  etc

> >Then you can use EAX for your NEXT, mechanism.

> In 32-bit x86 code, all registers can be used for memory addressing.
> There's no need to go through BX, SI, DI, and BP as in the olden days.

> James

Ah. Thank you Intel!

--
Julian V. Noble

"Elegance is for tailors!"    -- Ludwig Boltzmann



Fri, 23 Nov 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Minimum primitives for a ANS forth?

2. Forth primitives for 32-bit RISC

3. HW support for primitives (was Re:Graphics Primitives)

4. looking 4 all x86 machine code?

5. How to reset an x86 machine?

6. x86 machine code about

7. Machine opcodes for x86 - where?

8. Fortran with precision REAL*16 for x86 machines under MS DOS

9. F4: x86 Linux fig-Forth

10. stand-alone x86/pc forth?

11. lib4th 0.5.00 - Forth for x86-pc-linux

12. lib4th 0.2.05 - Forth for x86-pc-linux

 

 
Powered by phpBB® Forum Software