[comp.sys.apple2] Arrrgh, why's this not working?

jake@labpca.mscs.mu.edu (Jake Buchholz) (06/13/91)

Righto, time to ask for more help...  The following code is supposed to take
two parameters off the stack, and then print t1 as a character t2 times.
-----
         mcopy 2/ainclude/m16.msc
         mcopy 2/ainclude/m16.i.o

rpt      start

t1       dc    i'0'
t2       dc    i'0'

         pl2   t1
         pl2   t2
         lda   #0
l1       cmp   t1
         beq   l3
l2       cout  t2
         dec   t1
         bne   l2
l3       rtl
         end
-----
This is what the assembler says when I try to compile this bugger...
-----

ORCA/M ASM65816 1.1.1                    9 Jun 1991  14:18:47

Pass 1: rpt 
Pass 2: rpt 
     0014             +         PH2   &CHAR
Error RPT.ASM         22    Unidentified Operation 

1 errors found
16 was highest error level
 
26 source lines
5 macros expanded
33 lines generated
-----
I don't use assembly very often, I could have missed something very obvious.
If you have an idea what went wrong, please respond.

If it has any bearing on this at all, I'm attempting to link this code into
an Orca/C program with #append "file.asm", with it declared as

extern void rpt(char c, int n);

Another question would be whether or not I'm passing the parameters correctly.
(Either this kind of thing doesn't show up in the manuals (Orca/C or Orca/M)
or my retina's been burnt out by this screen worse than I've expected...)


jake@sc.mscs.mu.edu
--
[][][][][][][][][][][][][][][][]---------------------------------------------+
[]     Jacob S. Buchholz      [] With great intellect, comes an even greater |
[]  jake@labpca.mscs.mu.edu   [] possibility of a showing of a lack thereof. |
[][][][][][][][][][][][][][][][]---------------------------------------------+

meekins@anaconda.cis.ohio-state.edu (Tim Meekins) (06/13/91)

In article <1181@spool.mu.edu> jake@labpca.mscs.mu.edu (Jake Buchholz) writes:
>


>
>ORCA/M ASM65816 1.1.1                    9 Jun 1991  14:18:47
>
>Pass 1: rpt 
>Pass 2: rpt 
>     0014             +         PH2   &CHAR
>Error RPT.ASM         22    Unidentified Operation 
>


The macro ph2 wasn't found, after it got expanded by COUT macro. This
is strange since PL2. Just to make sure you get all the macros, do the 
following:

   1. change both of your 'mcopy's to a single 'mcopy rpt.mac'
   2. From the orca shell type 'macgen rpt.asm rpt.mac 2/ainclude/m16='

This will create a file for you called rpt.mac which contains only the
macros used in your program. If it says it couldn't find a macro, and gives
you a prompt. Type '2/ainclude/m16=' again. (there are better ways...)

>Another question would be whether or not I'm passing the parameters correctly.
>(Either this kind of thing doesn't show up in the manuals (Orca/C or Orca/M)
>or my retina's been burnt out by this screen worse than I've expected...)
>

OK. This is the part you really screwed up. It's a good thing it didn't
compile or you would have crashed after running it :(

{fingers crossed, this isn't that easy to explain}

placing 'dc' at the beginning of your routine is actually placing data at
the beginning of the function. When the function is called, these data
will be interpreted as actually assembly instructions, BRK in this case.

Data items need to placed at the end.

But again, you probably knew that. What you didn't know is how to set up
a stack frame. This is very tricky if you're not familiar with assembly.

In fact, I'm not going to discuss stack frames right now, but I'll follow
up if you or anyone else wants to know how to so...

To keep things simple, you need a macro which will build the stack frame
for. I don't have Orca/C, but Orca/Pascal included an assembly macro
called 'subroutine' which will build these stack frames. Try and find
it in your Orca/C manual, not the Orca/M manual. It should be there.

Since your code doesn't have local variable storage I'll skip that.

Put the following as the first line in your code (after removing
your dc's)

	subroutine(t1:2,t2:2)

or something like that (I just killed your source and forgot the
variable names and length). This will automatically set up a stack frame
and actually generate EQU's for t1 and t2 to correspond to stack
space.

Since you have no return values just use the following at the end, in
place of RTL:

	return

If you can't find these macros with Orca/C, let me know. I created
a disk of public domain (shareware actually) macros for Orca/M. I can
mail you the subroutine and return macros and documentation.

Note: If you get into assembly in the future, your code is missing something
else needed by the 65816:

	phb
	phk
	plb

	your code here

	plb

(don't worry, subroutine *should* take of this, or at least *mine* does) 

This is important if your assembly function resides in another bank than
it was called from. Your function will still be expecting the data bank to
be in the caller's bank, not the function. phk/plb sets the data bank
to the function's. phb/plb saves and restirs the callers data bank.

Of couse, this is all trivial since your function doesn't acces any data
in the bank anyways.

If you need more help, just ask!
--
++------------S-U-P-P-O-R-T---S-H-A-R-E-W-A-R-E---O-R---D-I-E-!-----------++
|| Tim Meekins                   ||  Snail Mail:           ||   Apple II  || 
||   meekins@cis.ohio-state.edu  ||    8372 Morris Rd.     ||   Forever!  ||
\\___timm@pro-tcc.cts.com________/\____Hilliard, OH 43026__/\_____________//

benson@vuse.vanderbilt.edu (Paul Benson) (06/13/91)

In article <1181@spool.mu.edu> jake@labpca.mscs.mu.edu (Jake Buchholz) writes:
>
>Righto, time to ask for more help...  The following code is supposed to take
>two parameters off the stack, and then print t1 as a character t2 times.
>-----
>         mcopy 2/ainclude/m16.msc
>         mcopy 2/ainclude/m16.i.o
>
>rpt      start
>
>t1       dc    i'0'
>t2       dc    i'0'
>
>         pl2   t1
>         pl2   t2
>         ...
>         rtl
  Among other good points made by Tim Meekings, you need to get the
  return address off of the stack, and save it somewhere.  Easier
  to use stack addressing as the Orca/C manual demonstrates, though.
  ie tsc phd tcd and ending with pld.  And yes, I know that it is
  truly direct page addressing and not 'stack,s' addressing.
  Paul Benson
  benson@vuse.vanderbilt.edu
  GEnie: p.benson1

jake@labpca.mscs.mu.edu (Jake Buchholz) (06/13/91)

Thanks for the quick response, Tim...  I did a quick scan thru my ORCA/C
manual again...  Still no macro for the "subroutine" thingy you mentioned,
though.

I've done some assembly before, but it's always been little things in the
same bank, and usually just in 6502...  Should have figured things'd be a
bit different for the 65816...

I've taken a compiler construction course, so I do know what a stack frame
is and how it's used, its the implementation for ORCA/* that I'd need to
cover.  (then again, a refresher overall wouldn't be a bad idea either if
you have the time).

Thanks again,

jake@sc.mscs.mu.edu
(ignore the .sig gotta fix it.)
--
[][][][][][][][][][][][][][][][]---------------------------------------------+
[]     Jacob S. Buchholz      [] With great intellect, comes an even greater |
[]  jake@labpca.mscs.mu.edu   [] possibility of a showing of a lack thereof. |
[][][][][][][][][][][][][][][][]---------------------------------------------+

benson@vuse.vanderbilt.edu (Paul Benson) (06/13/91)

  Sorry if this already made it, but the server on my end reported an error.

>Righto, time to ask for more help...  The following code is supposed to take
>two parameters off the stack, and then print t1 as a character t2 times.
>-----
>         mcopy 2/ainclude/m16.msc
>         mcopy 2/ainclude/m16.i.o
>
>rpt      start
>
>t1       dc    i'0'
>t2       dc    i'0'
>
>         pl2   t1
>         pl2   t2
>         ...
>         rtl
  Among other good points made by Tim, you need to get the
  return address off of the stack, and save it somewhere.
  Easier to use stack addressing as the Orca/C manual demonstrates, though.
  ie tsc phd tcd and ending with pld.  And yes, I know that it is
  truly direct page addressing and not 'stack,s' addressing.
  Also the macro stuff in Orca/C is on page 69 in the new & old manuals. 
    Paul Benson
    benson@vuse.vanderbilt.edu
    GEnie: p.benson1