What does .string do in assembly?
In an inline asm call in c, I wrote
.string \"Hello World\"
1) Can somebody give me an overview of how .string works?
2) Somehow that value gets saved in %esi. Why?
3) How can I append a return carriage on the end? \n doesn't work
.string
is an assembler directive in GAS similar to .long
, .int
, or .byte
. All it does is create and initialize memory for you to use in your program. The .string
directive will automatically null-terminate the string with [\0]
for you. In this case, the assembler is allocating space for 14 characters in 14 contiguous bytes of memory. If you were to look at the memory, you would see this:
["][H][e][l][l][o][ ][W][o][r][l][d]["][\0]
Except in hexadecimal rather than characters. I'm not sure how or why %esi
points to the string (it's either an assembler setting I'm not familiar with or has been set that way on a line of code you're not showing us). What it means is that %esi
"points" to the first byte of the string - in this case the first ["]
. You can use the %esi
register to loop through the bytes using an offset (%esi + 5
would be [o]
) or by incrementing the register itself.
To add a newline you might want to try \x0D\x0A
instead of \n
.
.ascii
, though).If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With