another data segment, destination for string operationgs
SP
stack pointer
BP
frame base pointer
SI
source index
DI
destination index
IP
instruction pointer
IP increment after running each instruction. CALL REt, JMP can modify it.
I/O
Only 1024 I/O addresses
Accessed with special instruction (IN, OUT)
Example: write a byte to line printer;
123456789101112131415161718
#define DATA_PORT 0x378#define STATUS_PORT 0x379#define BUSY 0x80#define CONTROL_PORT 0x37A#define STROBE 0x01voidlpt_putc(intc){/* wait for printer to consume previous byte */while((inb(STATUS_PORT)&BUSY)==0);/* put the byte on the parallel lines */outb(DATA_PORT,c);/* tell the printer to look at the data */outb(CONTROL_PORT,STROBE);outb(CONTROL_PORT,0);}
MMIO
Use normal physical memory address
Limited size of I/O address space
No need instructions
System controller routes to appropriate device
Work like “magic” memory
Addressed and accessed like memory, but does not behave like memory
Reads and writes can have “side effects”
Read results can change due to external events
side effect 是指:访问I/O寄存器时,不仅仅会像访问普通内存一样影响存储单元的值,更重要的是它可能改变CPU的I/O端口电平、输出时序或CPU对I/O端口电平的反应等等,从而实现CPU的控制功能。CPU在电路中的意义就是实现其side effect 。举个例子,有些设备的中断状态寄存器只要一读取,便自动清零。
Translate virtual address to physical address
pa = va + seg*16. e.g. set CS = 4096 to execute starting at 65536
Can’t use the 16-bit address of a stack variable as a pointer
0x66/0x67 can switch between 16-bit and 32bit
For example:
_main:// prologuepushl%ebpmovl%esp,%ebp// esp: always the bottom of stack, ebp: 用来保存上个func的esp, 已被返回时使用// bodypushl$8// parametercall_faddl$1,%eax//epiloguemovl%ebp,%esppopl%ebpret_f:// prologuepushl%ebpmovl%esp,%ebp// bodypushl8(%esp)call_g// epiloguemovl%ebp,%esppopl%ebpret_g:// prologuepushl%ebpmovl%esp,%ebp// save %ebxpushl%ebx// bodymovl8(%ebp),%ebx// why %ebp not %esp, because you push %ebx, then %esp will be added 4addl$3,%ebxmovl%ebx,%eax// restore %ebxpopl%ebx//epiloguemovl%ebp,%esppopl%ebpret