September 27, 2017

Useful assembly code instructions

❑ INC op1
❍ Increase the value of the op1 by 1.

❑ DEC op1
❍ Decrease the value of the op1 by 1.

❑ ADD op1, op2
❍ Add the two operands and store the result in op1.

❑ SUB op1, op2
❍ Subtract op2 from op1 and store the result in op1.

❑ MUL op1
❍ Multiply op2 by EAX. If the result is overflowed, the upper 4 bytes of the result are stored in the EDX register and the lower 4 bytes are stored in EAX.
op1에 EAX를 곱한다. 결과값이 넘친다면 상위 4 Bytes는 EDX 레지스터에에 저장하고 하위 4 Bytes는 EAX에 저장한다.

❑ DIV op1
❍ Divide 8 bytes(EDX: EAX) by op1. The quotient is stored in EAX and the rest in EDX.
8 Bytes(EDX:EAX)를 op1로 나눈다. 몫은 EAX에 저장되고 나머지는 EDX에 저장된다.

❑ SHL/SHR op1, op2
❍ Performs a bit shift operation op2 times to left/right on op1.
op1에 좌측/우측으로 비트 쉬프트 연산을 op2회 수행한다.

❑ ROL/ROR op1, op2
❍ Performs a bit shift operation op2 times to left/right on op1And the shifted value is rotated not discarding.
op1에 좌측/우측으로 비트 쉬프트 연산을 op2회 수행한다. 그리고 밀려난 값은 순환된다.

❑ LEA op1, op2
❍ Store the address of op2 to the op1.

❑ PUSHAL / POPAL
❍ Push/pop registers
* order : EAX - ECX - EDX - EBX - ESP - EBP - ESI - EDI

❑ CALL op1
❍ Push the return address to the stack and jump to the op1 function
* PUSH eip
JMP [op1]

❑ LEAVE
❍ Empty the current stack and assign the base address of the memory that called it to ebp.
* mov esp, ebp
pop ebp

❑ RET
❍ Store the value pointed to by ESP to EIP.
* Usually the return value is stored in EAX.
* POP EIP

❑ NOP
❍ Occupy 1 Byte and occupies empty space and do not anything.

❑ TEST op1, op2
❍ Perform AND operation on op1 and op2.
* This set OF=0, CF=0. And if the result is 0, ZF=1 otherwise ZF=0
* This doesn't save the result value.

❑ DWORD ptr SS:[ebp-4]
❍ DWORD ptr: Setting the size of the "SS:[ebp-4]".
❍ "SS:": Indicating the data of Stack segment.


❑ CMP op1, op2
❍ Subtract the op2 from the op1. This affects CF and ZF.
* This doesn't save the result value.
ResultZF(Zero Flag)CF(Carry Flag)
op1 < op2
0
1
op1 > op2
0
0
op1 = op2
1
0


❑ JCC(Jump Condition Code)
❍ Changes the execution flow to op1 according to the conditions.
CommandMeanCondition
JAJump if (unsigned) above(CF == 0) && (ZF == 0)
JAEJump if (unsigned) above or equalCF == 0
JBJump if (unsigned) belowCF == 1
JBEJump if (unsigned) below or equal(CF == 1) || (ZF = 1)
JCJump if carry flag setCF == 1
JCXZJump if CX is 0CX == 0
JEJump if equalZF == 1
JECXZJump if ECX is 0ECX == 0
JGJump if (signed) greater(ZF == 0) && (SF == OF)
JGEJump if (signed) greater or equal(SF == OF)
JLJump if (signed) less(SF != OF)
JLEJump if (signed) less or equal(ZF == 1) && (SF != OF)
JNAJump if (unsigned) not above(CF == 1) || (ZF = 1)
JNAEJump if (unsigned) not above or equalCF == 1
JNBJump if (unsigned) not belowCF == 0
JNBEJump if (unsigned) not below or equal(CF == 0) && (ZF == 0)
JNCJump if carry flag not setCF == 0
JNEJump if not equalZF == 0
JNGJump if (signed) not greater(ZF == 1) || (SF != OF)
JNGEJump if (signed) not greater or equalSF != OF
JNLJump if (signed) not lessSF == OF
JNLEJump if (signed) not less or equal(ZF == 0) and (SF == OF)
JNOJump if overflow flag not setOF == 0
JNPJump if parity flag not setPF == 0
JNSJump if sign flag not setSF == 0
JNZJump if not zeroZF == 0
JOJump if overflow flag is setOF == 1
JPJump if parity flag setPF == 1
JPEJump if parity is equalPF == 1
JPOJump if parity is oddPF == 0
JSJump if sign flag is setSF == 1
JZJump if the result is zeroZF == 1
 
LOOP: jump to op1 according to the conditions
CommandMeanCondition
LOOP op1
CX = CX - 1
jump to op1
Jump if CX != 0
LOOPNZ op1
LOOPNE op1
Loop if not zero(equal).
CX = CX - 1
jump to op1
Jump if
(CX != 0) && (ZF == 0)
LOOPZ op1
LOOPE op1
Loop if not zero(equal).
CX = CX - 1
jump to op1
Jump if
(CX != 0) && (ZF == 1)






 
 
 
 
 ※ Reference