gnupic: Thread: using gpasm & gplink to create a static dispatch table


[<<] [<] Page 1 of 1 [>] [>>]
Subject: using gpasm & gplink to create a static dispatch table
From: "George M. Gallant" ####@####.####
Date: 24 Feb 2004 17:00:41 -0000
Message-Id: <403B7B83.6050702@comcast.net>

I would like to create a static dispatch table for a pic18f1320 device.

table:  dw    task_1
        dw    task_2

I have been able to use the HIGH and LOW operators as in:

table:  dw    high(task_1), low(task_1)   
        dw    high(task_2), low(task_2)

The following does not work:

table:  db    high(task_1), low(task_1)   
        db    high(task_2), low(task_2)

Regads,
    George

Subject: Re: using gpasm & gplink to create a static dispatch table
From: Scott Dattalo ####@####.####
Date: 24 Feb 2004 17:27:41 -0000
Message-Id: <Pine.LNX.4.44.0402240835060.19163-100000@ruckus.brouhaha.com>

On Tue, 24 Feb 2004, George M. Gallant wrote:

> I would like to create a static dispatch table for a pic18f1320 device.

<snip>

George,

A better approach may be:

table:
        bra   task_1
        bra   task_2
        ...

If you wish to span the whole address space, then the single-word branch 
instruction will have to be changed to a 2-word goto instruction.

The way to use it would be something like this:

        rcall   TaskSwitch

   ...


TaskSwitch:
        movlw   HIGH(DispatchTable) ; high byte of table address
        movwf   PCLATH            ;will become high byte of PC
                                  ;
        rlncf   CurrentTask,W     ;Current Task ID is an index
                                  ;into the table. (Note, another
                                  ;rotate is needed if the bra's
                                  ;are changed into goto's).
        andlw   TABLE_MASK        ;table size is 2^n, so this
                                  ;will ensure we don't overflow
        addlw   LOW(DispatchTable);W=low byte of address
        skpnc                     ;If we crossed a byte boundary
         incf   PCLATH,F          ;then increment high byte
        movwf   PCL               ;Jump into the table

DispatchTable:
        bra     Task_1
        bra     Task_2
        return                  ;spare tasks
        return
        return
        return
        return
        return
DispatchTable_End:

; build the table mask from the addresses of the table
; (we could print a message to alert the user if table
;  is not 2^n)

TABLE_MASK   EQU   (DispatchTable_End - DispatchTable) << 1

-- Note, I've done this exact kind of thing several times in an 18F 
device. However, this particular snippet has not been tested.

Scott

Subject: Re: using gpasm & gplink to create a static dispatch table
From: "George M. Gallant" ####@####.####
Date: 24 Feb 2004 18:15:21 -0000
Message-Id: <403B8C2F.8050702@comcast.net>

Scott,

I am looking at porting the PICOS18 by Xavier Montange to Linux using
gputils. He uses the C18 compiler to generate an array of structures 
that contain
the address of the task. The SDCC compiler does not handle the source 
"C" code.
Is there a way to replicate the C &function with the "DW" directives? 
Perhaps, I
could download the C18 evaluation compiler and look at the assembler code
produced.

Regards,
George

Scott Dattalo wrote:

>On Tue, 24 Feb 2004, George M. Gallant wrote:
>
>  
>
>>I would like to create a static dispatch table for a pic18f1320 device.
>>    
>>
>
><snip>
>
>George,
>
>A better approach may be:
>
>table:
>        bra   task_1
>        bra   task_2
>        ...
>
>If you wish to span the whole address space, then the single-word branch 
>instruction will have to be changed to a 2-word goto instruction.
>
>The way to use it would be something like this:
>
>        rcall   TaskSwitch
>
>   ...
>
>
>TaskSwitch:
>        movlw   HIGH(DispatchTable) ; high byte of table address
>        movwf   PCLATH            ;will become high byte of PC
>                                  ;
>        rlncf   CurrentTask,W     ;Current Task ID is an index
>                                  ;into the table. (Note, another
>                                  ;rotate is needed if the bra's
>                                  ;are changed into goto's).
>        andlw   TABLE_MASK        ;table size is 2^n, so this
>                                  ;will ensure we don't overflow
>        addlw   LOW(DispatchTable);W=low byte of address
>        skpnc                     ;If we crossed a byte boundary
>         incf   PCLATH,F          ;then increment high byte
>        movwf   PCL               ;Jump into the table
>
>DispatchTable:
>        bra     Task_1
>        bra     Task_2
>        return                  ;spare tasks
>        return
>        return
>        return
>        return
>        return
>DispatchTable_End:
>
>; build the table mask from the addresses of the table
>; (we could print a message to alert the user if table
>;  is not 2^n)
>
>TABLE_MASK   EQU   (DispatchTable_End - DispatchTable) << 1
>
>-- Note, I've done this exact kind of thing several times in an 18F 
>device. However, this particular snippet has not been tested.
>
>Scott
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: ####@####.####
>For additional commands, e-mail: ####@####.####
>
>
>  
>


[<<] [<] Page 1 of 1 [>] [>>]


Powered by ezmlm-browse 0.20.