tom@phoenix.Princeton.EDU (Thomas C Hajdu) (02/10/88)
Sorry, but it's 4am and someone can save me a bunch of time by answering one simple question. Using Lattice, how do I compile and link in a .asm containing a routine I want to call from a main written in C?
daveh@cbmvax.UUCP (Dave Haynie) (02/12/88)
> > Sorry, but it's 4am and someone can save me a bunch of time by answering > one simple question. Using Lattice, how do I compile and link in > a .asm containing a routine I want to call from a main written in C? Some net turnaround time needed for this one. Anway... For Lattice at least, a C function is simply a subroutine. If you're passing arguments, these are pushed onto the stack in reverse order, so you reference them in order. If you want to return something, you place it in D0 prior to returning. In assembler, you routine would appear something like: XDEF _AsmFunc ; So my linker can see it. _AsmFunc: ; Don't forget "_" in Assembly MOVE.L 4(SP),A0 ; Put my C args into registers, arg1 MOVE.L 8(SP),D0 ; and arg2 (body of code) MOVE.L ReturnValue,D0 ; Result of the function. RTS And from C, extern LONG AsmFunc(LONG,LONG); main { LONG result, arg1, arg2; (some code) result = AsmFunc(arg1,arg2); (yet more code) } If you're dealing with arguments that aren't longwords, it may get trickier; you really have to know what you're compiler's going to do with a char or a short. I don't recall offhand. Also, doubles are coded differently, like as two longwords, returned in two registers as I recall. -- Dave Haynie "The B2000 Guy" Commodore-Amiga "The Crew That Never Rests" {ihnp4|uunet|rutgers}!cbmvax!daveh PLINK: D-DAVE H BIX: hazy "I can't relax, 'cause I'm a Boinger!"