3.0 ASM Basic Knowledge
This chapter will teach you the basics of your assembly language
1. 1 pseudo code (OPCODES)
The assembler is created with pseudo code. A pseudo code is an instruction that a processor can understand. E.g:
Add
The Add instruction adds two numbers to. Most pseudo code has parameters
Add Eax, EDX
ADD has two parameters. In the case of the addition, a source is a target. It adds the source value to the target value and saves the result in the target. There are many different types: registers, memory addresses, direct values (IMMEDIATE VALUES) as follows:
3. 2 register
There are several sizes of registers: 8-bit, 16-bit, 32 bits (there are more in the MMX processor). In the 16-bit program, you can only use 16-bit and 8-bit registers. In a 32-bit program, you can use 32-bit registers.
Some registers are part of the other registers: for example, if EAX saves the value EA7823BBH here is the value of other registers.
EAX
EA
78
twenty three
BB
AX
EA
78
twenty three
BB
AH
EA
78
twenty three
BB
Al
EA
78
twenty three
BB
AX, AH, Al is part of EAX. EAX is a 32-bit register (existed only over 386), AX contains the low 16-bit (2 bytes) of Eax, and AH contains the high byte of AX, and Al contains the low byte of AX. Therefore, AX is 16-bit, Al and AX are 8 bits. In the above example, these are the values of those registers:
EAX = EA7823BB (32-bit) AX = 23bb (16-bit) AH = 23 (8-bit) Al = BB (8-bit)
Examples of using registers (don't manage those pseudo codes, just see the registers)
Mov Eax, 12345678H
MOV loads a value into the register (note: 12345678h is a hexadecimal value because h is the suffix.
MOV CL, AH
Move the high byte of AX into CL
SUB CL, 10
Subtract 10 (decimal) from the value of CL
MOV Al, Cl
And store CL in EAX's lowest byte
Let us analyze the above code:
The MOV command can move a value from registers, memory, and direct values into another register. In the above example, EAX contains 12345678h, then the value of AH (the left left third byte) is copied into the CL (the lowest byte of the ECX register). Then, CL minus 10 and move back to Al (the lowest byte of EAX)
Different types of registers:
General Purpose
These 32-bit (their components are 16/8) registers can be used to do anything:
EAX (AX / AH / Al)
Adder
EBX (BX / BH / BL)
Base
ECX (CX / CH / CL)
counter
EDX (DX / DH / DL)
data
Although they have names, you can use them to do anything.
Segment register
Segment registers define which memory is used. You may not be able to use them in Win32ASM because Windows has a flat (FLAT) memory system. In DOS, memory is divided into 64KB segment, so if you want to set a memory address. You specify a segment and use an offset (offset) (like 0172: 0500 (segment: offset)). In Windows, there is 4GB size, so you don't need segments in Windows. The segment is always 16-bit registers. Cs
Code segment
DS
Data segment
SS
Stack segment
ES
Expand segment
FS (ONLY 286 )
Full functional segment
GS (ONLY 386 )
Full functional segment
Pointer register
In fact, you can use the pointer register as a full-featured register (except for EIP), as long as you save and restore their original value. The pointer register so this is called because they are often used to store memory addresses. Some pseudo codes (MOVB, SCASB, etc.) also use them.
ESI (Si)
Source index
EDI (DI)
Target index
EIP (IP)
Instruction pointer
EIP (IP in 16-bit programming) contains pointers that point to the next instruction to be executed. Therefore, you cannot use the EIP as a full-featured register.
Stack register
There are 2 stack registers: ESP and EBP. The ESP is equipped with the position of the current stack in memory (in the next chapter, there are more contents). EBP is used in a function to point to a pointer to a local variable.
ESP (SP)
Stack pointer
EBP (BP)
Base pointer