NASM - The Netwide Assembler

NASM Forum => Programming with NASM => Topic started by: georgelappies on April 28, 2012, 08:43:16 PM

Title: How is it possible for db to contain a string of characters?
Post by: georgelappies on April 28, 2012, 08:43:16 PM
Is db not a byte only? (define byte)? How is it then possible that a statement such as
Code: [Select]
message: db 'Hello World', 0ah, 0dh, '$'
is valid in NASM. Or is the label message treated like a pointer?
Title: Re: How is it possible for db to contain a string of characters?
Post by: Frank Kotler on April 28, 2012, 09:20:18 PM
Quote
Is db not a byte only? (define byte)?

Yeah... maybe "define byte or bytes" would be more accurate. Anything enclosed in quotes is taken as a list of bytes. You could also do:
Code: [Select]
my_byte_array db 0, 1, 3, 5, 42
another "list of bytes". Using a single number that exceeds byte size...
Code: [Select]
foo db 345
is probably an error, but Nasm will assemble it (just the low byte) with just a warning.

In Nasm syntax, the unadorned variable name - "message" - is the address (an "immediate" value). Masm (AoA) would call it "offset message". In Masm syntax, just "message" refers to the contents of memory at that address - 'H', or possibly more bytes - Nasm uses "[message]" to refer to "[contents]"...
Code: [Select]
mov dx, message ; address - Masm would need "offset"
mov al, [message] ; 'H'
mov eax, [message] ; "Hell" :)

(only one of the instances of "Hell" you'll encounter) :)

Best,
Frank