[英]MIPS print integer without use any pseudoinstructions
Here is what I did 这是我所做的
num1:.word 1
num2:.word 2
.globl main
.text
main:
lui $t0,0x1001
addi $v0,$0,1 #set commend to print
addi $s2,$0,5 # add 5 to $s2
sw $s2,4($t0) # store the val in word 2
addi $a0,$t0,4 # add 4 to t0 to start the second word
syscall # print int
I want the value of s2 to be print however I got 268500996. Also , if i want to print word 1 and word 2 how to make each output on its own line. 我希望打印s2的值,但是我得到268500996。此外,如果我想打印单词1和单词2,如何在自己的行上输出每个输出。
syscall
1 expects $a0
to contain the value to print , no the address of the value to print. syscall
1 期望$a0
包含要打印的值 ,不包含要打印的值的地址。 So instead of: 所以代替:
sw $s2,4($t0) # store the val in word 2
addi $a0,$t0,4 # add 4 to t0 to start the second word
you should just do: 您应该这样做:
or $a0, $s2, $0 # $a0 = $s2
To print a newline you would print the characters 13 (Carriage Return) and 10 (Linefeed). 要打印换行符,您将打印字符13(回车)和10(换行)。 You could do this either with
syscall
4 ( print_string
) or two calls to syscall
11 ( print_character
). 您可以使用
syscall
4( print_string
)或两次调用syscall
11( print_character
)来完成此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.