user3922145
user3922145

Reputation: 39

Assembly data types and storage space

How is it possible to store multiple characters of word in a Byte data type? I mean if the size of a variable declared as a Byte have the storage space of 1 Byte then how is it possible to assign more than 1 Byte? Look below:

     section .data
msg  db 'hello world'   ;here msg is defined to be byte but holds 11 char's 

If I am misunderstanding, Please help?

Upvotes: 0

Views: 562

Answers (1)

Ira Baxter
Ira Baxter

Reputation: 95344

The DB psuedo op really should be read as, "Define Byte(s)".

It accepts a series of expressions, and string literals. For each expression, it assigns one byte of memory, filled with the value of that expression as computed at assembly time. String literals are treated as a series of bytes, and each character of the string literal is assigned one byte of memory. So:

LABEL DB 17, "ABC", 2

fills in memory bytes, in order:

  0x11
  0x41
  0x42
  0x43
  0x02

The label on the DB command gets an assembly time value of the location of the first byte filled by the DB.

Other pseudo ops, like DW ("Define Word(s)"), DD ("Define DoubleWord(s)"), and DQ ("Define Quadword(s)"), spelling may depend on your assembler, accepts series of expressions, and fills "word" (2 bytes/16 bits), "doublewords (4 bytes/32 bits) and "quadwords" (8 bytes/64 bit) value in the assembled output. These ops typically do not accept strings (e.g., a quadword series of memory locations containing individual characters simply isn't used very much).

Upvotes: 3

Related Questions