[ColorForth] How to escape from loops
- Subject: [ColorForth] How to escape from loops
- From: CrowKiller <adresse_bidon@xxxxxxxxxxxxxxx>
- Date: Thu, 18 Jul 2002 02:22:09 -0400
Part of my forth implementation design,
this is how I handle looping in 32bit-x86 Forth,
NASM-Style:
;=============================================================
%MACRO Begin 0 ;5 bytes long
call $+5
%ENDMACRO
%MACRO Break 0 ; Break an infinite loop
add [ESP], 2 ;Skips Again
ret
%ENDMACRO
%MACRO Again 0 ;2 bytes long
push DWORD [ESP]
ret
%ENDMACRO
%MACRO End 0 ;5 bytes long
dec ECX ;Maximum count: 2^31
js SHORT $+4
Again
%ENDMACRO ;* Ends a For like structure ("mov ECX, imm" followed by "Begin")
;=============================================================
The only bad thing is the order operand not very forthish, in NASM we write:
mov ECX, 24h
Begin
WordcreatedByUser
ThoseareWrittenWithCaps
Again
To create a simple For structure.
An editor should have his own "forth",
so we could write
Begin - Standard loop start
or
"Begin 34" - Counted loop start (For)
I'll start one as soon as my primitives are clearly defined.
help me if you see any flaw, this will be free software
after all ;o)
Have a nice day
------------------------
To Unsubscribe from this list, send mail to Mdaemon@xxxxxxxxxxxxxxxxxx with:
unsubscribe ColorForth
as the first and only line within the message body
Problems - List-Admin@xxxxxxxxxxxxxxxxxx
Main ColorForth site - http://www.colorforth.com
Wiki page http://kristopherjohnson.net/wiki/ColorForth
ColorForth index http://www.users.qwest.net/~loveall/c4index.htm