-1

If db stands for Define Byte and can hold 8 bits (1 byte), why can we use a 6 bytes string with db? I know that one character is only 1 byte, and db holds 1 byte.

section .data
    text db "Yellow"

db is playing like a char in more high level languages (compared to asm), which we can just increase the buffer, but assembly does it automatically?

#include <stdio.h>

int main(void)
{
    char c = 'Y';
    char string[7] = "Yellow";
    return 42;
}

1 Answers1

4

The data definitions db, dw, dd, dq etc. accept more than one value, they are stored successively. For example

db 'Y', 'e', 'l', 'l', 'o', 'w', 0

is assembled as

59 65 6C 6C 6F 77 00

Since it is cumbersome to specify all characters individually, there is the notation as a string, both are equivalent:

db "Yellow", 0

Please note that the terminating zero byte must be specified separately in assembly (in contrast to C).

fcdt
  • 2,371
  • 5
  • 14
  • 26