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

MIPS汇编运行时地址未对齐错误及输出异常排查求助

MIPS汇编运行时地址未对齐错误及输出异常排查求助

各位大佬好,我最近写了一段MIPS汇编代码,本来打算先打印一个6×8的浮点矩阵,再让用户输入两个列号做后续处理,但运行时不仅触发了地址未对齐错误,矩阵的输出格式也完全不对,折腾了好一阵都没找到问题根源,求帮忙看看!

以下是我的完整代码片段:

.data
    # Define static matrix mymat consisting of 6x8 elements
    mymat: 
        .float 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0
        .float 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0
        .float 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0
        .float 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0
        .float 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 40.0
        .float 41.0, 42.0, 43.0, 44.0, 45.0, 46.0, 47.0, 48.0

    # Prompt messages
    prompt_coll: .asciiz "Enter column number 1 (0-7): "
    prompt_col2: .asciiz "Enter column number 2 (0-7): "
    error_msg:   .asciiz "Invalid column number. Please enter a number between 0 and 7.\n"

.text
main:
    # Printing the elements of mymat
    la $t0, mymat    # Load base address of mymat into $t0
    li $t1, 0        # Initialize counter for printing elements

print_mymat_loop:
    lwc1 $f0, 0($t0)    # Load float value from mymat
    li $v0, 2           # System call code for printing float
    syscall             # Print the float
    
    # 原本打算在这里加空格分隔元素,但忘了定义space字符串
    # li $v0, 4
    # la $a0, space
    # syscall
    
    addi $t0, $t0, 4    # Move to next float (each float is 4 bytes)
    addi $t1, $t1, 1    # Increment element counter
    
    bne $t1, 48, print_mymat_loop    # Loop until all 48 elements are printed

目前遇到的问题:

  • 运行时直接触发地址未对齐错误,但我用.float定义矩阵,每个元素占4字节,地址应该是自然对齐的,实在搞不懂哪里出问题了
  • 就算临时补上space字符串的定义,所有元素都会挤在一行输出,没法按6行8列的格式换行显示
  • 后续要做用户输入列号的验证,担心还有类似的地址或输入处理的坑

麻烦各位大佬帮我分析下问题原因,以及给出修改建议,谢谢大家了!

备注:内容来源于stack exchange,提问作者ahmed alsayegh

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.17 10:13:17