6

When determining the size of .asciiz string, should I take into consideration the terminating character ?

For example:

.data
string: .asciiz "Hello"

The size of "string" is 5 or 6 (byte) ?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
wonderingdev
  • 1,132
  • 15
  • 28
  • 3
    The size of the data includes the NULL byte at the end of the string, so it consumes 6 bytes. However, the length of the ASCIIZ string is 5 characters. I guess you want to know the space used, that would be 6 bytes. – gusbro Jun 30 '16 at 15:54
  • 1
    @gusbro So it's 6 bytes. Thank you. – wonderingdev Jun 30 '16 at 16:05

4 Answers4

4

if you are asking about how many bytes in memory the string is stored in then it's 6 bytes

if you are asking about what should be returned by a function that count the string length (strlen C function for example) it should be 5

Robert
  • 2,342
  • 2
  • 24
  • 41
1

This particular asciiz string requires 6 bytes of storage.

In programming situations, you will measure the string size to be 5. As in strlen().

When using this string, very likely, your loop will be testing for NULL conditions, and will run for 5 iterations.

When copying, storing this string, your code will likely loop 5 times, and then (outside of loop), add an extra NULL '\0' character at the end, to maintain NULL termination. Therefore the destination storage space must be 1 more than strlen().

Paxym
  • 76
  • 5
1

Agree with Robert, in this case the bytes in memory total 6. As Paxym explains however, in high-level languages it will measure the string 'size' to be 5.

-1

Every character of ascii is 1 byte. if you write hello it is 5 byte

Alim Öncül
  • 127
  • 2
  • 14