I am working on a program in assembly that adds two 64 bit words together.
I am working with a 32 bit system. From what I understand, a 32-bit system will only hold 32 bits per a word. Can someone explain a way I could go about making space for 64 bits?
Thank you!

- 25
- 6
-
1Use two 32-bit words to hold 64 bits, and you handle the two words as a unit by convention. If you need to add them, think of how you do arithmetic: add the lower words and add the upper words. If adding the lower words results in a carry, add the carry to the upper words. The assembly language usually has an "add with carry" instruction. You can probably Google for lots of information on this. – lurker Apr 29 '17 at 22:06
-
1What architecture are you programming for? – fuz Apr 29 '17 at 22:54
-
That's what the carry flag is for. See http://stackoverflow.com/questions/12722785/reason-to-use-the-carry-bit-and-the-overflow-bit/12725143#12725143 – sawdust May 05 '17 at 01:34
2 Answers
You don't make space; the system is 32 bits.
What you'd need to do is add the lower 32 bits of each value, handle any carry, and then (with that carry) add the upper 32 bits, storing each addition off to the correct part of wherever you need the total.

- 1,619
- 1
- 8
- 10
You actually already know how to do this from grade school.
If I have a single digit I can do things like
3
+5
===
8
and
4
+2
===
6
and so on, but if I want to use two columns I need to then carry stuff over
1
68
+ 13
=====
81
but if my base 10 processor could only store one digit then I would have to do 8 + 3 = 1 carry the 1. then i would need to add 6 + 1 plus the carry. 6+1+1 = 8 so one register has 1 another has 8 result is 81 across the two registers. binary makes it easier as there are only two symbols so you are either going to carry a 0 or carry a 1 over to the next column. It doesnt matter if you have 7 columns (7 bit registers) or 77 or 32 or whatever.
x
abcd
+efgh
=======
we can split this into
x
cd
+gh
====
with a carry bit of x
then
x
ab
+ef
====
to finish it off. If in assembly language and your processor has a carry flag (some dont use/produce flags but that is okay) then you look to see if they have an add with carry instruction. if not then they probably have a jump/branch if carry set or clear instruction.
so look at your instruction set to see if there is a carry flag, then look to see if your add instruction modifies/sets the carry flag, then look to see if you have an add with carry instruction, the arrange those in the proper order to get the right result.

- 69,149
- 8
- 89
- 168