I use Keil C and I want to use 128 bit integer addition/subraction on the LPC2148?

Can I do this math operation with pure C?

Can you give me inline assembler source code for this purpose?

I use Keil C and I want to use 128 bit integer addition/subraction on the LPC2148?

Can I do this math operation with pure C?

Can you give me inline assembler source code for this purpose?

You can do this in nearly any language. The question is of how much time it will take. I would approach it from a digital logic perspective - the infamous full adder. A one-bit full adder has three inputs and two outputs: A (in), B (in), Carry (in), Sum (out), and Carry (out). I’ll use A, B, Cin, S, and Cout, respectively.

You can find a full explanation on the web by searching “full adder”.

For multiple-bit math, these are cascaded (if you don’t use a look-ahead carry generator.) Cout of the lowest-order bit connects to Cin of the next-highest-order bit. The last Cout is the carry flag.

In software, you need only to logically cascade four 32-bit adders. For subtraction with two’s-compliment, invert B, set the lowest-order Cin to one, and add as you did before.

Perhaps this thread will help:

The hard part is that C (like most high level languages) doesn’t give you access to the carry bit. You can play difficult tricks, or you can use inline assembly.

It’s possible that your compiler supports a 128-bit integer data type, though. I know nothing of Keil C.

try declaring your 128 variables as “long long” and see if that works !

Well, well… google for bigdigits this is a library that perfom basic + more math operations in any integer precision, so 128bit is not a bit deal!

and here is the link: http://www.di-mgt.com.au/bigdigits.html

enjoy as I did!! this lib was a relief for me