13.3-depth understanding of the int, iret and stack
Checkpoint 13.1
(1) This road I think the key is to judge
add [bp+2],bx
This is the IP address changes, i.e. jump distance forwardly, i.e. in the range bx. bx sixteen-bit register, the range from -32768 to 32767, i.e. the maximum displacement of the transfer 32768
(2)
test program:
assume cs: code time segment db ' conversation ' , 0 time ends code segment start: mov ax, time mov ds, ax mov and 0 mov ax, 0b800h mov es, ax mov di, 12 * 160 mov bx, offset flag - flagend offset flag: cmp byte ptr DS: [SI], 0 je ok mov al, ds: [si] mov byte ptr es: [di], al mov byte ptr es: [di + 1 ] 2 inc si add di,2 int 7ch flagend:nop ok: mov ax,4c00h int 21h code ends end start
Interrupt routine:
the ASSUME CS: code code segment Start: ; program into designated idle region MOV AX, CS MOV DS, AX MOV Si, offset do7c MOV AX, 0 MOV ES, AX MOV DI, 200H MOV CX, offset do7cend - offset do7c CLD REP movsb ; set interrupt vector MOV AX, 0 MOV ES, AX MOV Word PTR ES: [7ch * . 4 + 2 ], 0 MOV Word PTR ES: [7ch * . 4 ], 200H MOV AX, 4c00h int 21H do7c: ; set IP position Push BP MOV BP, SP the Add SS: [BP+2],bx pop bp iret do7cend:nop code ends end start
13.4 BIOS and DOS interrupt routines provided
Typically a program stored in the ROM on the system board, called BIOS (Basic Input Output System), BIOS mainly comprising the following parts
- Hardware detection and initialization procedure
- External interrupt and internal interrupts interrupt routine
- A hardware device for I / O operations of the interrupt routine
- And other hardware-related interrupt routine
13.5 BIOS and DOS interrupt the installation process routine
BIOS and DOS interrupt the installation process routine
- After boot, the CPU a powered, initialization (CS) = 0FFFFH, (IP) = 0, automatically will be from FFFF: unit 0 begins execution, it is noted that FFFF: 0 This address is among system-wide BIOS, , so we can not go change. In FFFF: 0 Department has a jump instructions, CPU after execution of this instruction, the system will switch to perform hardware detection and initialization procedure in the BIOS
- Initialization program to build BIOS supports interrupt vector, then interrupt routine entry address will be provided by the BIOS of them registered in the interrupt vector table
- After the hardware detection and initialization is complete, to call int 19h to boot the operating system after the computer will be handed over to the operating system controls, where the need to pay attention to that is to go to call int 19h boot the operating system starts, so int 19h interrupt routines can not be provided by DOS
- After the DOS is started, in addition to performing other work, it will also provide interrupt routines into memory, and to establish the corresponding interrupt vector
Checkpoint 13.2
(1) error, can not be changed.
(2) error, hardware should be the BIOS interrupt routine
13.6 BIOS interrupt routine application
In the display buffer B8000H ~ B8FFFFH 32KB altogether space for 80 * 25 character mode color display buffer. A screen content accounts for 4000 bytes. Display buffer a total of eight, each 4KB page.
the ASSUME CS: code code segment ; set the cursor position mov AH, 2 ; set cursor mov BH, 0 ; page 0 mov DH, . 5 ; DH release number mov DL, 12 is ; column number int 10H ; displaying characters at the cursor position mov AH, . 9 ; the character displayed at the cursor position MOV Al, ' B ' ; characters in mov bl, 11001010b; color properties MOV BH, 0 ; page 0 MOV CX, . 3 ; the number of repeated characters int 10H MOV AX, 4c00h int 21H code ends End
13.7 DOS interrupt routine application
mov ah, 4ch; program returns (21h indicates interrupt subroutine calling number No. routine 4ch) MOV Al, 0 ; Return value int 21h
int 21h interrupt routine character string displayed at the cursor function
ds: dx to a string; required to display the string "$" character as the end MOV AH, 9 ; function 9 shows the display at the cursor strings int 21H
Programming 12 shown in row 5 'Welcome to masm!'
CS the ASSUME: code Data segment DB ' available for purchase to MASM! ' , ' $ ' Data ends code segment Start: ; set the cursor position mov AH, 2 mov BH, 0 mov DH, . 5 mov DL, 12 is int 10H ; display string mov AX, Data MOV DS, AX MOV DX, 0 MOV AH, . 9 int 21H MOV AX, 4c00h int 21H code ends End Start
Experiment 13 written application interrupt routine
(1) prepare and install int 7ch interrupt routines, functions to display a character string with the end of the 0, 0 interrupt routine is mounted: at 200
Parameters: (dh) = row number, (dl) = column number, (cl) = color, ds: si points to the first address string
test program
assume cs:code data segment db 'Welcome to masm!BIU',0 data ends code segment start: mov dh,12 mov dl,30 mov cl,2 mov ax,data mov ds,ax mov si,0 int 7ch mov ax,4c00h int 21h code ends end start
中断例程
assume cs:code code segment start: ;将程序写入0:200h mov ax,cs mov ds,ax mov si,offset func mov ax,0 mov es,ax mov di,200h mov cx,offset funcend-offset func;程序长度 cld rep movsb ;程序入口写入中断向量表中 mov ax,0 mov es,ax mov word ptr es:[7ch*4+2],0 mov word ptr es:[7ch*4],200h mov ax,4c00h int 21h func: push ax push di push es ;显示缓冲区地址 mov ax,0b800h mov es,ax ;将已知条件转换为正确的显存地址 mov al,160 mul dh mov di,ax dec dl mov dh,0 add dx,dx add di,dx show: ;判断是否遇到末尾的0 cmp byte ptr ds:[si],0 je ok ;将显示信息写入显示缓冲区 mov al,ds:[si] mov byte ptr es:[di],al mov es:[di+1],cl inc si add di,2 jmp show ok: ;结束 pop es pop di pop ax iret funcend:nop code ends end start
CS:IP和SS:SP在int和iret前后变化
入栈标志寄存器,CS,IP。SP=FFFAH
SS为当前段地址,CS:IP为空闲区域地址
(2)在屏幕中间显示80个'!'
测试程序
assume cs:code code segment start: mov ax,0b800h mov es,ax mov di,160*12 mov bx,offset s-offset se mov cx,80 s: mov byte ptr es:[di],'!' add di,2 int 7ch se: nop mov ax,4c00h int 21h code ends end start
中断程序
assume cs:code code segment start: ;将程序写入0:200h mov ax,cs mov ds,ax mov si,offset func mov ax,0 mov es,ax mov di,200h mov cx,offset funcend-offset func;程序长度 cld rep movsb ;程序入口写入中断向量表中 mov ax,0 mov es,ax mov word ptr es:[7ch*4+2],0 mov word ptr es:[7ch*4],200h mov ax,4c00h int 21h func: push bp mov bp,sp dec cx jcxz ok add ss:[bp+2],bx ok: pop bp iret funcend:nop code ends end start
(3)下面的程序,分别在屏幕的第2,4,6,8行显示4句英文诗
assume cs:code code segment s1: db 'Good,better,best,','$' s2: db 'Never let it rest,','$' s3: db 'Till good is better,','$' s4: db 'And better,best.','$' s: dw offset s1,offset s2,offset s3,offset s4 row: db 2,4,6,8 start: mov ax,cs mov ds,ax mov bx,offset s mov si,offset row mov cx,4 ok: mov bh,0 mov dh,ds:[si] mov dl,0 mov ah,2 int 10h mov dx,ds:[bx] mov ah,9 int 21h inc si add bx,2 loop ok mov ax,4c00h int 21h code ends end start