これは初めてのアセンブリプログラムの作成です。最初の2つのユーザー入力と合計を格納する$ t0、$ t1、$ t2を使用して基本的な追加プログラムを作成するはずです。私のユーザー入力が常に5として保存されている理由を理解できません。MIPS - 簡易加算 - 一時レジスタを使用した記憶域の入力
私のシステムコールに問題がありますか?
.data
prompt1: .asciiz "Give me an integer number: "
debug1: .asciiz "The first number inputted was: "
debug2: .asciiz "The second number inputted was: "
prompt2: .asciiz "\nGive me another integer number: "
result: .asciiz "\nThe sum of the two inputted numbers is: "
.text
li $v0, 4 #System call to print a string
la $a0, prompt1 #load prompt1 into address 0 - Give me an integer
syscall
#store first input in $t0
li $v0, 5 #System call code for Read Integer from input
move $t0, $v0 #Move value from $v0 to $t0
syscall
#print the First user input for debugging --> Always prints 5
li $v0, 4 #System call code for Print String
la $a0, debug1 #Print debug1 string
syscall
li $v0, 1 #print int
move $a0, $t0 #move value in $t0 to $a0
syscall
#call prompt 2
li $v0, 4 #Print a string
la $a0, prompt2 # Here is the value to print - "Give me another integer"
syscall
#store second input in $t1
li $v0, 5 #System call code for Read Integer from input
move $t1, $v0 # $t1 = value from input
syscall
#print the second int input for debugging --> Always prints 5
li $v0, 4 #System call code for Print String
la $a0, debug2 #Print debug2 string
syscall
li $v0, 1 #System call code for Print Int
move $a0, $t1 #move value in $t1 to $a0
syscall
#add numbers
add $t2, $t1, $t0 # $t2 = $t1+$t0
li $v0, 4 #System call to Print String
la $a0, result #Print the string result
syscall
li $v0, 1 #System call to Print Int
move $a0, $t2 #Move $t2, which = $t1 + $t0, into $a0
syscall
私は事前に助けていただきありがとうございます。
#store second input in $t1
li $v0, 5 #System call code for Read Integer from input
syscall
move $t1, $v0 # $t1 = value from input
李行の後にシステムコールを持っている、とない移動行の後にすべき -
デバッガでどの値がレジスタに入っているか確認しましたか?読まれたシステムコールの戻り値が期待どおりであることを確認し、それが後のコードの正しい場所に終わることを確認することができます。 (私は多くのMIPSを知らず、何か間違っていることに気づいていませんでした) –
ちょっと@PeterCordesはい、$ t0と$ t1レジスタは常に値5を返しています。 「Get Int From Input」のコードが5であるという事実に従ってください。別名「li $ v0、5」。ですから、なぜ$ v0は入力によって上書きされないのですか? – zomp