开发者

Print the letters of the word in MIPS

please help me to write progr开发者_运维百科am in assembly (MIPS) I have a word "hello!" and I need the mips prints next:

h
he
hel
hell
hello
hello!

I tried this:

.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

but it prints me all the string and i need only one letter or two.

thanks for help


OK, so you have a syscall to print a zero-terminated string. What you're going to have to then is either

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

or

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

Hopefully you know enough to code one of these up as assembler. You could also implement the first one by swapping the newline in and out of the string as well as the zero.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜