如何用浮点数填充二维数组?
使用装配 我需要一个简单的代码来填充二维数组
更新: 这就是我到目前为止所得到的。但我在打印数组时仍然遇到问题!
.data
arrayf: .word 600
msg1: .asciiz "Enter N: "
msg2: .asciiz " rows by "
msg3: .asciiz " values. Enter them: "
doneFill: .asciiz "Done with filling array\n"
.text
main:
li $v0, 4
la $a0, msg1
syscall
li $v0, 5
syscall
move $a1, $v0 # $a1 = N
li $v0, 1
move $a0, $a1
syscall
li $v0, 4
la $a0, msg2
syscall
move $a0, $a1
addu $a0, $a0, 1
li $v0, 1
syscall
li $v0, 4
la $a0, msg3
syscall
la $t1, arrayf
move $t0, $a1
add $t0, $t0, 1
mul $t0, $t0, $a1 # $t0 = N * (N+1)
fill:
li $v0, 6
syscall
swc1 $f0, 0($t1)
addi $t1, $t1, 4
subi $t0, $t0, 1
bnez $t0, fill
li $v0, 4
la $a0, doneFill
syscall
la $t1, arrayf
print
lwc1 $f12, 0($t1)
c.eq.s $f12, $f30
bc1t exit
li $v0, 2
syscall
add $t1, $t1, 4
j print
Using Assemply
I need a simple code that fill a 2-dimensional array
Update:
That what I got so far. But still I have a problem in printing the array!
.data
arrayf: .word 600
msg1: .asciiz "Enter N: "
msg2: .asciiz " rows by "
msg3: .asciiz " values. Enter them: "
doneFill: .asciiz "Done with filling array\n"
.text
main:
li $v0, 4
la $a0, msg1
syscall
li $v0, 5
syscall
move $a1, $v0 # $a1 = N
li $v0, 1
move $a0, $a1
syscall
li $v0, 4
la $a0, msg2
syscall
move $a0, $a1
addu $a0, $a0, 1
li $v0, 1
syscall
li $v0, 4
la $a0, msg3
syscall
la $t1, arrayf
move $t0, $a1
add $t0, $t0, 1
mul $t0, $t0, $a1 # $t0 = N * (N+1)
fill:
li $v0, 6
syscall
swc1 $f0, 0($t1)
addi $t1, $t1, 4
subi $t0, $t0, 1
bnez $t0, fill
li $v0, 4
la $a0, doneFill
syscall
la $t1, arrayf
print
lwc1 $f12, 0($t1)
c.eq.s $f12, $f30
bc1t exit
li $v0, 2
syscall
add $t1, $t1, 4
j print
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 2 个循环,一个用于列,一个用于行。给定 array[a][b],array[x][y] 的偏移量为
x + y*a
Use 2 loops, one for columns and one for rows. Given
array[a][b]
the offset ofarray[x][y]
isx + y*a
我发现了问题。
这是在打印过程中。分支退出的条件是错误的。
谢谢@blackbear & @Carl 花时间试图帮助我:)
I found the problem.
It was in the print procedure. The condition to branch to exit was wrong.
Thanks @blackbear & @Carl for spending your time trying to help me :)