.asciiz和.ascii有什么区别 [英] Whats the difference between .asciiz vs .ascii

查看:1172
本文介绍了.asciiz和.ascii有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到.asciiz null会终止字符串(附加\n?)...但是,当查看QtSPIM的用户数据段时,

I read that .asciiz null terminates the string (appending \n?) ... but when looking 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

输出" Hello WorldHello World "

更新

含义是什么?何时使用它们? asciiz听起来像是正确"的方法?

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

推荐答案

由@osgx编写的ASCIIZ表示字符串以\0(ASCII代码0)NUL字符终止.它们甚至被称为 C字符串.要从那里引用:

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:

在计算中,C字符串是以.结尾的字符序列. 空字符("\ 0",在ASCII中称为NUL).通常存储为 一维字符数组.[可疑–讨论]名称是指 使用此字符串表示形式的C编程语言. 备用名称为ASCIIZ(请注意,C字符串并不暗示使用 ASCII码)和以null结尾的字符串.

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.

这篇关于.asciiz和.ascii有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆