Author Topic: How is it possible for db to contain a string of characters?  (Read 3601 times)

Offline georgelappies

  • Jr. Member
  • *
  • Posts: 12
How is it possible for db to contain a string of characters?
« 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?

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2547
  • Country: us
Re: How is it possible for db to contain a string of characters?
« Reply #1 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



 

SMF spam blocked by CleanTalk