开发者

Whats the difference between .asciiz vs .ascii

I read that .asciiz null terminates the string (appending \n?) ... but when lookin开发者_开发知识库g at the User Data Segment of QtSPIM,

User data segment [10000000]..[10040000]
[10000000]..[1000ffff]  00000000
[10010000]    6c6c6548  6f57206f  00646c72  6c6c6548    H e l l o   W o r l d . H e l l 
[10010010]    6f57206f  00646c72  00000000  00000000    o   W o r l d . . . . . . . . . 
[10010020]..[1003ffff]  00000000

I don't see a difference?

.data
  str1: .asciiz "Hello World" # string str1 = "Hello World"
  str2: .ascii "Hello World" # string str2 = "Hello World"

.text
  .globl main
    main: 
      li $v0, 4 # print_string

      # print(str1)
      la $a0, str1 # load address of str1 into $a0
      syscall

      # print(str2)
      la $a0, str2 # load address of str2 into $a0
      syscall

      j $ra

Outputs "Hello WorldHello World"

UPDATE

What are the implications or when do I use each? asciiz sounds like the "proper" method?


As written by @osgx, ASCIIZ means that the string is terminated by the \0 (ASCII code 0) NUL character. They are even called C strings. To quote from there:

In computing, a C string is a character sequence terminated with a null character ('\0', called NUL in ASCII). It is usually stored as one-dimensional character array.[dubious – discuss] The name refers to the C programming language which uses this string representation. Alternative names are ASCIIZ (note that C strings do not imply the use of ASCII) and null-terminated string.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜