MASM - 如何输入一行ascii代码来输出字​​符串

时间:2018-03-20 04:41:40

标签: string assembly ascii masm data-conversion

任何人都知道如何在MASM中转换它?我在将数据段中的字符串与空终止符一起存储时遇到问题。我做了一个与此类似的项目,反之亦然。输入一个字符串以输出相应的ASCII值。现在我试图输入整数来获得相应的字符串值。

.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

0 个答案:

没有答案