

Type the above code using a text editor and save it as hello.asm. Now, take the following steps for compiling and linking the above program − Make sure you have set the path of nasm and ld binaries in your PATH environment variable. When the above code is compiled and executed, it produces the following result −Ĭompiling and Linking an Assembly Program in NASM Msg db 'Hello, world!', 0xa string to be printed Global _start must be declared for linker (ld) The following assembly language code displays the string 'Hello World' on the screen − MOV AL, 10 Transfer the value 10 to the AL register MOV TOTAL, 48 Transfer the value 48 in theĪND MASK1, 128 Perform AND operation on theĪDD MARKS, 10 Add 10 to the variable MARKS INC COUNT Increment the memory variable COUNT A basic instruction has two parts, the first one is the name of the instruction (or the mnemonic), which is to be executed, and the second are the operands or the parameters of the command.įollowing are some examples of typical assembly language statements − The fields in the square brackets are optional. Each statement follows the following format − Syntax of Assembly Language StatementsĪssembly language statements are entered one statement per line. Macros are basically a text substitution mechanism. These are non-executable and do not generate machine language instructions. The assembler directives or pseudo-ops tell the assembler about the various aspects of the assembly process. Each executable instruction generates one machine language instruction.

Each instruction consists of an operation code (opcode). The executable instructions or simply instructions tell the processor what to do. Assembler directives or pseudo-ops, and.Executable instructions or instructions,.Or, on the same line along with an instruction, like −Īssembly language programs consist of three types of statements − This program displays a message on screen It can appear on a line by itself, like − It may contain any printable character including blank. The syntax for declaring text section is −Īssembly language comment begins with a semicolon ( ). This section must begin with the declaration global _start, which tells the kernel where the program execution begins. The text section is used for keeping the actual code. The syntax for declaring bss section is − The bss section is used for declaring variables. The syntax for declaring data section is − You can declare various constant values, file names, or buffer size, etc., in this section. The data section is used for declaring initialized data or constants. An assembly program can be divided into three sections −
