GIDForums  

Go Back   GIDForums > Computer Programming Forums > Assembly Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 06-Apr-2009, 18:49
Mriswith Mriswith is offline
New Member
 
Join Date: Apr 2009
Posts: 3
Mriswith is on a distinguished road

MIPS 64-bit subtraction


Hello all, I'm quite new to programming, and I'm trying to impliment 64-bit subtraction in MIPS.

This is how I have things set up. X and Y are 64-bit positive integers, where each is represented as an array of two 32-bit positive integers. That is, X[0] and Y[0] contain the high order 16 bits, and X[1] and Y[1] contain the low order 16 bits.

I'm a little bit stuck here, as I don't know how to proceed. If anyone could point me in the right direction I would be greatly appreciative.

Thanks!
  #2  
Old 07-Apr-2009, 08:30
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 800
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: MIPS 64-bit subtraction


Could you post:
- a minimal sample of the code you are trying to do that runs.
- a sample of what you are trying to include in the above which you are having trouble with.
- A statement that expresses why YOU think it doesn't work.
- Also - what compiler are you using?
  #3  
Old 07-Apr-2009, 08:56
Mriswith Mriswith is offline
New Member
 
Join Date: Apr 2009
Posts: 3
Mriswith is on a distinguished road

Re: MIPS 64-bit subtraction


I'm sorry, perhaps I should have been more clear. I'm a little stuck on the concept. I think I could figure out the code if I knew where to begin. I'm more stuck on, "what do I need to subtract from where to obtain the correct value". Like, do I need to subtract Y[0] from X[0]? Or something else?

I'm using MARS for the compiler. courses.missouristate.edu
*EDIT* For some reason the link won't post.

Code:
http://courses.missouristate.edu/KenVollmar/MARS/

Thanks for the response.
  #4  
Old 08-Apr-2009, 00:54
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 800
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: MIPS 64-bit subtraction


I downloaded and tried it out. Nice IDE.

As far as working with 64 bit values goes,
Use the 64 bit registers on one of the new 64 bit cpus! haha

Seriously, I'm not sure what to tell you as I have never done this.
I have been trying to find a good reference but it is late.
I have seen it described for working with 32 bit values in 16 bit registers.

Above you are using 16 bit array elements,,,
so are you working with a cpu with 16 bit registers? or 32?

sorry I can't be of more help I can look some more tomorrow.
Maybe someone else could help us both.
  #5  
Old 08-Apr-2009, 10:16
Mriswith Mriswith is offline
New Member
 
Join Date: Apr 2009
Posts: 3
Mriswith is on a distinguished road

Re: MIPS 64-bit subtraction


I believe I mis-spoke, X[0] and Y[0] should contain the high order 32 bits, and X[1] and Y[1] contain the low order 32 bits.
  #6  
Old 08-Apr-2009, 11:14
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,217
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: MIPS 64-bit subtraction


Quote:
Originally Posted by Mriswith
...X[0] and Y[0] should contain the high order 32 bits, and X[1] and Y[1] contain the low order 32 bits.

I am assuming you are using a 32-bit machine with 32-bit add/subtract instructions.

Here are some considerations for multiple-precision integer subtraction:

First of all, for simplicity, assume that the integers are unsigned, and there are instructions to perform binary subtraction.

If there were a separate unsigned "subtract with borrow" instruction, as there is in just about all CISC machines, and if there were a "borrow" status bit that is set according to the results of any subtraction operation, this is how you would do it. (That is, this is how I would do it):

Code:
1. Subtract lower parts using normal unsigned subtraction: clow = alow - blow 2. Subtract upper parts using unsigned subtraction with borrow: clow = alow -blow - borrow

See the following for a discussion of why there is not an "add with carry" operation on standard MIPS machines. (The reasoning, obviously, applies to the question of why there is no "subtract with borrow" instruction on MIPS machines.) There is an example of multi-precision addition.
http://yarchive.net/comp/carry_bit.html

Now, see the following for examples of multiple-precision addition and other operations on standard MIPS machines:
http://staff.science.nus.edu.sg/~phy...tut5answr.html

Extrapolating from the addition example, consider the following for multiple-precision subtraction:

Code:
1. Subtract lower parts using the subu instruction: clow = alow - blow 2. Use the sltu instruction to create the "borrow" bit according to the following: If clow is less than or equal to alow, there is no "borrow" If clow is greater alow, there is a "borrow" 3. Subtract the high parts using the subu instruction: chigh = ahigh - bhigh 4. Use subu to subtract the "borrow" bit from the high result: chigh = chigh - borrow

Regards,

Dave
Last edited by davekw7x : 08-Apr-2009 at 11:49.
  #7  
Old 08-Apr-2009, 14:41
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,217
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: MIPS 64-bit subtraction


Quote:
Originally Posted by davekw7x
Code:
2. Use the sltu instruction to create the "borrow" bit according to the following: If clow is less than or equal to alow, there is no "borrow" If clow is greater alow, there is a "borrow"

Actually it looks as if the sgtu instruction might be more appropriate for this logic condition.

Regards,

Dave
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mips Array/Loop assistance SpeedisaVirus Assembly Language 2 19-Sep-2008 14:17
Request code for a non-recursive binary search in MIPS ks_100 Assembly Language 0 15-Feb-2008 12:10
MIPS instructions kokopo2 C Programming Language 7 24-Aug-2005 13:50

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 08:26.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.