Home > front end >  Is a .byte array the same as declaring an .asciz string literal?
Is a .byte array the same as declaring an .asciz string literal?

Time:12-23

This may seem like an odd question, but does x64 treat arrays declared as .byte segments the same as .asciz arrays? The context is that I’m reading in a string using the read system call (just to see if I can). I store this in a buffer array of type .byte. Though, if I try to print this array out to standard out via printf, it does not print anything. So, my question is, in essence, do I need to do something different in this case?

CodePudding user response:

Yes, with one exception: A .byte array doesn't put a null terminator at the end for you like .asciz does.

.asciz "Hello"

is the same as:

.byte 0x48,0x65,0x6C,0x6C,0x6F,0x00

This goes even further than that, however. For example, .word 0x1234 is treated identical to .byte 0x34,0x12 (assuming a little-endian architecture, which x86 is.) For clarity purposes it's best to declare your data with its intended type, but it's not required like it would be in C. (Some assemblers have an issue with it, but at runtime, all bets are off.)

  • Related