ASM program questions

Discussion in 'OT Technology' started by BoypussY, Mar 23, 2004.

  1. BoypussY

    BoypussY game over.

    Joined:
    Jun 27, 2000
    Messages:
    51,953
    Likes Received:
    0
    Location:
    IN YOUR HEAD
    Hi,

    I have to write a program (ASM - mips) that takes in a character string from the user and then counts the occurance of each character and stores it in an array. my question is, how do i go about storing these characters in an array. do i create an array of 128 bytes and store them in this array according to their ascii numbers?(for example array[65]=A). also, what is the best way to convert from ascii characters to real characters and vice-versa.

    this is a sample output:
    -> I regret that I have but one program to write.
    : 9
    .: 1
    I: 2
    a: 3
    b: 1
    e: 5
    g: 2
    h: 2
    i: 1
    m: 1
    n: 1
    o: 3
    p: 1
    r: 5
    t: 6
    u: 1
    v: 1
    w: 1
    "Notes:

    You will need a character array for user input. It should be at least 80 bytes long.

    When displaying the counts you can skip positions 0 through 31 in the count array since these correspond to ASCII codes for non-printing characters.

    When you read or write to the count array remember that you are reading or writing bytes not words. "





    Thanks in advance.
     
  2. BoypussY

    BoypussY game over.

    Joined:
    Jun 27, 2000
    Messages:
    51,953
    Likes Received:
    0
    Location:
    IN YOUR HEAD
    anyone? btw can someone show me a way to use procedures in assembly. especially using the jal(jump and link) and jr $ra(jump to return address) instructions.
     
  3. uneek

    uneek OT Supporter

    Joined:
    Dec 14, 2003
    Messages:
    12,002
    Likes Received:
    0
    What I would do is create the array and then the ascii value of the character.. i.e. if you get a 'c' then get the ascii value (dont know it off the top of my head) and increment that element in the array.

    inc byte ptr [array + ascii_c]

    I'm not really an asm programmer I just have toyed with it so I'm sure there's probably some trick or something more elegant than this :p

    plus I'm not familiar with mips so...
     
  4. EkriirkE

    EkriirkE Zika Xenu OT Supporter

    Joined:
    Jan 11, 2004
    Messages:
    14,799
    Likes Received:
    0
    Location:
    Dublin & San Francisco, CA
    set aside 128 bytes, zero it all out
    read the input byte-by-byte, increment the value in [base of array + ascii value] for each character read.

    You seem a bit confused on what a character/ascii value is. When storing an "A" in memory, the byte holding it has a value of 65. 65 is the ASCII value of the capital "A". There is no conversion going on. When you see "A", you are just seeing a graphical representation of 65.
     

Share This Page