I have the following method in C that takes two 16-bit short ints and:
- Adds the two integers
- If the carry flag is set, add 1 to the result
- Negate (NOT) all the bits in the final results
Return the result:
short __declspec(naked) getchecksum(short s1, short s2) { __asm { mov ax, word ptr [esp+4] mov bx, word ptr [esp+8] add ax, bx jnc skip_add add ax, 1 skip_add: not ax ret } }
I had to write this in inline assembly because I do not know any way to test the carry flag without using assembler. Does anyone know of a way to do this?