x86 assembly

  • Registers
    • General-purpose registers
      • EAX EBX ECX EDX - 32 bit
      • AX BX CX DX - 16 bit
      • AH BH CH DH - 8 bit (high)
      • AL BLCLDL - 8bit (low)
        在这里插入图片描述
      • Buffer pointer (缓冲区指针)
        • EDI ESI - 32 bit
        • DI SI - 16 bit
    • Stack Pointer
      • ESP - 32 bit
      • 指向 stack 顶端
    • Base Pointer
      • EBP - 32 bit
      • 指向 stack 底端
    • ESP 到 function 参数范围称为该 function 得到 Stack Frame
      在这里插入图片描述
    • Program counter register
      • EIP
      • 只想目前程式执行的位置
    • Flag register
      • eflags
      • 储存指令执行的结果
    • Segment register
      • cs ss ds es fs gs

汇编指令

  • AT & T
    • mov %eax,%ebx
  • Intel
    • mov ebx,eax
  • Basic instruction (基本命令)
    • mov
      • mov imm/reg/mem value to reg/mem
      • mov A,B (move B to A)
      • A 与 B 的 size 要相等
      • ex:
        • mov eax,ebx (√)
        • mov eax,bl (×)
        • mov eax,0xdeadbeef
    • add/sub
    • and/or/xor
      • add/sub/or/xor/and reg,imm/reg
      • add/sub/or/xor/and A,B
      • A 与 B 的 size 一样要相等
      • ex:
        • add ebp,0x48
        • sub eax,ebx
    • push/pop
      • push/pop reg
      • ex:
        • push eax 等价于 sub esp , 4 ; mov [esp] ,eax
        • pop ebx 等价于 mov ebx , [esp] ; add esp ,4
    • lea
      • ex:
      • lea eax , [esp+4]
  • lea v.s. mov

按我的理解解释,lea取地址。mov取值

  • jmp/call/ret
    • jmp 跳至程式码的某处去执行
    • call eax 等价于 push 下一条指令的ip ; jmp eax
    • ret 等价于 pop eip
  • leave
    • mov esp ,ebp
    • pop ebp
  • nop
    • 一个 byte 不做任何事
    • opcode = 0x90
  • System call
    • instruction : int 0x80
    • eax : system call number / return value
    • ebx,ecx,edx,esi,edi : argument
  • System call table
  • https://syscalls.w3challs.com/?arch=x86
  • 在这里插入图片描述
  • Calling convention (调用约定)
    • function call
      • call : push return address to stack then jump
    • function return
      • ret : pop return address
    • function argument
      • x86 下一般来说用 stack 传递 , 但也有用 register 传递 没有强制规定
      • 依序 push 进 stack 后 ,再去执行 function call
    • function prologue (我的理解就是开栈)
      • compiler(编译器) 在 function 开头加的指令 , 主要在保存 ebp 分配区域变数所需空间
    • function epilogue
      • compiler 在 function 结尾加的指令 , 主要在利用保存的 ebp 回覆 call function 时的 stack 状态
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值