Re: new color

Mark Slicker <[email protected]>
Newsgroups gmane.comp.lang.forth.colorforth
Message-ID <[email protected]>
On Sat, 4 Jun 2005, Ray St. Marie wrote:

> And there you go. Proof of the ambiguity about how these things work.

There is no ambiguity here, but I see some confusion in your understanding 
of a subroutine call. Lets try an example with your 'array'.

: string pop ;
: array string 2/ 2/ ;
: test align array 1 , 2 , 3 ,

Suppose I enter this in a block, compile it. I've dissasebled the output 
below so perhaps this is more clear to you:

string:
  8149fbb:       lea    -4(%esi),%esi
  8149fbe:       mov    %eax,(%esi)
  8149fc0:       pop    %eax
  8149fc1:       ret
array:
  8149fc2:       call   0x8149fbb
  8149fc7:       sar    %eax
  8149fc9:       sar    %eax
  8149fcb:       ret
test:
  8149fcc:       nop
  8149fcd:       nop
  8149fce:       nop
  8149fcf:       call   0x8149fc2
  8149fd4:       .int 1
  8149fd8:       .int 2
  8149fdc:       .int 3

Above you see the effect of the macros (pop, 2/, align). I'd like to show 
a trace of this program, I'll use the following notation for the stacks:

( d2 d1 d0 -- r0 r1 r3 )

d0 and r0 denoting the top elements of the data and return stack 
respectively. Starting with 'test' (8149fcc):

test:
  8149fcc: nop                ( -- )
  8149fcd: nop                ( -- )
  8149fce: nop                ( -- )
  8149fcf: call   0x8149fc2   ( -- )
array:
  8149fc2: call   0x8149fbb   ( -- 0x8149fd4 )
string:
  8149fbb: lea  -4(%esi),%esi ( -- 0x8149fc7 0x8149fd4 )
  8149fbe: mov    %eax,(%esi) ( -- 0x8149fc7 0x8149fd4 )
  8149fc0: pop    %eax        ( 0x8149fc7 -- 0x8149fd4 )
  8149fc1: ret                ( 0x8149fc7 -- 0x8149fd4 )
  8149fd4: ...                ( 0x8149fc7 -- )

At this point in the trace, you've started to execute the data you had 
defined ( 1 , 2 , 3 , ), I hope it is clear why this defintion of array is 
incorrect. I also hope this gives you a better appreciation for call/ret.

Mark
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.