- #1
Kerren
- 9
- 0
Hey guys I've been working on this program for just over a week now and I just can't seem to find any way around my problem. The problem I'm having is:
I'm trying to add 32 bit numbers together and if there is an overflow then I'd like to find a way to output the result as a 64 bit number.
I had a couple of ideas (as of yet, none of them have worked ) so here they are:
Thanks guys!
I'm trying to add 32 bit numbers together and if there is an overflow then I'd like to find a way to output the result as a 64 bit number.
I had a couple of ideas (as of yet, none of them have worked ) so here they are:
- My first bright idea
I tried to add numbers together and when there was an overflow I'd increment another register (lets call it the "overflow" register). Once the calculation was done I would just output the overflow register next to the other register to make a "64 bit" number In theory this would work IF we were working in decimal (base 10) because when there is an overflow a digit is added to the front of the result, however, in binary there is not always a whole new digit added to the front of the result so this didn't work for me and I got some pretty funny answers !
- The second idea
I tried to allocate 8 bytes in the heap memory block and just save the result to that. The problem I had is that I can't dereference that allocated memory in the actual add function. This means that I have to use an intermediate register for calculating the result and then I would copy this intermediate register to the allocated memory. This defeats the point of the allocated memory because the intermediate register is only 32 bits
- The third (untested) idea
I want to read in an actual binary input and then I can shift the bits and if there is an overflow I add them to a new binary number (the overflow register) and then output both the overflow register and the result register together to form a 64 bit number. The problem I'm having is that I don't actually know how to make a binary variable (is there even such a thing as a "binary variable" ??)
- The fourth idea
I tried to use the $f register because it looks to me like they are 64 bit registers but it seems like they are private registers that I cannot access. Does anyone know any way around this?
- Other thoughts
Is there any way to link registers together so that they can form virtual 64 bit ones (I know that's a really hopeful thought )?
Also does anyone have any other ideas on how to make a 64 bit system using only 32 bit registers?
Thanks guys!