在MIPS中打印单词的字母

时间:2010-08-26 18:29:06

标签: assembly mips

请帮我编写汇编程序(MIPS) 我有一句话“你好!”然后我需要mips打印:

h
he
hel
hell
hello
hello!

我试过了:

.data
lbl1: .asciiz "hello!"
lbl2: .asciiz "h "
end_line: .asciiz "\n"

 .text
 main:  la $s0, lbl1
        move $a0, $s0
        addi $v0, $zero, 4
        syscall jr $ra

但它打印了我所有的字符串,我只需要一两个字母。

感谢您的帮助

1 个答案:

答案 0 :(得分:2)

好的,所以你有一个系统调用来打印一个以零结尾的字符串。你将要拥有的是

for i = 1 to 6 (length of "hello!")    
    read the character from position i in your string and store it safely
    write a 0 into your string at position i
    syscall to print the edited string
    write the saved character back to position i
    syscall to print the newline
next

allocate a buffer for a complete copy of your string
for i = 1 to 6
   copy the first i characters of your string into the buffer
   append a newline and a zero to terminate the string
   syscall to print the buffer
next

希望你知道足以将其中一个编码为汇编程序。您还可以通过将换行符换入和换出字符串以及零来实现第一个。