Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!zephyr.ens.tek.com!tekig5!philj From: philj@tekig5.PEN.TEK.COM (Phil Jansen) Newsgroups: comp.sys.mac.programmer Subject: How do you use the THINK C assembler? Summary: My code doesn't work in asm (C is OK) Keywords: asm, THINK C, C, assembler Message-ID: <4841@tekig5.PEN.TEK.COM> Date: 25 Sep 89 18:45:08 GMT Reply-To: philj@tekig5.PEN.TEK.COM (Phil Jansen) Organization: Tektronix, Beaverton, OR Lines: 60 Hi there. I need to learn how to use the THINK C assembler. I have two pieces of code which I think should do the same thing, but they don't. One section is written in C, and the other uses asm{ }. Can somebody tell me what is different? It's not obvious from the assembler documentation (???) how to use it. How can I get the asm code to match what the C code does? Is it worth it (save ~30% in speed)? Has anyone seen a writeup of how to mix THINK C and assembler? Thanks Phil Jansen Here's my code ( C first [C works], then asm [asm code broken] ) --------------------------------------------------------------- #define BUFFSIZE 2048 /* MUST be a power of 2 */ #define BUFFMASK ( (BUFFSIZE*0x10000) - 1 ) #define NEXTLOC(x) ( (x) & BUFFMASK ) /* get next location (wrap) */ /* When in context, the declarations are like: register int val, *buf; register unsigned long int bp, inc; bp and inc represent fixed point numbers (0x00010000 is 1.0) */ /* C CODE HERE: */ #define ADDTONE(val, buf, bp, inc) val+= buf[(bp>>16)];\ bp = NEXTLOC(bp + inc); /* ASM CODE HERE */ #define asmADDTONE(val, buf, bp, inc) asm { /* BROKEN */ \ move.l bp, d0\ swap d0\ andi.l #0x0000ffff,d0 /* bp>>16 */\ add.l buf,d0\ move.l d0,a0 /* a0 = buf + (bp>>16) */\ move.b (a0),d0 /* d0 = buf[bp>>16] */\ add.w d0,val /* val += (a0) */\ \ move.l bp,d0\ add.l inc,d0 /* bp + inc */\ andi.l #BUFFMASK, d0 /* bp + inc & no overflow */\ move.l d0,bp /* save bp again */\ }; -------------------------------- Thanks for your help. -- If you repeat things often enough, they become true. Phil Jansen If you repeat things often enough, they become true. philj@tekig5.pen.tek.com If you repeat things often enough, they become true.