[comp.sys.handhelds] M/L Question: Stack

akcs.scotty@hpcvbbs.UUCP (SCOTTY THOMPSON) (06/02/91)

I wanted to write a program that would convert a string object to a
global name object on the stack in m/l.  I was successful, but upon
garbage collection or trying to "recall" the "non-existant" object, the
system would replace the global name with "External" and I would end-up
with a 5 nibble address instead.

Unthreading/Disassembling the HEX and ASC routines, I noticed that they
all create a new string and "copy" the data back to those strings.  I was
trying to alleviate this by moving D1 forward 3 nibbles and adjusting
the prolog and size to correspond to that of a global name.

For example, if I had the string "ABC" on the stack, the following
example is what I did:

   A=DAT1 A ;Got the address off the stack
   D0=A
   D0=D0+5  ;Point past prolog to size
   C=DAT0 A ;Get size to C
   C-C-5    ;Sub. 5 nibbles
   CSRB   A ;Convert to Bytes
   D0=D0+3  ;Point past 3 nibbles to last 2 nibbles (for byte size)
   DAT0=C B ;replace # of bytes in string
   D0=D0-5
   LCHEX 02E48 ;global name prolog
   DAT0=C  A ; replace
   CD0EX
   D0=C
   (oops, make that D1=C, above)
   ...restore/return...

This routine simply packs the 3 extra nibbles in the size field of the
string, puts in the number of bytes and the prolog for a global name. 
However, there are 3 nibbles freed-up.  How does one kill them?

I re-wrote the routine to allocate nibbles in a new string and copy all
of the information to the data area in the new string, adjusted the D1
pointer to the data area in the new string, but the process is the same,
right?  I mean, the old string prolog is effectively "removed" by
adjusting D1, so why don't I get the same results doing it the first way?
I would really like to know.  Do I need to fuss with D or B?

Needless to say, the routines works just fine since I copy the data to
the new string and adjust D1 10 nibbles.  Strange...