Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly 读取小写字母数的MIPS代码_Assembly_Mips_Mars Simulator - Fatal编程技术网

Assembly 读取小写字母数的MIPS代码

Assembly 读取小写字母数的MIPS代码,assembly,mips,mars-simulator,Assembly,Mips,Mars Simulator,我需要编写一个程序,从用户那里读取字符串并输出字符串中的小写字母数。这是我写的 .data msg1 : .word 0:24 .text .globl main main : addu $s0 , $0 , $ra #save the return address li $v0 , 8 #syscall for read str la $a0 , msg1 #load address of msg1 to store string li

我需要编写一个程序,从用户那里读取字符串并输出字符串中的小写字母数。这是我写的

.data
msg1 : .word 0:24
.text
.globl main

main :
addu $s0 , $0 , $ra         #save the return address
li $v0 , 8          #syscall for read str
la $a0 , msg1           #load address of msg1 to store string
li $a1 , 100            #msg1 is 100 bytes
syscall

add $t6, $t6, $0

compare :
lb $t0 , 0($a0)         #load the character into $t0
beq $t0, $0, endloop
li $t1 , 'a'            #get value of 'a'
blt $t0 , $t1 , nomodify    #do nothing if letter is less than 'a'
li $t1 , 'z'            #get value of 'z'
bgt $t0 , $t1 , nomodify    #do nothing if letter is great than 'z'
addi $t6, $t6, 1        #add one to the character count
addi $a0, $a0, 1        #move to next character
beq $0,$0,compare       #branch to compare 

nomodify :
addi $a0, $a0, 1        #next character
j compare

endloop :
addu $a0, $0, $t6       
li $v0 , 1          #syscall for print int
syscall
addu $ra , $s0 , $0     #restore return address
jr $ra  

然而,当它运行时,它会以错误终止,我不能完全确定我做错了什么。非常感谢您的任何建议!提前谢谢

MARS/SPIM中有一个退出应用程序的
exit
syscall。因此,与其以此结束您的计划,不如:

addu $ra , $s0 , $0     #restore return address
jr $ra 
你应使用:

li $v0, 10    
syscall    # syscall 10 = exit

jr$ra
只需跳回调用
main
例程的代码即可。在火星上,这似乎是“不存在的”,即当你的
main
开始运行
$ra
时,它是0。
在SPIM中,有一些设置代码调用你的
main
,然后在你返回时执行系统调用10。因此,在SPIM中,您的代码将按原样工作。

事实上,我相信它正在工作,但它仍然表示它将以错误终止。原因可能是什么?上面写着“错误在:无效的程序计数器值:0x00000000”Pro stack提示:请不要说“以错误终止”,您应该始终将实际错误与问题一起发布。