You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在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 unsigned DDIVU) does calculate both quotient and remainder, just like the standard MIPS DIV instruction. 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 $LO and $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) and MFHI (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 DDIVU instead of DDIV—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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:05:48