0% found this document useful (0 votes)
14 views4 pages

Assembly X86

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

Assembly X86

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Assembly

• JMP - Unconditional jump


• JE, JNE, JZ, JNZ - Conditional jumps
(Equal, Not Equal, Zero, Not Zero)
Registers:
• CALL, RET - Call subroutine, Return
General Purpose Registers: from subroutine
• AX, BX, CX, DX (16-bit) • CMP - Compare two values

• EAX, EBX, ECX, EDX (32-bit) Stack Operations:


• RAX, RBX, RCX, RDX (64-bit)
• PUSH, POP - Push onto stack, Pop
Index Registers: from stack
• SI (Source Index) I/O:
• DI (Destination Index)
• IN, OUT - Input/Output operations
Base Registers:
Directives:
• BP (Base Pointer)
• SP (Stack Pointer) • DB - Define Byte
• DW - Define Word
Segment Registers: • DD - Define Double Word
• CS (Code Segment) • DQ - Define Quad Word
• DS (Data Segment)
• SS (Stack Segment)
• ES (Extra Segment)

Instructions:
Data Movement:

• MOV - Move data from source to


destination

Arithmetic:

• ADD, SUB, MUL, DIV - Addition,


Subtraction, Multiplication,
Division

Logical:

• AND, OR, XOR, NOT - Bitwise


operations

Control Flow:
Assembly
Code : int 0x80 ; call kernel

1. Data manipulation ; Exit program


section .text mov eax, 1 ; system call for
global _start sys_exit

_start: xor ebx, ebx ; exit code 0

; Move value 5 into AX int 0x80 ; call kernel

mov ax, 5

; Move value 10 into BX not_equal:

mov bx, 10 ; Print message if not equal

; Add BX to AX mov eax, 4

add ax, bx mov ebx, 1

; Move result to CX mov ecx, not_equal_message

mov cx, ax mov edx, 15

; Compare CX with 15 int 0x80

cmp cx, 15

; Jump if equal to the label 'equal' ; Exit program

je equal mov eax, 1

; If not equal, jump to 'not_equal' xor ebx, ebx

jmp not_equal int 0x80

equal:

; Print message if equal section .data

mov eax, 4 ; system call for message db 'Result is 15', 0xA


sys_write not_equal_message db 'Result is not
mov ebx, 1 ; file descriptor 1 is 15', 0xA
stdout

mov ecx, message ; message to


write

mov edx, 11 ; message length


Assembly
mov dword [my_list + 8], 10 ;
Change the third element of the
list to 10
2. For loop
section .text ; Looping through the list

global _start mov ecx, 0 ; Initialize loop


counter
_start:
loop_start:
mov ecx, 10 ; Set loop counter to 10
cmp ecx, list_size ; Compare
for_loop:
loop counter with list size
; Your loop body code goes here
jge loop_end ; If counter >=
loop for_loop list size, exit loop
; Decrement ECX and jump back to mov eax, [my_list + ecx * 4] ;
for_loop if ECX is not zero Load list element into EAX

; Process list element here

3. List manipulation inc ecx ; Increment loop


counter
section .data
jmp loop_start ; Jump back
list_size equ 5 ; Define list size to loop start
my_list dd 1, 2, 3, 4, 5 ; Define loop_end:
an array (list) of integers

section .text
; Code after the loop goes here
global _start

_start:

; Accessing list elements

mov eax, [my_list] ; Load the


first element of the list into EAX

mov ebx, [my_list + 4] ; Load the


second element of the list into EBX

; Modifying list elements


Assembly
Directives : Reserves a specified number of
words (16-bit integers) of memory.
Data Definition Directives:
Example: `array resw 50
1. DB (Define Byte): Defines
4. RESD (Reserve Doubleword):
one or more bytes of data.
Reserves a specified number of
Example: doublewords (32-bit integers) of
memory.
my_byte db 10, 20, 30
Example: data resd 10
2. DW (Define Word):

Defines one or more words (16-bit


integers) of data. 5. RESQ (Reserve Quadword):
Reserves a specified number of
Example:
quadwords (64-bit integers) of
my_word dw 1000, 2000, 3000 memory.
3.DD (Define Doubleword): Example: `big_data resq 5
Defines one or more
### Segment Definition Directives:
doublewords (32-bit integers) of
data. 1. **SECTION:** Defines a section
of the program.
Example: `my_doubleword dd
1000000, 2000000, 3000000 Example: `section .data` or
`section .text`
4.DQ (Define Quadword):
2. **GLOBAL:** Declares a label
Defines one or more quadwords
as global, making it visible to other
(64-bit integers) of data.
modules or files.
Example: `my_quadword dq
Example: `global _start
1000000000, 2000000000,
3000000000 3. **EXTERN:** Declares a label
defined in another module or file
Reserving Memory Directives:
as external.
1. RESB (Reserve Byte):**
Example: extern printf
Reserves a specified number of
bytes of memory. These directives are essential for
organizing your code, defining
Example: `buffer resb 100
data, and managing memory in
2. RESW (Reserve Word): assembly language programs.
They provide instructions to the
assembler to generate appropriate
machine code.

You might also like