Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MIPS - Making a 64 bit number when you only have 32 bit register support

  1. Aug 10, 2012 #1
    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 :biggrin:) so here they are:

    1. My first bright idea :biggrin:
      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 :smile: 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 :smile:!
    2. 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 :smile:
    3. 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" :biggrin:??)
    4. 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?
    5. 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 :smile:)?

      Also does anyone have any other ideas on how to make a 64 bit system using only 32 bit registers?

    Thanks guys!!!
  2. jcsd
  3. Aug 10, 2012 #2
    I'm an idiot!! I thought I put this in the course work section :)!!! Can we move this quick?
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook