Contents of file "pfasm.4th"

0 ENUM AL CL DL BL AH CH DH BH /ENUM ( reg field for byte operations)

0 ENUM EAX ECX EDX EBX ESP EBP ESI EDI /ENUM ( reg field for word operations)

0 ENUM ES CS SS DS FS GS /ENUM ( segment registers)

0 ENUM B W IB IW MB MW /ENUM
 ( byte or word operation, in w field, I = immediate, M = memory)

0 ENUM X1 X2 X4 X8 /ENUM ( scale factor, ss)

2# 100000 ENUM [EAX] [ECX] [EDX] [EBX] [SIB] D32 [ESI] [EDI]
 [EAX+B] [ECX+B] [EDX+B] [EBX+B] [SIB+D8] [EBP+B] [ESI+B] [EDI+B]
 [EAX+W] [ECX+W] [EDX+W] [EBX+W] [SIB+D32] [EBP+W] [ESI+W] [EDI+W]
/ENUM

: MOD-R/M ( [array] -) ( compile src-dest information)
 ' -1 , ' []@ , ' 8 , ' < ' ( is source operand a register?)
 IF ' -2 , ' []@ , ' 8 , ' < , ( get dest operand, also register?)
  IF ' LIT , 2# 11000000 , ' -2 , ' []@ , ' | , ( build mod-reg-r/m byte)
  ELSE ' -2 , ' []@ , ' DUP , ' LIT , 2# 111 , ' & , ' SWAP , ( r/m)
  ' LIT , 2# 11000 , ' & , ' 3 , ' << , ( mod) ' | ,
  ENDIF
 ' -1 , ' []@ , ' 3 , ' << , ' | , ' , , ( compiled mod-reg-r/m)
 ' -2 , ' SIB , ( process Scale-Index-Base info if present)
 ' -2 , ' []@ , ' LIT , 2# 11111 , ' & , ' LIT , 2# 00101 , ' = , ( d32?)
  IF ' -3 , ' []@ , ' , , ( compile 32-bit word following mod-r/m byte)
  ENDIF
 ELSE ( source operand NOT a register)
 ' OVER , ' >R , ( save dest operand, which MUST be a register)
 ' -1 , []@ , ' DUP , ' LIT , 2# 111 , ' & , ' SWAP , ( r/m)
 ' LIT , 2# 11000 , ' & , ' 3 , ' << , ( mod) ' | ,
 ' R> , ' 3 , ' << , ' | , ' , , ( compiled mod-reg-r/m)
 ' -1 , SIB , ( process Scale-Index-Base info if present)
 ' -1 , ' []@ , ' LIT , 2# 11111 , ' & , ' LIT , 2# 00101 , ' = , ( d32?)
  IF ' -2 , ' []@ , ' , , ( compile 32-bit word following mod-r/m byte)
  ENDIF
 ENDIF ' ;S ,

: MOV, ( [array] n -) ( compile a MOV instruction)
 ( syntax for this, and for most instructions, is:
 [ dest src ] w|b opcode
 dest or src may be followed by scale, index, displacement)
 ' IW , ' > , ( memory-accumulator transfer?)
 IF 
 ELSE ' W , ' > , ( immediate operation?)
  IF ' 1 , ' & , ( get w bit) ' LIT , 2# 11000110 , ' | , ' , , ( opcode)
 ' SWAP , ' EDI , ' > ,
  ELSE
   IF
   ENDIF
  ENDIF
 ENDIF ' ;S ,

.S ( let us know if anything left on stack [meaning a bug!])
S" pfasm" SAVESYSTEM