chapter 2 parts of a computer system -----how the memory (内存) and cpu look to the assembly...
Post on 21-Dec-2015
217 views
TRANSCRIPT
![Page 1: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/1.jpg)
Chapter 2 Parts of a Computer System
-----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which have Intel 80x86 CPU
![Page 2: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/2.jpg)
Aims
Introduce memory system in IBM PC Introduce registers (寄存器) in 80X8
6 CPU Introduce I/O device Introduce software used in assembly lan
guage programming
![Page 3: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/3.jpg)
Outcomes
Master the concepts , model of the memory in IBM PC
Master the registers in 80x86 CPU Mater the software that used in
programming with assembly language
Know I/O device in IBM PC
![Page 4: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/4.jpg)
PC computer system Hardware
Central processing unit (CPU), memory circuits, keyboard, monitor and other input/output device
Software Refers to the programs that the
hardware executes System software Application software
![Page 5: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/5.jpg)
History of Intel CPU
We will discuss PC based on Intel CPU.So let’s look at the history of Intel CPU.
![Page 6: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/6.jpg)
The Microprocessor Age
4-bit microprocessors Intel 4004, the world’s first one, 1971 Intel 4040, an updated version of 4004
8-bit microprocessors Intel 8008, 8080,8085 Motorola MC6800, Zilog Z80
![Page 7: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/7.jpg)
The Modern Microprocessor
In 1978, Intel released the 8086 microprocessor; a year or so later, it released the 8088. Both devices are 16-bit microprocessors. They can run faster than 8085 and address (寻址) 1M bytes of memory.
![Page 8: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/8.jpg)
The Intel family of microprocessors
8086/8088, 80186/80188 80286 80386 80486 Pentium, MMX Pentium Pentium II, Pentium Pro Pentium III Pentium 4, Pentium TH
![Page 9: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/9.jpg)
The Future of Microprocessors Lots of new technology, used for parallel processin
g ( 并行处理 ) Superscalar ( 超标量 ) Superpipelining ( 超级流水线 ) SIMD (Single instruction multiple data) Hyper-Threading( 超线程 )
64-bit microprocessor EPIC (Explicitly Parallel Instruction Computin
g) in Itanium
![Page 10: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/10.jpg)
Personal Computer System
Memory system ( 存储器系统 )DRAM, SRAM, Cache, ROM, EEPROM, Flash memory
I/O system ( 输入输出系统 )Mouse, Keyboard, Monitor , Disk drive, DVD drive, Printer, Plotter, Scanner
Microprocessor ( 微处理器 ) = CPU (central processing unit 中央处理单元 )
Bus ( 总线 ) Data bus, control bus,address bus
Memory system Microprocessor I/O system
Buses
![Page 11: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/11.jpg)
2.1 PC hardware: Memory
Memory in an IBM PC or compatible microcomputer is logically a collection of “slots”, each of which can store one byte (字节) of instructions or data
![Page 12: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/12.jpg)
Little Endian
How to store a word (two bytes) in the memory?--Intel’s method: little endian ( 小端方式 )
The low byte goes to the low memory location, and the high byte goes to the high memory address.
An alternate method: big endian ( 大端方式 )
![Page 13: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/13.jpg)
Data in memory
34h
12h
78h
56h
341234h
56781234h
low
high
![Page 14: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/14.jpg)
RAM & ROM Read-only memory (ROM)
Permanently retain their contents and can be read from but not written to.
Random access memory (RAM) Can be written to read from by program
instructions The contents of RAM chips are lost when
the computer’s power is turned off
![Page 15: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/15.jpg)
Physical address (物理地址) Each memory byte has a 32-bit/20-bit
numeric label called physical address
![Page 16: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/16.jpg)
Prior to the 80386 chip
Processors has 20-bit address bus, so they can only directly address 220 bytes of memory. Range from 00000h to FFFFFh 1M
![Page 17: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/17.jpg)
Up to 80386
Processors has 32-bit address bus, so they can only directly address 232 bytes of memory. From 00000000h to FFFFFFFFh
A PC can contain up to four gigabytes memory
![Page 18: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/18.jpg)
Memory models (内存模式)
32-bit memory model Flat memory model (平展内存模式) Segmented memory model (分段内
存模式) 16-bit memory model
Real address mode memory model(实地址内存模式)
![Page 19: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/19.jpg)
Real address memory mode (实地址模式)
Real address allows the CPU to address only the first 1M bytes of memory space, which is called either the real memory ( 实存储器 ) or conventional memory ( 常规存储器 ).
Memory is visualized as a collection of segments, each segment 64Kbytes long, starting on an address that is multiple of 16.(paragraph)
A segment is a section (an area) of memory.
![Page 20: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/20.jpg)
Segment ( 段) The CPU may use many segments in the program.
For instance, a typical assembly language program consists of at least three segments: code segment ( 代码段 )
(holds the code, i.e. programs or procedures) data segment ( 数据段 )
(contains the most data used in a program) stack segment ( 堆栈段 )
(the area of memory used for the stack)
![Page 21: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/21.jpg)
Memory reference
Memory reference depends on its segment number and a 16-bit offset from the beginning of the segment. Normally only offset is encoded, and
the segment number is deduced from the context.
![Page 22: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/22.jpg)
Logical address and physical address
In the real mode, the physical address ( 物理地址 ) is the 20-bit address that is actually put on the address bus. This address can have a range of 00000H ~ FFFFFH.
The logical address ( 逻辑地址 ) consists of a segment address and an offset address. We’ll use logical address in programming. Segment address : offset address
![Page 23: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/23.jpg)
Segments and offsets A combination of a segment address and an
offset address access a memory location in the real mode. segment address ( 段地址 ): the beginning
address of any 64K-byte memory segment offset address ( 偏移地址 ): the location wi
thin the 64K-byte segment range, the distance or displacement ( 位移量 ) above the start of the segment
![Page 24: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/24.jpg)
Segment address In real mode, a segment is 64K in length and can
begin only at a 16-byte boundary. 16-byte boundary means that least significant four
bits are 0000b. This 16-byte boundary (such an address ends in 0H) is often called a paragraph ( 节 ).
Segment address : is most significant 16 bits of starting address
Segment number consists of the first four hex digits of its physical address.
![Page 25: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/25.jpg)
Offset address Offset is the distance from the first byte of the segment to the byte
being addressed. A segment is limited to 64K byte (16-bit) in the real mode,
therefore an offset address can range from 0000H to FFFFH. The offset address is added to the start of the segment to address
a memory location (physical address) within the memory segment.Segment address
Starting address
Offset address
Memory location
1000H
AB00H
1234H
10000H
AB000H
12340H
2000H
3405H
0100H
12000H
AE405H
12440H
![Page 26: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/26.jpg)
Conversion from logical address to physical address
Add the starting address of the segment and the offset
logical address segment address : offset
address
physical
address
1000H : 2000HAB00H : 3405H1234H : 0100H
12000HAE405H12440H
The physical address is calculated by shifting segment value one hex digit and adding the offset value.
![Page 27: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/27.jpg)
32-bit segmented memory model (from 386)
segment numbers are 16-bit long and used as an index into a table that contains the actual 32-bit starting addressing of the segment
add 32-bit offset and starting address to compute the “actual” 32-bit address
map the 32-bit address into physical addresses by paging mechanism
![Page 28: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/28.jpg)
Logical address
segment number(16bit) offset(32bit)
selector(选择器)
Global descriptor table (GDT)
global descriptor
( 描述符)
segment
line address
Linear address space(线性地址空间)
segment base address(段基地址)
![Page 29: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/29.jpg)
segment
line address
Linear address space(线性地址空间)
page
physical address
physical address spaceLine address
Dir.
table offset
Entry
page directory
page table
Entry
page
Paging is optional.If paging is not used, the linear address can be directly mapped into physical address.
![Page 30: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/30.jpg)
paging mechanism Layer of memory management performed
by the operating system and the Intel 80x86 CPU
Paging mechanism is transparent to programmer
Useful when logical address generated by the program exceeds the physical memory address
![Page 31: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/31.jpg)
for programmer
assigns different memory segments to code ,data and a system stack.
![Page 32: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/32.jpg)
Flat memory model
Programs will actually encode 32-bit addresses to logically reference locations in a single memory space where data and instructions are stored.
Is really a 32-bit segmented model with all segment registers containing the same value.
![Page 33: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/33.jpg)
2.2 PC Hardware: CPU
The X86 CPUs contain 16 program-visible registers.
Registers is internal storage location that can be accessed much more rapidly than a locations in RAM.
They are used during application programming and are specified by the instructions using their names.They are used to store information temporarily.
![Page 34: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/34.jpg)
Application registers
Multipurpose (or general-purpose) registers (通用寄存器)
Special-purpose registers (专用寄存器) Segment registers (段寄存器)
![Page 35: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/35.jpg)
IA-32 operating modes (操作模式) Protected mode (保护模式) Real address mode (实地址模式) System management mode SMM (系
统管理模式)
![Page 36: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/36.jpg)
Protected mode
Native state of IA-32. Cab directly execute 16-bit software in
protected, multitasking environment. Virtual 8086 mode (虚拟 8086 模
式)
![Page 37: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/37.jpg)
Real address mode
Implementing the programming environment of 8086 CPU with extension. Can switch to protected mode
Original mode following power-up or reset.
![Page 38: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/38.jpg)
System management mode SMM
This mode provides an operating system or executive with a transparent mechanism for implementing platform-specific functions such as power management and system security.
![Page 39: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/39.jpg)
Data registers / general registers
EAX (AX): accumulator 累加器 EBX (BX): base index 基址寄存器 ECX (CX): count 计数器 EDX (DX): data 数据寄存器
![Page 40: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/40.jpg)
8-, 16- and 32-bit registers Eight 8-bit general-purpose registers:
AH, AL, BH, BL, CH, CL, DH, DLH means high byte in the 16-bit registerL means low byte in the 16-bit registerAH and AL form AX, …
Eight 16-bit general-purpose registers:AX, BX, CX, DX, BP, DI, SI, SP
Eight 32-bit general-purpose registers:EAX, EBX, ECX, EDX, EBP, EDI, ESI, ESPE means 32-bit extended
![Page 41: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/41.jpg)
Special purpose registers
EIP (IP) : instruction pointer 指令指针 ESP (SP) : stack pointer 堆栈指针 EDI (DI): destination index 目的地址寄存
器 ESI (SI): source index 源地址寄存器 EBP (BP): base pointer基址指针
![Page 42: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/42.jpg)
EIP (IP)
EIP addresses the next instruction to be fetched in a section of memory defined as a code segment ( 代码段 ).
EIP points to the next instruction, but can be modified with a jump ( 跳转 ) or call ( 调用 ) instruction.
Cannot be directly accessed by programmer This register is IP (16 bits) in the real mode ( 实方
式 ) and EIP (32 bits) in the protected mode ( 保护方式 ).
![Page 43: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/43.jpg)
Pipelining mechanism (流水线机制)
Prefetching (预取) instruction Starting execution of an instruction be
fore it finishes execution of prior instructions
Increase effective processor speed
![Page 44: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/44.jpg)
ESP (SP)
ESP addresses an area of memory called stack. The stack ( 堆栈 ) memory is accessed using a
LIFO (last-in, first-out 后进先出 ) method. ESP points to the top of the stack, but will be
modified with a push or pop instruction. This register is SP (16 bits) in the real mode a
nd ESP (32 bits) in the protected mode.
![Page 45: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/45.jpg)
EBP(BP)
Mark a fixed slot in the stack This register is BP (16 bits) in the real
mode and EBP (32 bits) in the protected mode.
![Page 46: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/46.jpg)
EFLAGS ( 标志寄存器 ) EFLAGS indicate the condition of the microprocessor and c
ontrol its operation. The 16-bit CPU only contain a 16-bit FLAG register, which
has nine flags: CF, PF, AF, ZF, SF and OF are called conditional flags
( 条件、状态标志 ) indicate condition that resulted after an instruction wa
s executed. TF, DF, and IF are called control flags ( 控制标志 )
control the operation of instructions before they are executed.
![Page 47: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/47.jpg)
CF (carry flag 进位标志 ) Carry holds the carry after addition or the
borrow after subtraction. The carry flag also indicates error conditions as
dictated by some programs and procedures.
3A = 00111010+7C = 01111100
B6 = 10110110
CF=0
AA = 10101010+7C = 01111100
126 =100100110
CF=1
This is the carry flag.
![Page 48: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/48.jpg)
PF (parity flag 奇偶标志 ) Parity is a count of ones in a number expressed as even ( 偶数 )
or odd ( 奇数 ). Parity is a logic 0 for odd parity and a logic 1 for even parity. If a number contains odd binary one bits, it has odd parity. If a
number contains zero or even binary one bits, it has even parity.
3A = 00111010+7C = 01111100
B6 = 10110110
PF=0
3A = 10101010+78 = 01111000
B2 = 10110010
PF=1
![Page 49: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/49.jpg)
ZF (zero flag 零标志 ) The zero flag shows that the result of an arithm
etic ( 算术 ) or logic ( 逻辑 ) operation is zero. If the result is zero, ZF=1; If the result is not ze
ro, ZF=0.
3A = 00111010+7C = 01111100
B6 = 10110110
ZF=0
84 = 10000100+7C = 01111100
100 =100000000
ZF=1
Don’t worry. This is the carry flag.
![Page 50: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/50.jpg)
SF (sign flag 符号标志 ) The sign flag holds the arithmetic sign of the result
after an arithmetic or logic instruction executes. If SF=1, the sign bit (leftmost bit of a number) is set
( 置位 ) or negative ( 负 ); If SF=0, the sign bit is cleared ( 清除、清零 ) or positive ( 正 ) .
3A = 00111010+7C = 01111100
B6 = 10110110
SF=1
84 = 10000100+7C = 01111100
100 =100000000
SF=0
Don’t worry. This is the carry flag.
![Page 51: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/51.jpg)
OF (overflow flag 溢出标志 ) Overflow occurs when signed numbers are added
or subtracted. For unsigned operation, the overflow flag is ignored.
An overflow indicates that the result has exceeded the capacity of the machine.
3A = 00111010+7C = 01111100
B6 = 10110110
OF=1
AA = 10101010+7C = 01111100
126 =100100110
OF=0
58+124
182
-86+124
38
8-bit signed integer: -128 ~ +127
![Page 52: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/52.jpg)
Segment registers A segment register (16-bit) defines the starting addre
ss of a segment. CS: code segment DS: data segment SS: stack segment ES: extra segment (an additional data segment 附
加段 ) FS and GS: supplemental segment registers availab
le in the 80386 and above
![Page 53: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/53.jpg)
Numbers in segment registers
Real address memory mode Number in segment registers are segment
address. Segmented memory mode
Number in segment registers are selectors Flat memory mode
Irreverent to programmer All segment register have the same number.
![Page 54: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/54.jpg)
2.3 PC Hardware: Input/Output Devices
separate port address port address are distinct from ordinary
memory addresses, use instruction to output data or read data from these ports.
Memory-mapped input/output Use addresses in the regular memory
address space for I/O device access.
![Page 55: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/55.jpg)
80x86 architecture
separate port address 64K port addresses a typical I/O device uses three or eight
ports
![Page 56: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/56.jpg)
2.4 PC Software Software: refers to the programs or pr
ocedures executed by the hardware. System software (系统软件)
Operating system(操作系统) Application software (应用软件)
Text Editors (文本编辑器) Language Translators and Linker
![Page 57: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/57.jpg)
Operating system
Software to run other programs. DOS
Command line interface, prompt Windows
Graphical user interface Linux
Open codes
![Page 58: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/58.jpg)
Text Editors (文本编辑器) Software to create or modify text files that
are stored on the disk Text file is a collection of ASCII codes. Source code files are text file Notepad, Word processor, Edit
The extension name of assembly source file is .ASM
Example: test.asm
![Page 59: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/59.jpg)
Language Translators
Language translators are programs that translate a programmer’s source code into a form that can be executed by the computer. Interpreters(解释器) Compliers(编译器)
![Page 60: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/60.jpg)
Interpreters
Interpreters:directly decipher (解释) a source program Interpreter looks at a line of source c
ode and follows the instructions of that line
Slowly
![Page 61: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/61.jpg)
Compliers(编译器) Compliers: starts with source code and p
roduce object code that consists mostly of instructions to be executed by the intended CPU.
Assembler (汇编程序) : like a complier, translates assembly language into machine code. ML.exe
![Page 62: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/62.jpg)
How to use ML.EXE
![Page 63: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/63.jpg)
LINKER(连接软件) LINKER: link object code to make a p
rogram that can be executed. Link.exe
16-bit32-bit
![Page 64: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/64.jpg)
How to use link
![Page 65: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/65.jpg)
Debugger(调试器,调试软件) Debugger: allows a programmer to co
ntrol execution of a program, pausing after each instruction or at a preset breakpoint. Debug.exe Windbg.exe SoftIce.exe
![Page 66: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/66.jpg)
Integrated Development Environments IDE (集成开发环境)
Use a single interface to access an editor, a complier, and a linker. MASM32
![Page 67: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/67.jpg)
MASM32
![Page 68: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/68.jpg)
BUILD—buildc.bat 1
@echo off
if exist "%1.obj" del "%1.obj"if exist "%1.exe" del "%1.exe"
REM 汇编\masm32\bin\ml /c /coff "%1.asm"if errorlevel 1 goto errasm
![Page 69: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/69.jpg)
BUILD—buildc.bat 2
REM 连接\masm32\bin\Link /SUBSYSTEM:CONSOLE /OPT:NOREF "%1.obj"if errorlevel 1 goto errlink
dir "%1.*"goto TheEnd
![Page 70: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/70.jpg)
BUILD—buildc.bat 3
:errlinkecho Link errorgoto TheEnd
:errasmecho Assembly Errorgoto TheEnd
:TheEnd
pause
![Page 71: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/71.jpg)
After build…
![Page 72: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/72.jpg)
Run program
![Page 73: Chapter 2 Parts of a Computer System -----how the memory (内存) and CPU look to the assembly language programmer for IBM PC and compatible (兼容) systems which](https://reader030.vdocuments.us/reader030/viewer/2022032704/56649d625503460f94a43d62/html5/thumbnails/73.jpg)
Exercises
P30. Exercises 2.1-- 2 , 3 P34. Exercises 2.2--1, 2, 3 P34 Exercises 2.3--1, 2