Print a new line in MIPS

I am using the MARS MIPS simulator and I want to print a new line in my program.

.data space: .asciiz "\n" .text addi $v0, $zero, 4 # print_string syscall la $a0, space # load address of the string syscall 

Instead of printing a new line, it prints UUUU . What am I doing wrong?

+4
source share
4 answers

If you're just trying to print a new line, it's easier (and a little more memory) for this, using syscall 11 to print a single character.

 .text main: addi $a0, $0, 0xA #ascii code for LF, if you have any trouble try 0xD for CR. addi $v0, $0, 0xB #syscall 11 prints the lower 8 bits of $a0 as an ascii character. syscall 
+6
source

I came here trying to find the answer to the same question that you asked. Since then you have asked this question. Let me answer it one way or another for those who can watch this channel in the future.

Everything else is fine in your code, except that "space" is a reserved word in Mips. I think it is used to create arrays. So, if you replace the place with another word, I used the "new line". It works as intended.

 .data newline: .asciiz "\n" .text li $v0, 4 # you can call it your way as well with addi la $a0, newline # load address of the string syscall 
+4
source

Initialize a new line after the code that prints the value.

therefore he reads:

  addi $v0, $zero, 4 # print_string syscall la $a0, space # load address of the string syscall .data space: .asciiz "\n" .text 
+2
source

try this .. it works for me

  .data newLine .asciiz "\n" .text (your code) la $a0, newLine addi $v0, $0, 4 syscall 
0
source

Source: https://habr.com/ru/post/1403499/


All Articles