在C代码的反汇编中定义了哪些数值? [英] What numeric values defines in dissembled of C code?

查看:163
本文介绍了在C代码的反汇编中定义了哪些数值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在理解汇编代码和C代码. 我有以下C程序,仅编译为生成目标文件.

I'm understanding the assembly and C code. I have following C program , compiled to generate Object file only.

#include <stdio.h>
int main()
{
  int i = 10;
  int j = 22 + i;
  return 0;
}

我执行了以下命令

objdump -S myprogram.o

以上命令的输出为:

objdump -S testelf.o 

testelf.o:     file format elf32-i386


Disassembly of section .text:

00000000 <main>:
#include <stdio.h>

int main()
{
   0:   55                      push   %ebp
   1:   89 e5                   mov    %esp,%ebp
   3:   83 ec 10                sub    $0x10,%esp
  int i = 10;
   6:   c7 45 f8 0a 00 00 00    movl   $0xa,-0x8(%ebp)
  int j = 22 + i;
   d:   8b 45 f8                mov    -0x8(%ebp),%eax
  10:   83 c0 16                add    $0x16,%eax
  13:   89 45 fc                mov    %eax,-0x4(%ebp)

  return 0;
  16:   b8 00 00 00 00          mov    $0x0,%eax
}
  1b:   c9                      leave  
  1c:   c3                      ret  

助记符命令前的数字是什么意思 即"sub"命令之前的"83 ec 10"或 在移动"命令之前输入"c7 45 f8 0a 00 00 00"

What is meant by number numeric before the mnemonic commands i.e. "83 ec 10 " before "sub" command or "c7 45 f8 0a 00 00 00" before "movl" command

我正在使用以下平台来编译此代码:

I'm using following platform to compile this code:

$ lscpu 
Architecture:          i686
CPU op-mode(s):        32-bit
Byte Order:            Little Endian
CPU(s):                1
On-line CPU(s) list:   0
Thread(s) per core:    1
Core(s) per socket:    1
Socket(s):             1
Vendor ID:             GenuineIntel

推荐答案

这些是x86操作码. 此处可提供除上面注释中列出的参考之外的详细参考.

Those are x86 opcodes. A detailed reference, other than the ones listed in the comments above is available here.

例如,movl $0xa,-0x8(%ebp)之前的c7 45 f8 0a 00 00 00是操作码字节的十六进制值.它们告诉CPU将立即数10十进制数(作为4字节值)移动到位于堆栈帧基址指针上方8字节的当前堆栈上的地址中.运行代码时,这就是C源代码中的变量i所在的位置.堆栈顶部的内存地址比堆栈底部的内存地址低,因此从底部向负方向移动会使堆栈向上移动.

For example the c7 45 f8 0a 00 00 00 before the movl $0xa,-0x8(%ebp) are hexadecimal values for the opcode bytes. They tell the CPU to move the immediate value of 10 decimal (as a 4-byte value) into the address located on the current stack 8-bytes above the stack frame base pointer. That is where the variable i from your C source code is located when your code is running. The top of the stack is at a lower memory address than the bottom of the stack, so moving a negative direction from the base is moving up the stack.

c7 45 f8操作码的意思是移动数据并清除 EFLAGS 中的算术进位标记注册.有关更多详细信息,请参见参考.

The c7 45 f8 opcodes mean to mov data and clear the arithmetic carry flag in the EFLAGS register. See the reference for more detail.

其余代码为即时值.由于您使用的是Little Endian系统,因此会首先列出数字的最低有效字节,因此将0a 00 00 00存储为十进制的10个十进制(十六进制为0x0a,其4字节值为0x0000000a).

The remainder of the codes are an immediate value. Since you are using a little endian system, the least significant byte of a number is listed first, such that 10 decimal which is 0x0a in hexadecimal and has a 4-byte value of 0x0000000a is stored as 0a 00 00 00.

这篇关于在C代码的反汇编中定义了哪些数值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆