(Assembly) Basic instruction of x86 assembly based on VS

environment

visual studio select x86 to run

sample code

/**
| 32位 | 16位 | 高8位 | 低8位 |
| ---- | ---- | ----- | ----- |
| EAX  | AX   | AH    | AL    |
 */
#include <iostream>

int main() {
    
    
    int32_t x = 1;
    int32_t y = 2;

    // 简单加法示例
    __asm {
    
    
        mov eax, x;
        mov ebx, y;
        add eax, ebx;
        mov x, eax;
    };

    ::std::printf("x = %d y = %d\n", x, y);
    
    return 0;
}

Assembly basics

flag bit

# visual studio 中的标志位
# OV UP EI PL ZR AC PE CY
  • OV overflow
    • Out of range means overflow 1, otherwise 0
  • UP increment
    • 1: Process data strings in descending order; 0: Process data strings in ascending order
  • EI enable interrupt
    • CPU enables interrupt 1, otherwise 0
  • PL Positive
    • The operation result is 1 if it is regular, otherwise 0
  • ZR líng
    • 1 if the result of the operation is 0, otherwise 0
  • AC auxiliary carry
    • Carry 1 from the lower 4 bits to the higher bit, otherwise 0
  • PE parity
    • The number of 1 in the lowest 16 bits is an even number is 1, otherwise 0
  • CY carry
    • The highest bit carries 1, otherwise 0

common command

Here we introduce the common basic instructions of assembly, without too much expansion, only record the basic meaning

instruction effect e.g
add addition add eax, ebx;
and bitwise AND operation and eax, ebx;
call The address of the next instruction is pushed onto the stack and jumps to the target for instruction execution call address;
cmp Operand 1-(sign extension) operand 2
is not saved, observe the flag bit
cmp eax, ebx;
dec Decrement dec eax;
div Division
result, remainder (different parameters)
various bx;
low Multiplication
(different parameters)
imul eax, ebx, ecx;
inc self-increment inc eax;
jmp jump This is a series of instructions
lea load address lea eax, address;
mov mov eax, 114514;
movsd double-precision assignment to register
movss But assignment of precision numbers to floating-point registers
movsx/movsxd sign extension transmission
movs series bulk memory transfer
movzx 0 extended transmission
neg Reversal (±) neg eax;
not bitwise inversion not eax;
or bitwise or or eax, ebx;
pop and related pop out pop eax;
push and related stack push eax;
rcl Circularly shift
the highest bit to cf, and cf to the lowest bit
rcl eax, times;
rcr Circular right shift
cf to fill in the highest bit and the lowest bit to fill in cf
rcr eax, times;
ret Restore address from stack ret ;
role Circularly shift
the highest bit to cf and the lowest bit, the original value of cf is discarded
rol eax, number of times;
ror Circularly shift
the lowest bit to the right and fill in the highest sum cf
ror eax, times
sar Arithmetic right shift
sign bit preserved
sar eax, value;
shr Logical right shift
high bit complement 0
shr eax, times
sub subtraction sub eax, ebx;
test Bitwise and
do not save, observe the flag bit
cmp eax, ebx;
xor bitwise XOR xor eax, ebx;

vs configuration

register

After entering debug mode, debug at the top -> window -> register

disassembly

In the editing interface, right click -> go to disassembly

After entering, right click and select to display specific information

detection variable

Note that the settings do not enable optimization




END

Guess you like

Origin blog.csdn.net/CUBE_lotus/article/details/130871551
Recommended