0

I am trying to get a basic feel for assembly and am working through some tutorials. The following code is an excerpt of one of the tutorials.

.
.
.
section  .data
msg1 db 'Hello, programmers!',0xA,0xD   
len1 equ $ - msg1

As I understand it, the directive db tells the assembler to reserve 1 byte of memory but 'Hello, programmers!' is certainly longer than 1 byte. Also, I do not know what 0xA,0xD are supposed to accomplish. Moreover, len1 is supposed to hold the length of the string, I want to know what the expression $-msg1 specifically $ is. Thanks!

  • 3
    `db` reserves one byte each for the given initializers. `0xA,0xD` is ascii code for line feed and carriage return (aka end of line) although it is normally reverse order. `$` is current position. Consult nasm manual about directives and special symbols. – Jester Jan 20 '21 at 13:35
  • 1
    `db` allows [defining strings](https://www.nasm.us/xdoc/2.15.05/html/nasmdoc3.html#section-3.2.1). U+000D is Carriage Return, U+000A is Line Feed, usually CR then LF is used to do a linebreak. ["$ evaluates to the assembly position at the beginning of the line containing the expression;"](https://www.nasm.us/xdoc/2.15.05/html/nasmdoc3.html#section-3.5) – ecm Jan 20 '21 at 13:39
  • hey jester, can you take a look at my other question? Thanks! – peterparker Jan 20 '21 at 13:50
  • 2
    This is like 3 questions in one, but I was able to find 3 separate duplicates, one for each part (ASCII codes for line endings, multi-byte `db`, and how `$` works.) – Peter Cordes Jan 20 '21 at 18:02

0 Answers0