#squre(x)
.text
.globl main
main:
square:
la $t0,word
la $a0,msg #print message for calling for type in
li $v0,4
syscall
li $v0,5 #Read_int
syscall
sw $v0,0($t0)
lw $t2,0($t0)
#不需要用 "li $t1,0" 或 "la $t1,word" 來 initialize $t1
#如果用 "la $t3,word",則運算元內容將會變成 address 而不是 value
Loop:
beq $t1,$t2,EXIT #$t1 is count, $t3 is sum, if i==x, than branch to EXIT
add $t3,$t3,$t2 #j=j+x
addi $t1,$t1,1 #increment i
sw $t3,4($t0)
j Loop
EXIT:
la $a0,ans #print message of result prompt
li $v0,4
syscall
lw $t4,4($t0) #print the answer
li $v0,1
move $a0,$t4
syscall
.data
msg: .asciiz "請輸入一個數字:"
word: .word 0,0
ans: .asciiz "平方的結果是:"
#Finished by Veck Hsiao
就也是一個念資訊的大學生,涉足領域在網路、資安、程設、系統、網設..... Next City @ Veck:http://veck.logdown.com/
2011年4月25日 星期一
~計組~ MIPS 組語寫平方程式
因為最近在考試,就只有先PO上完成的程式碼當參考~
訂閱:
文章 (Atom)