-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.asm
95 lines (65 loc) · 2.96 KB
/
main.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
; Basic Syntax for Assembly
; -------------------------
; An assembly program can be divided into three sections:
; The data section, the bss section, and the text section.
; The Data Section
; ----------------
; The data section is used for declaring initialized data or constants. This data does not change at
; runtime. You can declare various constant values, file names, or buffer size, in this section.
; The syntax for declaring data section is:
section.data
; The BSS Section
; ---------------
; The bss section is used for declaring variables. The syntax for declaring bss section is:
section.bss
; The Text Section
; ----------------
; The text section is used for keeping the actual code. This section must begin with the declaration
; global _start, which tells the kernel where the program execution begins.
; The syntax for declaring text section is:
section.text
global _start
_start:
; Assembly Language Statements
; ----------------------------
; Assembly language programs consist of three types of statements:
; Executable instructions or instructions, Assembler directives or pseudo-ops, and
; macros.
; The executable instructions or simply instructions tell the processor what to do. Each instruction
; consists of an operation code (opcode). Each executable instruction generates one machine
; language instruction.
; The assembler directives or pseudo-ops tell the assembler about the various aspects of the
; assembly process. These are non-executable and do not generate machine language instructions.
; Macros are basically a text substitution mechanism.
; Syntax of Assembly Language Statements
; --------------------------------------
; Assembly language statements are entered one statement per line. Each statement follows the following format:
; [label] mnemonic [operands] [;comment]
; The fields in the square brackets are optional. 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.
; Following are some examples of typical assembly language statements:
INC COUNT ; Increment the memory variable COUNT
MOV TOTAL, 48 ; Transfer the value 48 in the
; memory variable TOTAL
ADD AH, BH ; Add the content of the
; BH register into the AH register
AND MASK1, 128 ; Perform AND operation on the
; variable MASK1 and 128
ADD MARKS, 10 ; Add 10 to the variable MARKS
MOV AL, 10 ; Transfer the value 10 to the AL register
; Hello World in Assembly
; -----------------------
section .text
global _start
_start:
mov edx,len
mov ecx,msg
mov ebx,1
mov eax,4
int 0x80
mov eax,1
int 0x80
section .data
msg db 'Hello, world!', 0xa
len equ $ - msg