CPU寄存器register
寄存器分类:
通用寄存器
如 `EAX`, `EBX`, `ECX`, `EDX`, `ESI`, `EDI`, `EBP`, `ESP`。
段寄存器
如 `CS`, `DS`, `ES`, `FS`, `GS`, `SS`。
标志寄存器
如 `EFLAGS`。
Flags分类:
Status:状态标志
Overflow:溢出标志
Carry :进位标志
内联汇编Inline assembly
_asm
适用于单行汇编代码时可不使用花括号{},多行需用{}包围
注释:;或//
scanf:输入
Call scanf之前先在最前面int input
printf:输出
Stack栈 VS Queue队列:
1、存储顺序
栈:LIFO(后进先出)。
Upside-down stack:栈顶(Top of the Stack)在最底部,栈底(Bottom of the Stack)在最顶部
队列:FIFO(先进先出)。
2、操作方式
栈:push 和 pop。
Push:首先递增 ESP,然后将数据写入新的栈顶位置。
Pop:首先从 ESP 指向的地址读取数据,然后递减 ESP
队列:enqueue 和 dequeue。
栈指针(Stack Pointer,ESP)
使用原因:释放和分配栈空间
Add:减少栈空间(释放栈空间)
Sub:增加栈空间(分配栈空间)
栈应用场景:
1、用于临时储存:使用栈保存循环计数器(Loop Counter)
2、传递参数:通过栈传递参数并调用 printf 函数。
指令instruction
指令结构:
1、action or operation
2、operands
3、result
每条机器指令都由特定的位字段(distinct bit fields in the prefix)编码
这些字段包含
1、operation
2、location of operands and results
3、data type of operand
寻址模式
1、立即寻址Immediate (operand) mode
2、数据寄存器直接寻址Data Register Direct
速度max
3、内存直接寻址Memory Direct
4、地址寄存器直接寻址Address Register Direct
5、寄存器间接寻址Register Indirect
6、带偏移的索引寄存器间接寻址(Indexed Register Indirect with Displacement)
控制程序流control program flow
jump:
分类:
1、Unconditional
e.g.JMP <address of the target instruction>
2、Conditional:true则jump,false则continue
e.g.JCXZ,JECXZ
循环
Loops
Implementing higher-order constructs: conditional statements:
For
While
Do-while
switch-case