Chinmay
Chinmay

Reputation: 13

How to print a string and another string variable in same line in MIPS?

Currently I get output as

dsajnd

is not a palindrome

And I want it to output such that the (e.g dsajnd) and " is not a palindrome" are on the same line.

dsajnd is not a palindrome

the code I have for printing this is

true:   
move $a3, $t0
la $v0, 4
syscall
        # printing the true_msg, and exit.
la $a0, true_msg
li $v0, 4
syscall
b exit


false:
move $a3, $t0
la $v0, 4
syscall

la $a0, false_msg # printing the false_msg, and exit.
li $v0, 4
syscall
b exit


exit: ## exit the program:
li $v0, 10 # loading "exit" into $v0.
syscall 

.globl Print_string
Print_string: # print the string whose starting address is in register a0
li $v0, 4
syscall
jr $ra

.data
buffer: .space 12
true_msg: .asciiz "is a palindrome"
false_msg: .asciiz "is not a palindrome"

Upvotes: 0

Views: 4789

Answers (1)

qwr
qwr

Reputation: 10955

Whatever string you have must have a newline or line feed at the end. You need to remove that. MIPS will not automatically add newlines unless you explicitly tell it to.

Upvotes: 1

Related Questions