Mips:asciiz 与 ascii,打印许多变量

问题描述 投票:0回答:1

我知道 (asciiz) 字符串以 ' ' 结尾,而 (ascii) 则不是。 但我还是很困惑。在这段代码中,为什么会打印:

‘一二三三四五五’

而不是简单地按照与打印命令相同的顺序打印它们?

.data
str1: .asciiz"One"    
str2: .ascii " Two"
str3: .asciiz" Three"  
str4: .ascii " Four" 
str5: .ascii" Five" 
.text

main:
la $a0,str1
li $v0,4
syscall

#---------------------------
la $a0,str2
li $v0,4
syscall
#---------------------------
la $a0,str3
li $v0,4
syscall
#---------------------------
la $a0,str4
li $v0,4
syscall
#---------------------------
la $a0,str5
li $v0,4
syscall
#---------------------------
#End
li $v0, 10
syscall
.end main
mips
1个回答
3
投票

NUL 终止符 (

'\0'
) 对于
print_string
系统调用来说是必需的,以了解字符串的结束位置。系统调用将继续打印字符,直到到达 NUL 终止符。

打印

str1
打印
One

打印

str2
会打印
Two Three
,因为
str2
不是以 NUL 结尾。

打印

str3
打印
Three

打印

str4
会打印
Four Five
,因为
str4
不是以 NUL 结尾。

打印

str5
打印
Five

将所有这些放在一起,您将得到

One Two Three Three Four Five Five

© www.soinside.com 2019 - 2024. All rights reserved.