0

I am new to assembly and don't understand it fully yet. I have come across a program which prints out "Hello World!". The line of code where this string is defined looks like this:

message db 10, 'Hello World!', 10, 0

I would really appreciate if someone could explain what all these numbers mean. I suppose that 0 represents the end of the string, but I am not sure what these two 10s are for. Thanks

ivana14
  • 107
  • 8
  • 2
    On Linux the value `10` is the ASCII code for Line Feed which acts like the [New Line character](https://en.wikipedia.org/wiki/Newline). This code when printed out presumably would print a NewLine character followed by `Hello World!` followed by another New Line character. The `0` on the end is the Nul terminator character. In _C_ for example strings are Nul terminated and some routines are designed to detect the end of the string with this character. – Michael Petch Nov 24 '17 at 17:20
  • thanks for clearing that up :) – ivana14 Nov 24 '17 at 17:23
  • 1
    *"0 represents end of the string"* - the code may treat this memory content like that, but in principle this line defines 15 byte values. There are no "strings", nor "end of strings" for the machine itself, it's just series of bytes: 10, 72, 101, 108, 108, ... ..., 10, 0. It's the remaining machine code, executed by user, which gives this part of memory content the logical meaning of being a "string". (if you wonder I'm trying to emphasise this bare metal point of view... it becomes handy once you will start to think, how to concatenate two strings, or how to modify one, etc..) – Ped7g Nov 24 '17 at 18:46
  • Semi-related: [NASM Hello World using only 32-bit x86 Linux system calls](https://stackoverflow.com/questions/39550402/what-parts-of-this-helloworld-assembly-code-are-essential-if-i-were-to-write-the), with *lots* of comments and text description of how it works. I used an explicit-length string for `sys_write` instead of an implicit-length (terminated by a `'\0'`) string, though. – Peter Cordes Nov 25 '17 at 01:33

0 Answers0