poke function ....

Dony dony@willowglen.com.sg
Mon Sep 21 18:11:00 GMT 1998


Hii ...
First of all, I wanna say "thank's" for all who have replied me.
I still have another question regarding argument passing in M68K.
What will happen in stack whenever the function pokeb 
is being called?? Is the same like Intel where the frame pointer
being pushed to the stack?? If it is, that means during
that time my stack will be like this :

             MSB                     LSB
            +0      +1      +2      +3
         +-------+-------+-------+-------+
  SP+16  |   data (extended to 32 bits)  |
         +-------+-------+-------+-------+
  SP+12  |            offset             |
         +-------+-------+-------+-------+
  SP+8   |          base_addr            |
         +-------+-------+-------+-------+
  SP+4   |       return PC addr          |
         +-------+-------+-------+-------+
  SP->   |         old A6 value          |
         +-------+-------+-------+-------+


Art Berggreen wrote:
> 
> >> /* pokeb(char *base_addr, int offset, char data) */
> >>         .global pokeb
> >> pokeb:
> >>         move.l  4(%sp),%a0      /* get base_addr */
> >>         add.l   8(%sp),%a0      /* add offset */
> >>         move.b  15(%sp),(%a0)   /* move data byte */
> >>         rts
> >>
> >> Art
> >
> >Hii,
> >Can anybody tell me how the argument will be passed into stack for
> >function pokeb(char *base_addr, int offset, char data)??
> >Is it like below??
> >
> >data highest byte (3rd arg, 4th byte)          ->      sp+15
> >data high byte (3rd arg, 3rd byte)             ->      sp+14
> >data low byte (3rd arg, 2nd byte)              ->      sp+13
> >data lowest byte (3rd arg, 1st byte)           ->      sp+12
> >offset highest byte (2nd arg, 4th byte)                ->      sp+11
> >offset high byte (2nd arg, 3rd byte)           ->      sp+10
> >offset low byte (2nd arg, 2nd byte)            ->      sp+9
> >offset lowest byte (2nd arg, 1 byte)           ->      sp+8
> >base_addr highest byte (1st arg, 4th byte)     ->      sp+7
> >base_addr high byte (1st arg, 3rd byte)                ->      sp+6
> >base_addr low byte (1st arg, 2nd byte)         ->      sp+5
> >base_addr lowest byte (1st arg, 1st byte)      ->      sp+4
> >sp highest byte                                        ->      sp+3
> >sp high byte                                   ->      sp+2
> >sp low byte                                    ->      sp+1
> >sp lowest byte                                 ->      sp+0
> 
> Since the m68k is a big-endian machine, you've got the order of bytes
> within a 32 bit word wrong.  And the first thing on the stack will
> be the return PC address, not the old stack pointer.
> 
> In the m68k calling interface, arguments are pushed onto the stack
> from right to left (so that the first argument will be the smallest
> offset).  Arguments that are 8 or 16 bits are extended to 32 bits
> before being pushed onto the stack (to maintain a 32 bit stack
> alignment).  Finally the subroutine is called with a jsr instruction
> which pushes the PC address following the jsr onto the stack.  The
> called function is expected to preserve the contents of D2-D7 and
> A2-A6.  Registers D0, D1, A0, and A1 may be modified.  Function
> return values will be returned in D0 (and D1 if between 32 and 64
> bits).  So, on your call the stack should look like:
> 
>            MSB                     LSB
>            +0      +1      +2      +3
>         +-------+-------+-------+-------+
>  SP+12  |   data (extended to 32 bits)  |
>         +-------+-------+-------+-------+
>  SP+8   |            offset             |
>         +-------+-------+-------+-------+
>  SP+4   |          base_addr            |
>         +-------+-------+-------+-------+
>  SP->   |       return PC addr          |
>         +-------+-------+-------+-------+
> 
> Of course as everyone has pointed out, you ought to just use a pointer
> under C.
> 
> inline void pokeb(char *base_addr, int offset, char data)
> {
>         *(base_addr+offset) = data;
> }
> 
> Art

-- 
Dony Oswan
Hardware Engineer
Willowglen Services Pte Ltd
151 Lorong Chuan, #05-07
New Tech Park, Singapore 556741
Tel   : 65 - 2800437
Fax   : 65 - 2804657
Email : dony@willowglen.com.sg



More information about the crossgcc mailing list