Как вывести число и строку в одной строке с системными вызовами MARS / SPIM? - PullRequest
0 голосов
/ 04 февраля 2020

Недавно я делал домашнюю работу и пытался напечатать переменную и строку в одной строке. Я хочу спросить, как напечатать их в одной строке в MIPS?

Мой текущий результат:

Please enter your nickname: Harry
Please enter your surname: Chan
Harry
Chan
How old are you? 20
You are 20
 years old.

Что я хочу:

Please enter your nickname: Harry
Please enter your surname: Chan
Harry
Chan
How old are you? 20
You are 20 years old.

MIPS код :

.data

question1: .asciiz "Please enter your nickname: "
question2: .asciiz "Please enter your surname: "
question3: .asciiz "How old are you? "
buffer1: .space 60
buffer2: .space 60
buffer3: .space 60
str1: .asciiz "You are "
str2: .asciiz " years old."

#-----Text Segment----------------- 
.text
.globl __start 
__start:
# ---------------------- 
# Write your code here
li $v0, 4
la $a0, question1
syscall

li $v0,8 #take in input
la $a0, buffer1 #load byte space into address
li $a1, 60 # allot the byte space for string
move $t0,$a0 #save string to t0
syscall

li $v0, 4
la $a0, question2
syscall

li $v0,8 #take in input
la $a0, buffer2 #load byte space into address
li $a1, 60 # allot the byte space for string
move $t1,$a0 #save string to t1
syscall

la $a0, buffer1 #reload byte space to primary address
move $a0,$t0 # primary address = t0 address (load pointer)
li $v0,4 # print string
syscall

la $a0, buffer2 #reload byte space to primary address
move $a0,$t1 # primary address = t1 address (load pointer)
li $v0,4 # print string
syscall

li $v0, 4
la $a0, question3
syscall

li $v0,8 #take in input
la $a0, buffer2 #load byte space into address
li $a1, 60 # allot the byte space for string
move $t2,$a0 #save string to t2
syscall

li $v0, 4
la $a0, str1
syscall

la $a0, buffer1 #reload byte space to primary address
move $a0,$t2 # primary address = t2 address (load pointer)
li $v0,4 # print string
syscall

li $v0, 4
la $a0, str2
syscall

# ----------------------
# Terminate the program
li $v0, 10
syscall

1 Ответ

0 голосов
/ 13 февраля 2020

Ответ от моего одноклассника:

    #print out question 3 and store input

        li $v0, 4
        la $a0, question3 

        syscall

        li $v0, 5
        syscall

        move $t0, $v0

    #print out str 1, str2 and answer

        li $v0, 4
        la $a0, str1
        syscall

        li $v0, 1
        move $a0, $t0
        syscall

        li $v0, 4
        la $a0, str2
        syscall
...