• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7796
  • Last Modified:

Reading a string in MIPS assembly language

I am very new to writing in assembly.
My question is, if there is are bunch of characters entered in by the user, and I only want to access one character at a time, would the following code work for me? (The effect I hope to acheive would be similar to getchar() in C)

-----------
abcdefg
-----------

#code to read each letter, one at a time
buffer:     .space    1
...


      la  $a0, buffer
      li   $a1, 1
      li   $v0, 8
      syscall

So the first time I use this code, "a" will be read, and next "b", and so forth. I am assigning a high value because this solution is needed very soon.  
0
Kevin_P23
Asked:
Kevin_P23
1 Solution
 
dimitryCommented:
Seems, no...
And it is not the assembler problem but syscall for read string implementation.
http://www.doc.ic.ac.uk/lab/secondyear/spim/node8.html
Also pay attention that read string will put 0 at the end, so you need at least:
 buffer: .space 2

Aslo you can get the whole line: abcdef and then you can process one character at a time.

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now