0

Anyone knows how to convert this in MASM? I'm having trouble storing string in data segments along with null terminator. I did a project similar to this, but vice-versa. Inputting a string to ouput the corresponding ASCII values. Now I'm trying to inputting integers to get the corresponding string values.

.data           #data Segment

stringMsg: .asciiz "Enter 4 integers that are between 65-90, inclusive: "
                #Stores string in data segment + null terminator

alphaTable: .byte 'A', 0, 'B', 0, 'C', 0, 'D', 0, 'E', 0, 'F', 0, 'G', 0, 'H', 0, 'I', 0, 'J', 0, 'K', 0, 'L', 0, 'M', 0, 'N', 0, 'O', 0, 'P', 0, 'Q', 0, 'R', 0, 'S', 0, 'T', 0, 'U', 0, 'V', 0, 'W', 0, 'X', 0, 'Y', 0, 'Z', 0

    .text

string: 

    li $v0, 4           #Syscall #4 prints string
    la $a0, stringMsg   #Loads address of string "inputMsg"
    syscall             #Prints inputMsg    

    li $v0, 5           #Syscall #5 reads integer
    syscall             #reads inputted val into $v0
    la $s0, $v0       #save first number into s0

    li $v0, 5           #Syscall #5 reads integer
    syscall             #reads inputted val into $v0
    la $s1, $v0       #save second number into s1

    li $v0, 5           #Syscall #5 reads integer
    syscall             #reads inputted val into $v0
    la $s2, $v0      #save third number into s2

    li $v0, 5           #Syscall #5 reads integer
    syscall             #reads inputted val into $v0
    la $s3, $v0       #save fourth number into s3

    sub $s0, $s0, 65    #Subtract 65 from the 4 # to get correlating value in array
    sub $s1, $s1, 65
    sub $s2, $s2, 65
    sub $s3, $s3, 65

    la $s4, alphaTable  #Loads table into $s4   (used to get index val)
    la $s5, alphaTable  #Loads table into $s5   (used to reset index val)


    add $s5, $s5, $s0
    li $v0, 4           #Syscall #4 prints string
    lb $a0, $s5       #Loads address of string "inputMsg"
    syscall             #Prints inputMsg
    la $s5, $s4

    add $s5, $s5, $s1
    li $v0, 4           #Syscall #4 prints string
    lb $a0, $s5       #Loads address of string "inputMsg"
    syscall             #Prints inputMsg
    la $s5, $s4

    add $s5, $s5, $s2
    li $v0, 4           #Syscall #4 prints string
    lb $a0,$s5      #Loads address of string "inputMsg"
    syscall             #Prints inputMsg
    la $s5, $s4

    add $s5, $s5, $s3
    li $v0, 4           #Syscall #4 prints string
    lb $a0, $s5       #Loads address of string "inputMsg"
    syscall             #Prints inputMsg


exit:
    li $v0, 10          #syscall #10: exit
    syscall             #ends program
CHARot
  • 9
  • 1
  • Convert to what? – wallyk Mar 20 '18 at 05:27
  • I wanted to convert this program to masm syntax. So it could input a line of ascii codes separated by comma and output the corresponding strings – CHARot Mar 20 '18 at 05:32
  • It's not just syntax, you'd need to port it to x86 (32 or 64-bit), and to Windows system calls instead of MIPS-simulator system calls. Windows doesn't have a system call for reading a formatted integer, so you'll want to use a C library function like `scanf` instead. You are talking about MASM, Microsoft's Macro Assembler for x86 on Windows, right? Because your code is for MARS or SPIM (MIPS simulators). – Peter Cordes Mar 20 '18 at 07:36
  • 1
    This is barely valid MIPS syntax. `lb` normally requires `()` around the address, like `lb $a0, ($s5)` (and the comment is wrong: that loads 1 byte, not an address of a string). And `la` takes a label, not a register. I think most MIPS assemblers would reject `la $s5, $s4`. To copy a register, use `move $s5, $s4`. Or don't copy a register at all, and use `add $s5, $s4, $s3` to put the destination in a new register without destroying either input, unlike x86. – Peter Cordes Mar 20 '18 at 09:18
  • Also, the whole program seems ridiculous. You don't need a lookup table to map integers to ASCII codes; the ASCII codes for A-Z are already contiguous. Other than the alternating `0` bytes, it seems like your program does `c-65` then uses a lookup table to map that back to `c`. – Peter Cordes Mar 20 '18 at 09:21

0 Answers0