Home > Software engineering >  Does assembly code include the labels, or are labels just syntax decoration?
Does assembly code include the labels, or are labels just syntax decoration?

Time:11-04

Are labels that are usually put before x86 instructions, such as

0x09: mov eax, 1001

(a line I made up) a part of the assembly code?

On the one hand, I feel that assembly instructions such as jmp would make no sense without labels; on the other hand, online assembling sites such as https://defuse.ca/online-x86-assembler.htm, does not seem to recognise labels as a part of the assembly code. Reason why I have this question.

[edit] By assembly code, I mean the lowest-level human readable code that is closest to 0-1 machine code. By assemble, or assembling, I mean the process of translating assembly code into 0-1 machine code.

By labels, I actually meant for the addresses.

CodePudding user response:

There's a subtle difference between assembly language and machine code, but the two are often used interchangeably. Assembly language is what you're writing in your text editor. Machine code is what gets run by the machine itself. The assembly language source code is assembled into machine language, much like C code is compiled into machine code.

Labels are just for your convenience, they get automatically converted into memory addresses by the assembler. Otherwise, every time you write more code you'd have to adjust all of your jumps!

CodePudding user response:

The labels and other non-instructions are very much part of the language and they are the primary places that makes assembly languages incompatible for the same target. How comments are defined, how labels are defined rules for labels, other directives. Macro syntax, etc. All part of the language. If it were not then the assembler would not fail to parse/assemble the code.

It is like asking if function names or function prototypes, typedefs, defines, etc are part of the C language.

  • Related