Page 1 of 1

Trap

Posted: Thu Feb 17, 2011 1:45 pm
by Pascal
hello all,

i need to mix a C program with a asm game. From the asm code , i need to call functions of the C program. I was thinking using the Trap opcode.

As i don't need to return to the asm program (no RTE) , i'll do a SP+6 in my trap handler.

Do i need to do something more ? good or bad idea to use trap ?

thanks

Posted: Thu Feb 17, 2011 1:59 pm
by Chilly Willy
Bad idea - just go with the C ABI. The 68000 ABI is save all regs other than d0-d1/a0-a1, and all args go on the stack as longs, regardless of size. Trap, as with all exceptions on the 68000, is slow, taking far longer to dispatch than a simple jsr. If the function never returns, a simple jmp is even faster!

Posted: Thu Feb 17, 2011 2:14 pm
by Pascal
thanks ! silly of me , i'll go for a simple jump ;)

Re: Trap

Posted: Sun Feb 27, 2011 3:46 am
by plee
Pascal wrote:hello all,

i need to mix a C program with a asm game. From the asm code , i need to call functions of the C program. I was thinking using the Trap opcode.

As i don't need to return to the asm program (no RTE) , i'll do a SP+6 in my trap handler.

Do i need to do something more ? good or bad idea to use trap ?

thanks
Depending on the compiler you use, you can inter-mix the C code with assembly. GCC's register ops is a bit funky but it can be done.

Re: Trap

Posted: Sun Feb 27, 2011 4:08 am
by Chilly Willy
plee wrote:Depending on the compiler you use, you can inter-mix the C code with assembly. GCC's register ops is a bit funky but it can be done.
Just put "--register-prefix-optional" in the command line and forget the funk. :wink: