math - MIPS Mars4.5 保存算术项中的第一个数字
问题描述
您好,我的 MIPS 代码有问题。我正在尝试保存算术术语的第一个数字以供以后使用,但它不知何故不起作用。我是 MIPS 的新手,但对它还不是很熟悉。我有函数 main: 接受用户输入并调用 handle_one_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_cursor和get_current_char(返回光标现在指向的字符$v0:当前字符)
handle_one_line 看起来像这样,它应该做的就是给我这个术语的第一个数字。is_num 检查 char 是否为数字, 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
它应该给出 $s1 但当我输入我的输入时它实际上什么都不做
解决方案
推荐阅读
- android - 当设备重新启动并强制关闭应用程序时,Redmi 和其他自定义中文 ROM 中未收到 WorkManager doWork 回调
- python - 如何忽略熊猫断言帧相等的索引比较
- angular - 使用延迟加载以角度获取路由参数
- sql - 如何通过文本列将 JSONB 列与数组连接?
- angular - 在过渡时禁用 mat-stepper 的动画
- scala - 具有可变伙伴的不可变 POD 类
- c# - 在 FormattableString 和 (str, params object[]) 之间转换
- java - RxJava2:迭代项目并获取匹配条件的项目
- java - AerospikeException - 错误代码 1500:在 lmap.put() 的命名空间上未启用 LDT,即使 ldt-enabled 设置为 true
- sql - 加入显示空值