Reputation: 450
I have a character array initialized as follows
int main()
{
char ptr1[] = "testit";
}
has an assembly equivalent
main:
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-7], 1953719668 ; These lines form the string "testit"
mov WORD PTR [rbp-3], 29801 ; These lines form the string "testit"
mov BYTE PTR [rbp-1], 0 ; These lines form the string "testit"
mov eax, 0
pop rbp
ret
I would like to know how the the character array is stored? What are these numbers(in assembly 1953719668 , 29801, 0
) referencing to (or how these numbers are calculated) ?
Upvotes: 1
Views: 61
Reputation: 26656
The first number, 1953719668, is also 0x74736574 converted to hex.
Written as separate bytes, in little endian ordering, we have 0x74, 0x65, 0x73, 0x74.
Using ascii we have t, e, s, t.
The 2nd number encodes "it" similarly but in only 16 bits for the 2 characters: 29801 = 0x7469, converted to hex, and to bytes little endian: 0x69, 0x74: i, t.
The last byte is the null terminating byte used by C strings.
Upvotes: 2