Assembly MIPS32汇编语言基本存储和打印服务

Assembly MIPS32汇编语言基本存储和打印服务,assembly,mips32,Assembly,Mips32,我试图提示用户输入字符串、整数和字符,然后用标签将它们显示回屏幕 我让字符串正常工作,但字符和整数结果给了我垃圾。这是我的第一个汇编语言程序,我不知道为什么当我将结果保存到$t寄存器时,当我去检索它们时,会得到垃圾 任何帮助都将不胜感激 .data stringPrompt: .asciiz "Enter a string up to 25 characters: " intPrompt: .asciiz "Enter an integer: " charPromp

我试图提示用户输入字符串、整数和字符,然后用标签将它们显示回屏幕

我让字符串正常工作,但字符和整数结果给了我垃圾。这是我的第一个汇编语言程序,我不知道为什么当我将结果保存到$t寄存器时,当我去检索它们时,会得到垃圾

任何帮助都将不胜感激

        .data
stringPrompt:   .asciiz "Enter a string up to 25 characters: "
intPrompt:      .asciiz "Enter an integer: "
charPrompt:     .asciiz "Enter a character: "

theString:      .space 26           # max of 25, +1 for '\0'
                .align 2
theInt:         .space 4
theChar:        .space 1

stringMsg:      .asciiz "\n\nThe string is: "
intMsg:         .asciiz "The integer is: "
charMsg:        .asciiz "\nThe character is: "

        .text
        .globl main

main:
        li $v0, 4
        la $a0, stringPrompt
        syscall         
        li $v0, 8               # read string service
        la $a0, theString       # address of buffer for string
        li $a1, 26              # read up to 25 & append '\0'
        syscall

        li $v0, 4
        la $a0, intPrompt
        syscall         
        li $v0, 5           # read int service
        syscall             # $v0 has integer entered after call
        move $t0, $v0           # copy (save) integer to $t1


        li $v0, 4
        la $a0, charPrompt
        syscall         
        li $v0, 12          # read char service
        syscall             # $v0 has char (gen) entered after call

        move $t3, $v0           # copy (save) char to $t3
        la $t9, theChar
        sb $v0, 0($t5)          # save gen to mem (@ gen_charInMem)


        ###output all data with labels####

        li $v0, 4
        la $a0, stringMsg
        syscall

        li $v0, 4
        la $a0, theString
        syscall


        li $v0, 4
        la $a0, intMsg
        syscall

        move $a0, $t1
        li $v0, 1
        la $a0, theInt
        syscall


        li $v0, 4
        la $a0, charMsg
        syscall

        move $a0, $t5
        li $v0, 11
        la $a0, theChar
        syscall


        li $v0, 10          # graceful exit service
        syscall
#################################################

你似乎误解了工作原理。他们希望值以$a0的形式输出,而不是存储值的地址

因此:

    move $a0, $t1
    li $v0, 1
    la $a0, theInt
    syscall
应该是:

    move $a0, $t0   # $t0 is where you saved the integer earlier
    li $v0, 1
    syscall
    move $a0, $t3   # $t3 is where you saved the character earlier
    li $v0, 11
    syscall
这是:

    move $a0, $t5
    li $v0, 11
    la $a0, theChar
    syscall
应该是:

    move $a0, $t0   # $t0 is where you saved the integer earlier
    li $v0, 1
    syscall
    move $a0, $t3   # $t3 is where you saved the character earlier
    li $v0, 11
    syscall
除此之外,还应将其移除:

    la $t9, theChar
    sb $v0, 0($t5)          # save gen to mem (@ gen_charInMem)
如果出于某种原因,您仍然希望将角色保存在CHAR中,则至少应将第一行更改为la$t5,即CHAR