Machine Level Programming
-
machine code <-> assembly code
-
code -> low level, how to generate by GCC
-
intel 64(x86)
-
instruction set(hardware designers provide to users)
-
register
Turning C into object code
C program(.c)
-(Compiler)->
Assembly Program(.s)
-(Assembler)->
Object program(.o) (+Static libraries(.a))
-(Linker)->
Executable program
Compiling into Assembly
-
汇编内容
-
pushq : 压栈
-
movq : 复制,使用内存或寄存器地址
-
popq : 弹栈
-
call : 调用函数
-
ret : 从特定函数返回
-
.开头:给其他部分提供的信息
-
-
汇编中的数据类型
-
整型和浮点
-
本质都是字节序列
-
没有数组一类的结构
-
-
反汇编器:从机器代码到汇编代码,还会包含某些原始汇编代码中没有的底层指令。
-
objdump
-
gdb也有这个功能
-
-
所有命名全部消失,转化为位置
x86-64 Integer Register
-
%r for 64bit and %e for 32bit
-
special : %rsp stack pointer
-
operand types
-
Immediate: Constant integer data, prefixed with $
-
Register: %
-
Memory: address given by register, like (%rax)
-
-
Immediate doesn't have real position, and memory to memory is forbidden.
-
Memory Addressing
-
(R):Mem[Reg[R]]
-
D(R):Mem[Reg[R]+D] (Displacement)
-
-
Argument registe:%rdi, %rsi
-
lea: compute an address, and store it into the register.
-
load effective address
-
实际类似于c语言的取地址运算&,即其并未根据计算出的地址去访问内存,而只是将计算出的地址存入目的操作数
-
可以将数值输入地址计算的函数以实现简便运算?
-
-
Move
-
b,w,l,q(length)
-
z,s(how to lengthen)
-
movabsq: (directly use bit pattern, regardless of two's complementary form of negative numbers)
-
-
push & pop
-