Nios/add64

From ASMBits

nios/bits2Previous

Write a function that returns the sum of its two parameters. The parameters and return values are both 64-bit integers. 64-bit operands are passed in two consecutive registers. Thus, the first parameter is in r4 and r5, while the second parameter is in r6 and r7, with the return value returned in r2 and r3.

long long add64 (long long a, long long b);

Expected solution length: Around 5 lines.

Sample Input

(1, 1)

Sample Output

2 

The difference between regular addition and big-integer addition is that you need to detect the carry-out from the low-order adder and feed that to the high-order adder (much like a ripple-carry adder). Nios II does not have an easy way to detect carry-out from an addition. The method recommended by the ISA reference is to compare the result with one of the operands: If an addition overflows, the addition result is always (unsigned) smaller than both of its operands.

Write your solution here

Upload a source file...