我正在嘗試編寫MIPS彙編語言,提示用戶輸入描述系統屏幕的兩個維度(用像素表示)的兩個數字,然後計算並打印屏幕的像素數。MIPS彙編語言
例如,在C++:
int width,height,result;
cout<<"Enter width of the device screen: ";
cin>>width;
cout<<"Enter height of the device screen: ";
cout>>height;
result=width*height;
cout<<"The result of the Iphone 4S in pixel: "<<result;
(這是我第一次寫這個MIPS彙編,所以我相信這個代碼是錯誤的,我需要有人幫我更正下面這個代碼和解釋。 。我請)
.data
str1: .asciiz "Enter width of the device screen: "
str2: .asciiz "Enter height of the device screen: "
str3: .asciiz "The result of the Iphone 4S in pixel: "
newline: .asciiz "\n"
main:
li $v0,4 #system call code for print string
la $a0,str1 #address of str1
syscall #print str1
#get the first number from the user, put into $s0
li $v0,5 #system call for read input
syscall #read integer into $v0 from console.
move $s0,$v0 #move the number read into $s0
#read input string for str2
li $v0,4 #system call code for print string
la $a0,str2 #address of str2
syscall #print str2
#get the second number from the user, put into $s1
li $v0,5 #system call for read input
syscall #read integer into $v0 from console.
move $s1,$v0 #move the number read into $s0
#do the calculation
mul $s2,$s0,$s1 # s2 is the register to store $s0 and $s1 from the user input.
#read print string for st3
li $v0,4 #system call code for print string
#print width*height
li $v0,1
move $ao,$s2 #move the result of multiplication into $a0 to print
syscall
什麼是你的問題?你在哪個部分遇到麻煩? – 2013-02-23 00:23:39