简体   繁体   中英

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.

syscall 1 expects $a0 to contain the value to print , no the address of the value to print. 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). You could do this either with syscall 4 ( print_string ) or two calls to syscall 11 ( print_character ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM