Several basic assembly instructions

Source: Internet
Author: User

Several basic assembly instructions in detail common registers
Register Device 16 Guests 32 Guests 64 Guests
Cumulative register Ax EAX RAX
Base Address Register Bx EBX RBX
Count Register CX Ecx RCX
Data registers Dx EDX Rdx
Stack base pointer Bp Ebp RBP
Variable address register SI Esi RSI
Stack top pointer Sp Esp RSP
Instruction Register Ip Eip Rip
Assembly Instructions MOV
    • MOVB (8-bit), MOVW (16-bit), MOVL (32-bit), MOVQ (64-bit)

    • Register addressing:

      movl%eax,%edx

      EAX-EdX

    • Immediate number addressing:

      movl $0x123,%edx

      Digital Register

    • Direct addressing:

      movl 0x123,%edx

      Direct access to memory address data, edx = * (int32_t *) 0x123;

    • Indirect addressing:

      MOVL (%EBX),%edx

      %EBX is a memory address, (%EBX) refers to the data in that address, edx = * (int32_t*) ebx;

    • Variable address addressing:

      MOVL 4 (%EBX),%edx

      edx = * (int32_t*) (ebx+4);

The Push & pull stack data structure introduces the role:
    • Program Call Framework
    • Passing parameters
    • Save return address
    • Provide local variables
    • ......
Structure:

    • Related registers: ESP, EBP

    • Related actions: Pop, push

      //建立被调用者函数的堆栈框架pushl %ebpmovl %esp, %ebp//拆除框架movl %ebp, %esppopl %ebpret
Push: Press Stack
    • Push%eax

      Equivalent:

      subl $4, %esp//栈顶指针减4movl %eax, (%esp)//%eax -> esp 地址
Pop: Out of the stack
    • Pop%eax

      Equivalent:

      movl (%esp), %eaxaddl %4, %esp//栈顶指针加4
Call&retcall
    • Call 0x12345

      Equivalent:

      pushl %eipmovl $0x12345, %eip//当前地址压栈,存入新地址
Ret
    • Equivalent:

      popl %eip//栈 -> eip
Enter&leaveenter
    push %ebp    movl %esp, %ebp    //将堆栈置空(栈上重堆)
Leave
    movl %ebp, %esp    popl %ebp    //将堆栈置空(撤销堆栈)
Example: Analyzing a piece of assembly code
    pushl $8   ①    movl %esp, %ebp     ②    subl $4, %esp  ③    movl $8, (%esp)        ④

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Several basic assembly instructions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.