Math MIPS Mars4.5在算术术语中保存第一个数字

Math MIPS Mars4.5在算术术语中保存第一个数字,math,mips,mars-simulator,Math,Mips,Mars Simulator,您好,我的MIPS代码有问题。我试图保存算术术语的第一个数字,以备以后使用,但不知何故,它不起作用。我是MIPS的新手,对它还不是很熟悉。我有一个函数main:它接受用户输入并调用handle\u one\u line:这是我目前正在使用的函数。梅因:看起来像这样 main: m_loop: # Load address of line buffer and read new user input into it. la $a0, line_buffer li $a1, 8192 li

您好,我的MIPS代码有问题。我试图保存算术术语的第一个数字,以备以后使用,但不知何故,它不起作用。我是MIPS的新手,对它还不是很熟悉。我有一个函数main:它接受用户输入并调用handle\u one\u line:这是我目前正在使用的函数。梅因:看起来像这样

    main:
m_loop:
# Load address of line buffer and read new user input into it.
la $a0, line_buffer
li $a1, 8192
li $v0, 8 # read string
syscall

# Reset the cursor so that it points at the first character in line buffer.
la $t0, cursor_pos
li $t1, 0
sw $t1, 0($t0)

jal handle_one_line

# Repeat.
j m_loop
我还有一些其他的基本函数,比如advance\u cursor和get\u current\u char(返回光标现在指向的字符$v0:current character)

一条线看起来像这样,它要做的就是给我这个学期的第一个数字。is_num检查字符是否为数字,read_num应给出数字

handle_one_line:
# Save return address because we are calling other functions.
addi $sp, $sp, -4
sw $ra,  0($sp)


is_num:

    jal get_current_char    #returns the current char in $v0
    li $t0, '0'     #stores the ascii value of '0' in $t0
    bltu $v0, $t0, notdigit #If current char Ascii value<'0'->notdigit
    li $t0, '9'     #stores the ascii value of '9' in $t0
    bltu $t0, $v0, notdigit #If value of '9'<current char value->notdigit
    li $v0,1        #$v0 = 1

        notdigit:
        li $v0,0    #$v0 = 0



read_num: 
    jal is_num      #check if current cursor position char is a digit       
    beq $v0, $zero, Zeichen #If its not a digit quit and go to Zeichen
    jal get_current_char    #returns the current char in $v0
    lb $t0, ($v0)       #load the current char into $t0
    la $s1, link_chars  #set $s1 to the buffer
    sb $t0, ($s1)       #store current character in the buffer
    addi $s1, $s1, 1    #link_chars pointer points a position forward
    jal advance_cursor
    j read_num
Zeichen:
    li $v0, 4
    la $a0, ($s1)
    syscall
handle\u一行:
#保存返回地址,因为我们正在调用其他函数。
附加$sp,$sp,-4
西南$ra,0($sp)
是_num:
jal get_current_char#返回当前字符,单位为$v0
li$t0,“0”将“0”的ascii值存储在$t0中
bltu$v0,$t0,notdigit#如果当前字符Ascii值notdigit
li$t0,“9”将“9”的ascii值存储在$t0中
bltu$t0,$v0,非数字#如果'9'的值不是数字
li$v0,1#$v0=1
notdigit:
li$v0,0#$v0=0
阅读编号:
jal为_num#检查当前光标位置字符是否为数字
beq$v0,$0,Zeichen#如果不是数字,请退出并前往Zeichen
jal get_current_char#返回当前字符,单位为$v0
lb$t0,($v0)#将当前字符加载到$t0中
la$s1,link#u chars#将$s1设置到缓冲区
sb$t0,($s1)#将当前字符存储在缓冲区中
addi$s1,$s1,1#link_chars指针指向前方位置
日航前进号
j读数值
泽城:
李$v0,4
la$a0,($s1)
系统调用

它应该给出$s1,但当我输入输入时,它实际上什么也不做

出现了几个问题。。1)
handle\u one\u行
通过按下当前返回地址开始,但相应的pop在哪里?2)
is_num
read_num
都是
一行处理的一部分,还是它们是独立的功能?3) 如果它们是
handle\u one\u line
的一部分,为什么
read\u num
使用
jal
跳转到
is\u num
?4) 如果
jal
是正确的,为什么
is_num
中没有
jr$ra
?5) 为什么
is_num
发生在
read_num
之前,因此在到达
read_num
之前总是会执行
is_num
部分?6) 为什么在
is__num
部分中的
li$v0,0
后面直接有一个
li$v0,0
?我建议您利用MARS中的调试功能逐步检查代码,并在运行时检查其行为。