MIPS汇编语言
问题描述:
我正在尝试编写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
答
你的程序是非常接近 - 你只是有几个问题:
您错过了
.text
指令。这可能应该在newline
行之后,并且在main:
之前。-
你有一个
$ao
你可能想要一个$a0
接近程序结束。您li $v0,4 #system call code for print string
行之后la $a0,str3 #address of str3 syscall
:你需要添加 -
你没有以往打印
str3
。-
你应该确保在你的程序的末尾添加
exit
系统调用:li $v0,10 syscall
+0
非常感谢你对我有帮助。 – user2101075 2013-02-23 01:51:58
答
.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"
.text
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
la $a0, str3
syscall
#print width*height
li $v0,1
move $a0,$s2 #move the result of multiplication into $a0 to print
syscall
#
li $v0, 10
syscall
什么是你的问题?你在哪个部分遇到麻烦? – 2013-02-23 00:23:39