Forth ASM 標準化 (Win32Forth 移植)

27 views
Skip to first unread message

燕南

unread,
Apr 20, 2019, 9:21:46 PM4/20/19
to 符式協會
\ Forth ASM  標準化 (Win32Forth 移植)

\ ForthVM & x86
\ sp equ <esp> \ Stack Pointer for Forth, the hardware stack
\ rp equ <ebp> \ Return Pointer, Forth's subroutine stack
\ ip equ <esi> \ Instruction Pointer for Forth
\ up equ <edx> \ USER pointer
\ tos equ <ebx> \ Top of stack is in EBX
\ <edi> \ CONSTANT ZERO

\ x86
\ T0 equ eax \ Temp Register for Fort
\ T1 equ ecx \ Temp Register for Fort
\ T2 equ edi \ Temp Register for Fort

\ 標準化 Forth 組合語言描述

\ imn 要處理的資料位元數宣告(不指定時 依照系統預定(cell))

CODE imn.AND ( imn1 imn2 -- imn ) \ Bitwise AND.

imn.POP imn.WP \ [DSP]->WP,DSP+imn/byte->DSP (LDR WP,[DSP],#-imn/byte)

imn.AND imn.TOS, imn.WP \ TOS&WP->TOS ( AND TOS,WP)

END-CODE


\ 原Win32Forth codes

CODE SKIP       ( adr len char -- adr' len' ) \ skip leading chars "char" in string
                pop     ecx
                jecxz   short @@2
                mov     eax, ebx                \ eax = character
                pop     edi
                repz    scasb
                je      short @@1
                add     ecx, # 1
                sub     edi, # 1
@@1:            push    edi
                xor     edi, edi                \ edi is zero
@@2:            mov     ebx, ecx
                next    c;
\ Forth VM
CODE SKIP       ( adr len char -- adr' len' ) \ skip leading chars "char" in string
                pop     T1
                jecxz   short @@ 2
                mov     T0, TOS                \ T0 = character
                pop     T2
                repz    scasb
                je      short @@ 1
                add     T1, # 1
                sub     T2, # 1
@@: 1           push    T2
                xor     T2, T2                \ T2 is zero
@@: 2           mov     TOS, T1
                next    c;
Reply all
Reply to author
Forward
0 new messages