我正在尝试编写 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