Reading a string in MIPS assembly language

Posted on 2004-11-29
Last Modified: 2013-03-14
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)


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

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

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.  
Question by:Kevin_P23
    1 Comment
    LVL 11

    Accepted Solution

    Seems, no...
    And it is not the assembler problem but syscall for read string implementation.
    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.


    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
    Synchronize a new Active Directory domain with an existing Office 365 tenant
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    This video discusses moving either the default database or any database to a new volume.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now