CompuServe Thread

#Pascal->asm->C

5 messages in this thread
#131785From: Burt JohnsonJul 14, 1993 2:28 AM
A friend is having a problem that I am unable to help with, so I promised to ask the combined genius here on CI$ and see if someone else knows. Since I do not know assembly (or at least haven't looked at it since 1980), I'm not really in a position to give them an answer. They have a MPW Pascal program that was converted to Think C. It now works, but there is one function that is much slower than it was before. They believe that this is likely the result of the way one function was converted. Since it was inline assembly code, I can't really help. The original code was: FUNCTION CallTLPM(tlCode: INTEGER; pmParams: PMParamPtr;theProc: ProcPtr): OSErr; INLINE $205f,$4e90; {——————————————————————-} { This procedure is a glue routine for jumping into an executable } { block of memory pointed to by the handle "tlProtocol" – a handle } { detached from a protocol handler resource. The routine passes } { to the protocol handler a "tlCode" (ie: open, close, write, read) } { and a parameter block "pmParams". The protocol handler will } { return its result as the function result of this glue routine. } { } { The INLINE code translates into: } { MOVEA.L (SP)+,A0 ; $205f } { JSR (A0) ; $4e90 } {——————————————————————-} This was converted to the following: //=================================================================== pascal OSErr CallTLPM ( short tlCode, PMParamPtr pmParams, ProcPtr theProc ) { OSErr err; // we put our assembly code here to call the TLPM code resource proc // since had problems reading the function arguments, we pass the // arguments on stack again. Inefficient but works ! asm{ move.l tlProc, a0 clr.w -(sp) // make space for result move.w tlCode, -(SP) move.l pmParams, -(sp) jsr (a0) // call code resource // we should pop off 6 bytes off stack here but // it appears that the TLPM code does it for us, so not necessary move.w (sp)+, err // pop up result } return( err ); } As I said, the code _does_ work, but appears to be a bottleneck somehow. Any suggestions are greatly appreciated! – Burt
#131837From: Peter MarxJul 14, 1993 5:35 PM
Burt: The rewritten code is slower than the original, perhaps by a factor or 4 or 5 (I'm sure someone will tell you exactly how much, but I'm not normally into cycle-counting). Here's a more literal translation, into Think C 5, of the original: pascal OSErr CallTLPM(short tlCode, PMParamPtr pmParams, ProcPtr theProc) = {0x205F, 0x4E90}; -Peter
#131871From: Burt JohnsonJul 14, 1993 11:10 PM
Thanks — The client just gave me his disks and asked me to look into it more. I'll give your code a try! – Burt
#131898From: Mario VanoJul 15, 1993 7:38 AM
What Peter said is what I also think should work! Mario
#131862From: DAVID THOMAS CRAIGJul 14, 1993 9:19 PM
Burt: Why can't the original asm code be assembled by itself and then linked into the C program? This seems the easiest to me. — DAVID T CRAIG