Re: A92: Periodic events


[Prev][Next][Index][Thread]

Re: A92: Periodic events




>
> Thank you, your example has clarified a lot of things.  However, I still have
> a couple of questions:
>

*SIGH*  Quite an omission I made all right..  Fixed code is starred (**) below.


<<< TOP OF CODE SNIPPED >>>

> > my_Task:
> >         ; This task will be run aproximately 20 times per second.
> >         ; You MUST save and restore all registers used in this interrupt!
> >
> >         movem.l d0-d7/a0-a6,-(a7)       ; Save all registers
> >                                         ; This interrupt does not use any
> >                                         ;   registers so this isn't needed,
> >                                         ;   but shown for completeness..
> >         not.b   (tios::main_LCD)        ; Blink some pixels in upper left
of
> > LCD
> >
> >         movem.l (a7)+,d0-d7/a0-a6       ; Restore registers (must match
> >                                         ;   previous register list!!!)

; NEW CODE: attached to end in place of 'RTE'

***  old_Int:
***	jmp 0x10000001			; This code is modified to point to
					;   the correct place


   Self modifying code is where you actually change the executing code instead
of just some variable which is then tested.  In this case, the code for JMP
0x10000001 is changed to JMP ($theOldInterrupt).  This saves at least 2 bytes,
probably more like 6 bytes actually.  I use the value 0x10000001 to force the
assembler to use a full 4 byte jump instead of a 2 byte jump (not sure if it
matters, but I like to be sure).
   The code modifies itself with the instruction 'move.l  ($Auto_Int5),2(a1)'
 This moves the longword at the Auto_Int5 vector to old_Int+2.  Why old_Int+2
and not just old_Int?  Because the first two bytes after the label old_Int are
the JMP instruction, the next four are the actual address to jump to.

An alternate method (used by most programmers) is:

main:
	...				; Instruction Size:
	lea old_Int(pc),a1		; 4 Bytes
	move.l ($Auto_Int5),(a1)	; 4
	...

my_Task:
	...
	lea old_Int(pc),a1		; 4
	jmp (a1)			; 2
	...

old_Int:
	dc.l 0x00000000			; 4
					; Total: 18 Bytes

  Why don't I do it this way?  We can count up the sizes of instructions; my
version uses only 12 bytes and is two instructions shorter.  There are other
methods such as 'move.l ($Auto_Int5),old_Int' but this compiles out to 6 bytes
by itself plus two more bytes of relocation information for the Fargo loader.
 Anyway, if you're interested in highly optimized code, that's a totaly
separate thread...

Lemme know if there are any other errors..

--Bryan
bcturner@eos.ncsu.edu


References: