如何用浮点数填充二维数组?

发布于 2024-10-08 06:22:13 字数 846 浏览 0 评论 0原文

使用装配 我需要一个简单的代码来填充二维数组

更新: 这就是我到目前为止所得到的。但我在打印数组时仍然遇到问题!

.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神爱温柔 2024-10-15 06:22:13

使用 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 of array[x][y] is x + y*a

无可置疑 2024-10-15 06:22:13

我发现了问题。

这是在打印过程中。分支退出的条件是错误的。

谢谢@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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文