Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!willett!ForthNet From: ForthNet@willett.UUCP (ForthNet articles from GEnie) Newsgroups: comp.lang.forth Subject: PYGMY Forth Message-ID: <460.UUL1.3#5129@willett.UUCP> Date: 13 Feb 90 23:36:34 GMT Organization: Latest link in the ForthNet chain. (Pgh, PA) Lines: 58 Category 1, Topic 45 Message 24 Tue Feb 13, 1990 F.SERGEANT [Frank] at 01:01 CST To Doug Philips re changing registers in Pygmy CODE words Here's a quote from screen 2102 (in ASM.DOC): If your routine disturbs CS, DS, BP, SP, SI, or BX it must restore it. The direction flag must be left clear. Yes, it is perfectly proper to change the other registers without restoring them or to change the above registers if you restore them. Forget about CS, you aren't going to change it. Suppose you want to do a DOS Int $21 call that needs other registers set up than the built in words DOS or DOS2 provide. For example, you might want to use function $40 "Write to a File or Device" and you want to use a buffer outside of Pygmy's segment. CODE WRITE-BUF ( buf-offset buf-seg handle count - #bytes-written f) BX CX MOV, ( move count from TOS to CX) BX POP, ( put handle in BX) AX POP, ( put seg temporarily in AX) DX POP, ( put offset in DX) ( now we have all our parameters off the data stack) ( and it is free for us to use to save DS ) DS PUSH, ( save DS) AX DS MOV, ( reload it with segment) $4000 #, AX MOV, ( tell DOS we want function $40 ) $21 INT, ( do it ) ( now AX holds bytes actually written if carry is not set) ( or an error code if carry is set ) DS POP, ( restore DS ) AX PUSH, ( push either count or error code ) BX BX SBB, ( convert the carry flag to a forth flag of -1 or 0 ) ( this might have been clearer if written this way ) ( CS, IF, -1 #, BX MOV, ELSE, BX BX SUB, THEN, ) NXT, END-CODE Note that we don't bother preserving AX or CX or DX. BX is altered, but carefully, as we must see that it holds Top of Stack. DS was saved before the $21 INT, and restored afterwards. I haven't tested the above routine put it should get the general idea across. You could change the code to accomodate a different order for the operands. You know what must go in the various registers by consulting a reference book on DOS calls. I'm looking at a Microsoft programmer's reference manual for MS-DOS 2.0. And, what's the worst that can happen if you screw it up? Probably just wiping out your hard disk. Current backups might add to your peace of mind, but Forth programmers live dangerously and crash the system all the time. -- Frank ----- This message came from GEnie via willett through a semi-automated process. Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'