簡體   English   中英

MIPS 和矩陣

[英]MIPS and matrices

我正在處理一個涉及 MIPS 和矩陣的學校項目。 基本上我必須編寫一個程序,通過輸入給定一個 N 參數(這應該是我的 NxN 方形矩陣的大小)並且里面的所有元素(同樣,通過用戶輸入插入)應該計算點積將這兩個矩陣的結果放入第三個矩陣中。

我首先來到這段代碼,它在兩個 static 矩陣之后進行點積。 不是通過輸入。 兩件事情。 我應該如何更改它以便讓用戶插入兩個矩陣(以及 N 大小),並且主要是我的矩陣初始化是否正確? 我沒有做這樣的段落“[(i * num_columns + j)*4] 我想知道我得到的是純粹的運氣而不是合理化的問題。提前感謝任何願意幫助我的人並且抱歉對於任何語言錯誤。

.data
v1:     .word 1,2,3,4

    .word 5,6,7,8

    .word 9,10,11,12

v2:     .word 10,20,30,40

    .word 10,10,10,10

    .word 10,10,10,10

v3:     .word 0:12


c: .word 4

space: .asciiz "\n"

.text

main:


li $t0, 0
li $t2, 12
la $t9, c
li $t8, 0


loop:
lw $t3, v1($t0)
lw $t4, v2($t0)

mul $t3, $t3, $t4
addi $t2, $t2, -1

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

li $v0, 4
la $a0, space
syscall

sw $t3, v3($t0)
addi $t0, $t0, 4
addi $t8, $t8, 1
bne $t2, $zero, loop


li $v0, 10
syscall

除了指導您更好地學習語言外,沒有什么可以告訴您如何完成作業。 當你遇到麻煩時,把你遇到的事情和問題貼出來,就會有人幫助。 這是一個框架,可以幫助闡明如何開始。

    .text
main:   
    #call prompt_size       
    #s0 = return val = N

    #a0 = s0: arg = N
    #call new_matrix
    #s1 = return val = address of matrix

    #repeat that two more times

    #call fill_matrix 3 times, sending each matrix address
    #calcuate dot product
    #exit
prompt_size:
    #output prompt
    #read integer
    #return 
new_matrix:
    #t0 = (arg)^2
    #call sbrk(t0)
    #return
fill_matrix:
    #for each byte, prompt for an integer, and insert it
prompt_matrix_element:
    #output_prompt
    #read integer
    #return
exit:
    #exit

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM