错误:运行时异常...存储地址在字边界上未对齐 [英] Error: Runtime exception ... store address not aligned on word boundary

查看:77
本文介绍了错误:运行时异常...存储地址在字边界上未对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打印任何整数输入的二进制数字并将它们存储在从最后一个索引开始的数组中.然后我试图从数组中打印它.

I am trying to print binary digits of any integer input and store them in the array starting at the last index. Then I am trying to print it from the array.

    .data

prompt: .asciiz "Enter an int: "
errorLarge: .asciiz "Error Value to large CANNOT be held in 16 bit"
errorSmall: .asciiz "Error Value is to small CANNOT be held in 16 bits"

# 64bytes =512 bits created (1 int =4 bytes):: (16 int =64 bytes)
array: .space 64

newLine: .asciiz "\n"

    .globl main
    .text

main:
    li $v0,4
    la $a0,prompt
    syscall

    li $v0,5
    syscall
    move $t0,$v0

    li $t1,32767
    li $t2,-32767

    bgt $t0,$t1,InputToGreat
    blt $t0,$t2,InputToSmall

    li $t2,2
    li $t5,64     # last memory location in array+1

    li $t7,0

    j initializer

InputToGreat:

    li $v0,4
    la $a0,errorLarge
    syscall

    j main

InputToSmall:

    li $v0,4
    la $a0,errorSmall
    syscall

    j main

finalizer:

    subi $t5,$t5,4
    sw  $t4,array($t5)

    li $t4,0

    bne $t5,$zero, finalizer

OutPut:

    lw $t6,array($t7)

    li $v0,1
    move $a0,$t6
    syscall

    addi $t7,$t7,4
    bne  $t7,252,OutPut

    li $v0,10
    syscall

initializer:

    div    $t0,$t2  # (inside house) 1) 12/2  2) 6/2   3) 3/2
    mflo   $t0  #quotient       6        3        1
    mfhi   $t4  #rem                0        0        1

    beq    $t4,1,finalizer

InputToArray:

    subi $t5,$t5,4
    sw  $t4,array($t5) #first time array+60 last location in array

    li $v0,1
    move $a0,$t4
    syscall

    j initializer

我在第 99 行 sw $t4,array($t5) #first time array+60 last location in array 上遇到一个错误

I am getting an error on line 99 sw $t4,array($t5) #first time array+60 last location in array which says

第 99 行:0x004000d8 处的运行时异常:存储地址未在字边界 0x100100ab 上对齐

line 99: Runtime exception at 0x004000d8: store address not aligned on word boundary 0x100100ab

推荐答案

因为你用 sw 存储到 arrayarray 必须是 4字节对齐.这是 mips 架构的限制.lw 也是如此.

Because you store into array with sw, array must be 4 byte aligned. This a restriction of the mips architecture. Likewise for lw.

所以,改变:

array: .space 64

进入:

    .align 4
array: .space 64

另外,请注意 $t5 应该可以被 4 整除(这是你的测试程序运行时)

Also, note that $t5 should be divisible by 4 (which it is when your test program runs)

这篇关于错误:运行时异常...存储地址在字边界上未对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆