![]() |
| ||
| Arithmetic Overflow - MIPS I am converting an MASM procedure to MIPS. Here's the MASM: ; -------------------------------------------------------- Now here's my conversion to MIPS: # ----- Now I don't know why the console displays arithmetic overflow. What am I doing wrong? |
| ||
| Re: Arithmetic Overflow - MIPS And why are you storing your return address into your address of average? Also in odd_lp you're storing the list entry to the minimum $a2 not the median $a3 as your comment says sw $t2, ($a2) Save minimum #median You know the 80x86 code has a bug? You should have displayed the C equivalent function. Finding someone knowing both 80x86 and MIPS can be difficult. OH, this is assembly language. Almost every line of code needs documentation. At a minimum every sub block. Detailing what data is being accessed! On the PC you are using an array of 16-bit numbers? And on the MIPS an array of 32-bit numbers? If int list[] was used on both platforms then the memory access is correct. If not then a problem as the following discusses. If the data on the MIPS is 16-bit then you need to manipulate the load. That is load 32-bit and shift the number into position (high/Low) Load, or you'll get an alignment error. If the data on MIPS is 16-bit then you are running off the end of the list, thus bad data. Since the 80x86 version didn't overflow I'm assuming your numbers are small values. But on the MIPS if 16-bit then you're reading pairs of numbers which appear to be a very large number thus easy to overflow. You are using lw meaning load word and a word is 32-bit. 80x86 MIPS You are scanning the list backwards which isn't memory efficient, however, you don't need to keep doing your pointer math. Merely set your pointer to your list[] entry, then either step backwards by (4 if 32-bit) until the pointer reaches the advancing pointerl. (Beginning of buffer). Or use your length count as a down count by two, and step the two pointers toward each other. When count reaches one or zero you've finish parsing the list. Better yet, pre-subtract one so when the count reaches zero or negative then you're done. Also why are you dividing by two, when you merely need to do a logical shift right by 1. I'll keep looking for your problem! But that should be something to double-check, as well as comment in your code! BTW - In the 80x86 code they could have used a scalar with the register for the memory access and saved some operands. And where is your loop for all list elements? It seems to only be looking at the last two! |
| All times are GMT -4. The time now is 10:22 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC