CompuServe Thread

#asm code

4 messages in this thread
#7220From: Peter H. TeesonJul 20, 1993 2:16 PM
The following function in THINK C compiles fine: short Foo(register short x) { asm {rol.w #1, x} return (x ^ 0x1021); } it generates the following disassembled code Foo: 00000000: 4E56 0000 LINK A6,#$0000 00000004: 2F07 MOVE.L D7,-(A7) 00000006: 3E2E 0008 MOVE.W $0008(A6),D7 0000000A: E35F ROL.W #$1,D7 0000000C: 3007 MOVE.W D7,D0 0000000E: 0A40 1021 EORI.W #$1021,D0 00000012: 2E1F MOVE.L (A7)+,D7 00000014: 4E5E UNLK A6 00000016: 4E75 RTS 00000018 so I thought to convert it to C++ by doing short Foo(register short x) { return ((x<<1) ^ 0x1021); } which seems to compile OK and generates the following (longer and different) disassembled code: Foo(short): 00000000: 4E56 0000 LINK A6,#$0000 00000004: 2F03 MOVE.L D3,-(A7) 00000006: 362E 0008 MOVE.W $0008(A6),D3 0000000A: 3003 MOVE.W D3,D0 0000000C: E340 ASL.W #$1,D0 0000000E: 0A40 1021 EORI.W #$1021,D0 00000012: 261F MOVE.L (A7)+,D3 00000014: 4E5E UNLK A6 00000016: 205F MOVEA.L (A7)+,A0 00000018: 544F ADDQ.W #$2,A7 0000001A: 4ED0 JMP (A0) 0000001C: 8746 6F6F 5F5F DC.B $80+$07, 'Foo__Fs' 4673 00000024: 0000 DC.W 0 ; size of literals 00000026 My goal was to remove the asm so here are my questions: (0) Please show me the correct way to do this in C++ so I do not need the asm. (1) If I do need the asm should I be using #pragma parameter ….. e.g. to force use of d0 (3) Finally my assembler days are long over and furthermore were on 370. But I am guessing ASL is Arithmetic Shift Left and ROL is Rotate Left. Am I correct? If so would ASL preserve the sign bit but ROL shift it? Finally do both ASL and ROL right fill with zeroes? Or does ROL really rotate the shifted bit around to the right hand end?
#7249From: David SachsJul 20, 1993 9:55 PM
[…so I thought to convert it to C++ by doing short Foo(register short x) { return ((x<<1) ^ 0x1021); }…] One thing you could do is declare it as an inline function inline short Foo(register short x) { return ((x<<1) ^ 0x1021); }
#7276From: Peter H. TeesonJul 21, 1993 5:43 AM
Thanks for your help… I was intending to after I debugged it. Peter
#7269From: Steve StockmanJul 21, 1993 12:16 AM
Peter: >>> If I do need the asm should I be using #pragma parameter ….. e.g. to force use of d0 <<< Would be a good idea. >>> But I am guessing ASL is Arithmetic Shift Left and ROL is Rotate Left. <<< You are correct. With ASL, the high order bit is shifted into both the Carry and Extend bits of the condition code register (CCR), and zeros are shifted into the low order bits. With ROL, the high order bit is shifted into both the CCR Carry bit and the low order bit of the same value. Steve