如何在WinMIPS64中计算除法余数?DDIV指令相关疑问
Handling Division Remainders in WinMIPS64
Hey there! I’ve run into this exact quirk with WinMIPS64 before—let me walk you through the easiest way to get both quotient and remainder without resorting to tedious repeated subtraction.
First, let’s clear up the confusion around DDIV:
- Unlike what you might initially think, WinMIPS64’s
DDIV(and unsignedDDIVU) does calculate both quotient and remainder, just like the standard MIPSDIVinstruction. The catch is that the results are stored in the special$LO(quotient) and$HI(remainder) registers, which are often hidden by default in the GUI.
How to access $LO and $HI:
- In WinMIPS64’s register view, look for a settings/options menu (usually a small gear icon or right-click menu) and make sure to check the box to display
$LOand$HI. These are special-purpose registers, so they don’t show up with the general-purpose registers by default. - If you still can’t get them to display, no problem—you can move their values to general-purpose registers using
MFLO(Move From LO) andMFHI(Move From HI) instructions, which will make the values visible in the standard register list.
Example code to get quotient and remainder:
.data dividend: .dword 25 # Dividend (25) divisor: .dword 4 # Divisor (4) .text # Load values into general-purpose registers ld $a0, dividend($zero) ld $a1, divisor($zero) # Perform division: 25 / 4 ddiv $a0, $a1 # Quotient (6) goes to $LO, remainder (1) goes to $HI # Move results to visible registers mflo $t0 # $t0 now holds the quotient (6) mfhi $t1 # $t1 now holds the remainder (1) # You can now store these values to memory or output them as needed
Key notes:
- For unsigned division, use
DDIVUinstead ofDDIV—it works the same way, just treats the operands as unsigned integers. - The terminal output only showing the integer part is probably because you’re only printing the quotient value; once you extract the remainder with
MFHI, you can output that too.
This method is way more efficient than implementing division via subtraction, and it’s exactly how the underlying MIPS architecture handles division—WinMIPS64 just hides those special registers by default!
内容的提问来源于stack exchange,提问作者David
相关产品推荐
相关产品推荐

