mips help

Discussion in 'OT Technology' started by notwist, Jan 27, 2007.

  1. notwist

    notwist Active Member

    Joined:
    Nov 8, 2004
    Messages:
    5,738
    Likes Received:
    0
    I'm trying to write a program that will have the user enter in an expression in the form: A (operation) B (operation) C and print out the result. After the user enters in the expression, I want to parse out each of the 3 integers and the 2 operations by reading the 2 digit ASCII code of each individual character and storing each digit or operation in its own register. I'm having trouble reading each seperate character after the user enters the expression.

    li $v0, 8
    la $a0, expr
    li $a1, 20
    syscall

    How do I store each character? Something like the code below? (I know the code below will not work.) Am i supposed to store the string in a new register before reading each seperate byte? :dunno:

    sb 0(expr), $t0



    Also, since i'm only working with numbers between 20 and 99, and the operations + and *, is it ok to reserve only 5 bytes for the entire expression since 1 byte can represent one ASCII character?
     
  2. Darketernal

    Darketernal Watch: Aria The Origination =)

    Joined:
    Oct 8, 2002
    Messages:
    10,498
    Likes Received:
    3
    Location:
    Care,for all is like a bonsai tree
    http://sandbox.mc.edu/~bennet/cs314/examples/echo_s.html strange i found a sight that sorta seems to do what your doing , im not familiar with mips tho.

    In Borland builder i would use a character box and a integer box and then save them both to a notepad, so i could recall the values from the text.
     
  3. TheDarkHorizon

    TheDarkHorizon \xC0\xFF\xEE

    Joined:
    Sep 26, 2002
    Messages:
    2,396
    Likes Received:
    0
    Location:
    San Francisco, CA
    Don't forget to leave room for the null terminator. You have the address of your buffer in $a0 already, so you can use lb (load byte) to read each character.
     
  4. notwist

    notwist Active Member

    Joined:
    Nov 8, 2004
    Messages:
    5,738
    Likes Received:
    0
    Hmm, I look into it once I sit down to work on it tomorrow. I was thinking, since 1 byte represents 1 ASCII char and 8 bits make up 1 byte.. I would have to load each char by an offset of 8?
     
  5. TheDarkHorizon

    TheDarkHorizon \xC0\xFF\xEE

    Joined:
    Sep 26, 2002
    Messages:
    2,396
    Likes Received:
    0
    Location:
    San Francisco, CA
    It's byte addressable, not bit addressable.
     
  6. notwist

    notwist Active Member

    Joined:
    Nov 8, 2004
    Messages:
    5,738
    Likes Received:
    0
    Ok, so after the user inputs a string, it's saved in $a0.

    Can i store a single char from that string into a seperate register? Something like:
    lb 2($a0), $s3

    Btw, I'm not at my computer so I can't try that.
     

Share This Page