I need to add a 32-bit number to a 48-bit number. What I want to do is perform the first 32 bit arithmetic in C as follows: Wv.A += Wv.B ; And to propagate the carry to the most significant word as follows: __asm { ADDC WORD Wv+10,#0 } Unfortunately I get on compilation the following error: error C195: inline-asm: Invalid instruction operand(s) Apparently the identifier Wv is not known by the compiler though it is known in C expressions and similar assembler statements are generated by the compiler when I select a SRC output of the compiler. Is someone familiar with inline assembly? Thanks
The 166 has no instruction encoding for:
ADDC mem,#data
#include <reg167.h> : __asm { ADDC Wv+10,ZEROS } // fails
I mean:
#include <reg167.h> : __asm { ADDC Wv+10,ZEROS } // works
You can do this all in C by checking to see if the low word rolls over, and if so incrementing the high word. Something like:
// access 64-bit word in various sized pieces typedef union { U64 u64; U8 array[8]; U16 warray[4]; struct { MultiByte32 ms; MultiByte32 ls; } longs; } MultiByte64; void U64AddEqU32 (U64* u64, U32 u32) { if ((MaxU32 - ((MultiByte64*)u64)->longs.ls.u32) <= u32) { // addition will roll over ((MultiByte64*)u64)->longs.ms.u32++; } ((MultiByte64*)u64)->longs.ls.u32 += u32; } // U64AddEqU32