tags:

views:

64

answers:

1

Hello, please help me to write program 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

+1  A: 

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.

Rup
i tried this also, i advance $s0 by 1, so mips prints me "ello!" without "h", if i advance one more time it's "llo!" and so on. and i need it prints me first of all "h" and then "he", and then "hel", "hello", "hello!". can you show me the code too?
Sergey
I don't really know MIPS but the protocol around here is that we don't post code solutions to homework questions (or questions we suspect are homework). No, you you need to do more than that: you'll need to either edit the string in place or copy the shortened form to a new buffer as I've described - e.g. have another register (s1?) equal to s0 + 1, read a byte from there, write 0 to that byte, syscall, write the byte back, increment s1 and loop - until the byte you read out is 0, then stop.
Rup
thank you for your answer.but if there somebody who knows a little mips, please give me a clue. which code or instruction operation i need to use in order to load one letter from the string e.g. "hello". i need to put the letter "h" to register $s0. the code i already tried is above the comments.
Sergey