“很多人认为推崇机器语言根本就是我所犯的最大错误,不过我坚持认为除非你了解了各种底层细节,否则根本不可能为态度认真的计算机程序员写书”—DonaldKnuth
“汇编语言是所有程序设计语言中最古老的语言,他与计算机的机器语言最为接近,通过汇编语言可以直接访问计算机的硬件,这就要求读者深入了解计算机体系结构和操作系统的大量细节。”
汇编器->链接器->调试器
汇编语言与诸如c++和java等高级语言时多对一的关系即 一条高级语令对等于多条汇编语言。
但是汇编语言和机器语言确实一对一的关系。
汇编语言不像java那样可以移植
汇编语言的用处:
· 嵌入式程序 ->节约使用内存
· 游戏机有 严格限制内存容量 ->用汇编速度快
· 驱动程序
虚拟机的概念:是说明计算机软硬件之间相互关系的最佳途径。
由于最底层语言L0对于人类来说过于冗长而负责,那么编写一个更容易理解的语言L1需要有两种方式可以达到这个目的:
· 解释方式:边执行L1边解码L1到L0
· 翻译方式:一口气把L1翻译成L0
虚拟机图解:
·
数据的表示方法:
One kilobyte is equal to 2^10, or 1024 bytes.
• One megabyte (1 MByte) is equal to 2^20, or 1,048,576 bytes.
• One gigabyte (1 GByte) is equal to 2^30, or 10243, or1,073,741,824 bytes.
• One terabyte(1 TByte) is equal to 2^40,or 10244,or 1,099,511,627,776 bytes.
•One petabyte is equal to 2^50, or 1,125,899,906,842,624 bytes.
• One exabyte is equal to 2^60, or 1,152,921,504,606,846,976 bytes.
• One zettabyteis equal to 2^70 bytes.
• One yottabyteis equal to 2^80 bytes.
十六进制2cf补码:
(15-每位)后+1
Ex:
6A3D --> 95C2 + 1--> 95C3
95C3 --> 6A3C + 1 --> 6A3D
波尔运算(Boolean operation)
NOT:notated as ¬ or ~ or '
AND:notated as 倒v or *
OR: notated as v or +
微机的基本结构:各个子结构用途见p22页汇编语言程序设计
程序是如何运行的:
操作系统的多任务:
Mostmodern operating systems simultaneously execute tasks that communicate withhardware,
displayuser interfaces, perform background file processing, and so on. A CPU canreally
execute only one instruction at atime, so a component of the operating systemnamed the
scheduler allocates a slice ofCPU time (called a time slice) to each task. During a single time slice,
theCPU executes a block of instructions, stopping when the time slice has ended.
Byrapidly switching tasks, the processor creates the illusion they are running simultaneously.
Onetype of scheduling used by the OS is called
round-robin scheduling.
通用寄存器用于算术运算和数据传输(32位和16位)
段寄存器用于存放段的基址
• CS contains the 16-bit code segment address
• DS contains the 16-bit data segment address
• SS contains the 16-bit stack segment address
指令指针(EIP)存放下一条指令的地址(貌似就是offset,不过段结构要复杂很多)
EFLAGS寄存器:反应寄存器的运算结果的指标
控制标志:
• The Carry flag (CF) is set when the result of anunsigned arithmetic operation is too large to
fit into the destination.
• The Overflow flag (OF) is set when the result of asigned arithmetic operation is too large or
too small to fit into the destination.
• The Sign flag (SF) is set when the result of anarithmetic or logical operation generates a
negative result.
• The Zero flag (ZF) is set when the result of anarithmetic or logical operation generates a result of
zero.
• The Auxiliary Carry flag (AC) is set when anarithmetic operation causes a carry from bit 3
to bit 4 in an 8-bit operand.
• The Parity flag (PF) is set if the least-significantbyte in the result contains an even number
of 1 bits. Otherwise, PF is clear. In general, it is used for errorchecking when there is a possibility
that data might be altered or corrupted.
20线性地址计算:
由于处理器是20位的线性地址,由于要解决16为寄存器不能存放20为的地址。
所以解决办法为:
用两个16位表示:段和偏移地址
• A 16-bit segmentvalue, placed in one of the segment registers(CS, DS, ES, SS)
• A 16-bit offsetvalue
• ES, FS, and GS can point to alternate datasegments, that is, segments that supplement the
defaultdata segment
计算时段自动进1位最左边+0然后与偏移地址相加