home .. forth .. colorforth mail list archive ..

Re: [colorforth] ‘?dup’ and ‘drop’


Oh, I get it now.  Block 24 (CF05) has a perfect example:
0: ?dup c031 2, ;
The ‘c031’ is ‘31 0c’ which is ‘xor eax, eax’
You want a zero put on the stack and the flags all reinitialised, so you use a ?dup just to put any old value on the stack—you don’t actually care that a dup really is dup-ing, so you’re happy to remove the ‘drop’ if there was a ‘drop’ in the word before—and then you xor it with itself to do the work.

You use ‘?dup’ when you want to create a new value on the stack and you don’t care what value because you are going to modify eax directly; you’re effectively just creating a space on top of the stack. If you cared that it really was a duplicate then you would use the un-optimized ‘dup’.

Jason

Jason Kemp said the following on 17/10/2008 17:55:
Sorry: ignore that one. Kristopher Johnson had asked it before and got an answer. http://www.strangegizmo.com/forth/ColorForth/msg00193.html

I've just spent quite a while trying to work it out but should have looked at the archive first.

Jason Kemp said the following on 17/10/2008 17:42:
Hi,

I understand that ?dup only compiles a dup if the previous instruction was not a drop. If it was a drop then the drop is removed and no dup is compiled either. Karig, http://www.karig.net/os/cf/c.htm#cdrop explains this.

But how can it be assumed that the TOS (that was to have been dropped) and NOS are identical so that we don't need a drop followed by a dup?

Thanks,
Jason





---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx
Main web page - http://www.colorforth.com





---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx
Main web page - http://www.colorforth.com





---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx
Main web page - http://www.colorforth.com