如何在 MIPS 中加载数组的地址
How do I load the Address of an array in MIPS
.data
strA: .asciiz "Original Array:\n"
strB: .asciiz "Second Array:\n:"
newline: .asciiz "\n"
space : .asciiz " "
# This is the start of the original array.
Original: .word 200, 270, 250, 100
.word 205, 230, 105, 235
.word 190, 95, 90, 205
.word 80, 205, 110, 215
# The next statement allocates room for the other array.
# The array takes up 4*16=64 bytes.
#
Second: .space 64
.align 2
.globl main
.text
main:
la $t0, Original #load address of original array
li $v0, 4 #system call code for printing
la $a0, strA
syscall
addi $t1, $zero,0
sll $t2, $t1, 2
add $t3, $t2, $t1
li $v0, 4
lw $a0, 0($t3)
syscall
我正在尝试制作一个转置矩阵的程序。但是我一直收到错误地址读取错误:0x00000000。我尝试加载矩阵的地址,然后将 0 加载到 $t1 作为起始索引,然后将其乘以四并将其添加到数组的基址。
如您所见,我已经加载了数组的地址,并且还添加了带有 sll 的 i*4 数量。为什么会出现此错误?
系统调用 4 打印一个 字符串。如果你想打印一个整数数组,你必须编写一个循环并对数组中的每个整数使用系统调用 1 (print_int
)。
异常发生在 lw $a0, 0($t3)
,如果你看看你设置 $t3
的方式,应该很明显它不能有除 0 之外的任何其他值,所以我不确定您希望在那里发生什么。
我假设您使用的是 SPIM 或 MARS 之类的模拟器,因此您可以轻松地自己找出这些东西。模拟器将报告发生异常的地址,因此您可以在该地址设置断点(或单步执行到该地址)并查看寄存器的值以查看它们是否有意义。
.data
strA: .asciiz "Original Array:\n"
strB: .asciiz "Second Array:\n:"
newline: .asciiz "\n"
space : .asciiz " "
# This is the start of the original array.
Original: .word 200, 270, 250, 100
.word 205, 230, 105, 235
.word 190, 95, 90, 205
.word 80, 205, 110, 215
# The next statement allocates room for the other array.
# The array takes up 4*16=64 bytes.
#
Second: .space 64
.align 2
.globl main
.text
main:
la $t0, Original #load address of original array
li $v0, 4 #system call code for printing
la $a0, strA
syscall
addi $t1, $zero,0
sll $t2, $t1, 2
add $t3, $t2, $t1
li $v0, 4
lw $a0, 0($t3)
syscall
我正在尝试制作一个转置矩阵的程序。但是我一直收到错误地址读取错误:0x00000000。我尝试加载矩阵的地址,然后将 0 加载到 $t1 作为起始索引,然后将其乘以四并将其添加到数组的基址。
如您所见,我已经加载了数组的地址,并且还添加了带有 sll 的 i*4 数量。为什么会出现此错误?
系统调用 4 打印一个 字符串。如果你想打印一个整数数组,你必须编写一个循环并对数组中的每个整数使用系统调用 1 (print_int
)。
异常发生在 lw $a0, 0($t3)
,如果你看看你设置 $t3
的方式,应该很明显它不能有除 0 之外的任何其他值,所以我不确定您希望在那里发生什么。
我假设您使用的是 SPIM 或 MARS 之类的模拟器,因此您可以轻松地自己找出这些东西。模拟器将报告发生异常的地址,因此您可以在该地址设置断点(或单步执行到该地址)并查看寄存器的值以查看它们是否有意义。