2016-02-20 206 views
0

刚开始学习MIPS,可能有人在这个简单的代码解释一个细节:这里是代码:MIPS,寄存器,初学者

main: 

    li $v0, 5 
    syscall 
    move $t0, $v0 

    li $v0, 5 
    syscall 
    move $t1, $v0 

    add $t2, $t0, $t1 

    move $a0, $t2 
    li $v0, 1 
    syscall 
exit: 
    li $v0, 10 
    syscall 

这是我的理解:li $v0 5 syscall -means立即加载一个整数,被阅读(在$v0?我认为)。然后我得到其余的移动,加入...

当我开始不理解是当行:li $v0, 1 syscall - 出现。这将不得不打印一个整数(从$v0?)。它如何知道要打印$a0$t2。这个怎么用?

像这个例子:

la $a0, str1 
li $v0, 4 
syscall 

这从$a0打印字符串。为什么不打印另一个字符串,但特别是这个?那是最后提到的字符串印刷规则

+0

见https://www.doc.ic.ac.uk/实验室/ secondyear/SPIM/node8.html – Michael

回答

0

这只是系统调用提供服务的一部分(在这种情况下):http://courses.missouristate.edu/KenVollmar/mars/Help/SyscallHelp.html

main: 

li $v0, 5 #read integer 
syscall 
move $t0, $v0 #t0 is the integer you intend to read 

li $v0, 5#same as above 
syscall 
move $t1, $v0 

add $t2, $t0, $t1 #add two integers and store it in t2 

move $a0, $t2 # move sum to integer to print 
li $v0, 1 #integer to print 
syscall 
exit: 
li $v0, 10 # terminate execution 
syscall