Assembly language instructions

Assembly language

Assembly language is a low-level programming language that is closely tied to a specific computer architecture. Different computer architectures have different sets of assembly language instructions. Here are some common assembly language instructions, covering common instruction types:

The following are some common assembly instructions for the x86 architecture with their explanations and examples:

  1. Data transfer instructions:

    • MOV: Copies data from one location to another.
      Example: MOV AX, BX Copies the value of the BX register to the AX register.

    • XCHG: Exchange data at two locations.
      Example: XCHG AX, BX Swap the values ​​of the AX and BX registers.

    • PUSH: Push data onto the stack.
      Example: PUSH AX Push the value in the AX register onto the stack.

    • POP: Pop data from the stack.
      Example: POP AX Pop a value from the stack and store it in the AX register.

  2. Arithmetic and logical instructions:

    • ADD: Add two numbers.
      Example: ADD AX, BX Adds the values ​​of the AX register and the BX register and stores the result in the AX register.

    • SUB: Subtract one number from another.
      Example: SUB AX, BX Subtract the value of the BX register from the AX register and store the result in the AX register.

    • MUL: Multiply two numbers.
      Example: MUL AX, BX Multiply the values ​​of the AX register and the BX register and store the result in the AX register.

    • DIV: Divide one number by another number.
      Example: DIV AX, BX Divide the value in the AX register by the value in the BX register and store the quotient in the AX register and the remainder in the DX register.

    • AND: Perform logical AND operation on two binary numbers.
      Example: AND AX, BX Performs a logical AND operation on the values ​​in the AX register and the BX register and stores the result in the AX register.

    • OR: Perform logical OR operation on two binary numbers.
      Example: OR AX, BX Performs a logical OR operation on the values ​​in the AX register and the BX register and stores the result in the AX register.

    • XOR: Perform logical XOR operation on two binary numbers.
      Example: XOR AX, BX Performs a logical XOR operation on the values ​​in the AX register and the BX register and stores the result in the AX register.

    • NOT: Perform logical NOT operation on a binary number.
      Example: NOT AX Performs a logical NOT operation on the value of the AX register and stores the result in the AX register.

  3. Jump and branch instructions:

    • JMP: Jump to the specified address unconditionally.
      Example: JMP Label Unconditionally jump to the tag named Label.

    • JC: If the carry flag is true, jump to the specified address.
      Example: JC Label If the carry flag is true, jump to the label named Label.

    • JZ: If the zero flag bit is true, jump to the specified address.
      Example: JZ Label If the zero flag is true, jump to the label named Label.

    • JE: If the equality flag is true, jump to the specified address.
      Example: JE Label If the equality flag is true, jump to the label named Label.

    • JNE: If the inequality flag is true, jump to the specified address.
      Example: JNE Label If the inequality flag is true, jump to the label named Label.

    • CMP: Compare two numbers and set the corresponding flag bit according to the comparison result.
      Example: CMP AX, BX Compare the values ​​of the AX register and the BX register, and set the flag bit based on the comparison result.

  4. Loop instructions:

    • LOOP: Repeat a section of code based on the counter value.
      Example: LOOP Label Repeatedly execute the code at the label named Label based on the value of the CX register.

    • FOR: Instructions to implement loop structures.
      Example: FOR I, 1, 10 Implement a loop structure from 1 to 10, with the loop variable stored in register I.

  5. Memory access instructions:

    • LEA: Load the memory address into the register.
      Example: LEA AX, [BX+SI] Add the values ​​of the BX and SI registers and load the result into the AX register as a memory address.

    • LDS: Load data in memory into segment registers and general registers.
      Example: LDS AX, [BX] Take the value in the BX register as the memory address and load the data at that address into the DS segment register and AX register.

    • STOS: Store data into the specified memory address.
      Example: STOS BYTE PTR [DI], AL Store the value of the AL register to the memory address specified by the DI register.

  6. Procedure call instructions:

    • CALL: Call a subroutine or function.
      Example: CALL Subroutine Calls a subroutine or function named Subroutine.

    • RET: Return from subroutine or function.
      Example: RET Return from a subroutine or function to the point where it was called.

This is an example of some common assembly instructions in the x86 architecture, covering common instruction types such as data transfer, arithmetic logic, jump branches, loops, memory accesses, and procedure calls.
Please note that different instruction sets and architectures have different instruction sets and syntax rules. In actual programming, you should refer to the documentation and guides of the specific architecture and compiler to understand its supported instruction set and syntax rules.

Supplementary assembly language instructions encountered later

SHRsumTESTcommand.

  1. SHRinstruction:

    • SHRIt is the abbreviation of "Shift Right". It is used to shift a binary number to the right by a specified number of digits.
    • SHRThe syntax of the instruction is usually: SHR destination, count, where destination represents the target operand to be shifted, and count represents The number of bits to move.
    • SHRThe instruction moves the binary bits of the target operand to the right. The vacant bits on the right are filled with 0s. The number of bits moved is specified by count.
    • SHRInstructions are commonly used for logical and arithmetic right shift operations.
    • For example, the SHR instruction can be used to divide an unsigned integer by a power of 2.
  2. TESTinstruction:

    • TESTThe instruction is used to perform a logical AND operation on two operands and update the processor flag register (such as the zero flag, carry flag, etc.).
    • TESTThe syntax of the instruction is usually: TEST operand1, operand2, where operand1 and operand2 represent the operands to be logically ANDed .
    • TESTThe instruction performs a logical AND operation on operand1 and operand2, and the result affects the status of the flag register without storing the result.
    • TESTInstructions are often used in scenarios such as conditional judgment, control flow, and bit operations. The relationship between operands is determined by checking the status of the flag register.
    • For example, you can use theTEST instruction to check whether a bit in a register is set (to 1) and perform a conditional branch based on the result.

Guess you like

Origin blog.csdn.net/ultramand/article/details/134960640