Answer the question
In order to leave comments, you need to log in
Why are these lines written to memory differently?
Good afternoon!
In an attempt to figure out why I can successfully send and receive requests to a web server in C language and why I cannot do the same in assembly language, I noticed this feature:
request db "GET / HTTP/1.1\r\nHost: myip.ru\r\n\r\n"
char* c = "GET / HTTP/1.1\r\nHost: myip.ru\r\n\r\n";
47 45 54 20 2f 20 48 54 54 50 2f 31 2e 31 5c 72 5c 6e 48 6f 73 74 3a 20
6d 79 69 70 2e 72 75 5c 72 5c 6e 5c 72 5c 6e
47 45 54 20 2f 20 48 54 54 50 2f 31 2e 31 0d 0a 48 6f 73 74 3a 20 6d 79
69 70 2e 72 75 0d 0a 0d 0a
GET / HTTP/1.1\r\nHost: myip.ru\r\n\r\n
GET / HTTP/1.1
Host: myip.ru
Answer the question
In order to leave comments, you need to log in
Because in C, this sequence "\r" is an escape sequence and it is written to memory as 0xd (one byte). The compiler does this work.
And in the assembler, as you wrote down the line, so it lies in memory, i.e. there the character "\" lies as 0x5c, and the character "r" also lies next to it. But for an HTTP request, it is a line feed (sequence 0xd, 0xa) that is needed, and not the text "\r".
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question