Note that there are programs and test programs. For example, exp1303.asm refers to Chapter 13's third question. exp1303. ASM refers to the test of exp1303 program...
; Exp1301.asm
Install the 7ch Interrupt Routine
Function: calculates the square of a word number.
;
;
Assume Cs: Code
Code segment
Start:
; Copy the code to a non-system management area
MoV ax, CS
MoV ds, ax
MoV Si, offset sqr; copy from sqr of CS segment to 0: 200
MoV ax, 0
MoV es, ax
MoV Di, 200 h
MoV CX, offset sqrend-offset sqr; CX is the number of Code bytes to be copied
ClD
Rep movsb; call movsb to copy ES: [di] bytes to DS: [Si]
; Set the interrupt vector
MoV ax, 0
MoV es, ax
MoV word ptr es: [7ch * 4], 200 h; Use Word PTR to indicate that a word is to be copied
MoV word ptr es: [7ch * 4 + 2], 0
MoV ax, 3
Int 7ch
MoV ax, 4c00h
Int 21 h
Sqr:
Mul ax
Iret
Sqrend:
NOP
Code ends
End start
; Exp1302.asm
Install the 7ch Interrupt Routine
Function: Display strings starting with DS: [Si ].
Assume Cs: Code
Data Segment
DB "Welcome to MASM! ", 0
Data ends
Code segment
Start:
; Copy the code to a non-system management area
MoV ax, CS
MoV ds, ax
MoV Si, offset int7c; copy from int7c of CS segment to 0: 200
MoV ax, 0
MoV es, ax
MoV Di, 200 h
MoV CX, offset int7cend-offset int7c
ClD
Rep movsb
; Set the interrupt vector
MoV ax, 0
MoV es, ax
MoV word ptr es: [7ch * 4], 200 h
MoV word ptr es: [7ch * 4 + 2], 0
; DH = number of rows, DL = strong, CL = color, DS: Si points to the first address
MoV DH, 10
MoV DL, 10
MoV Cl, 2
MoV ax, Data
MoV ds, ax
MoV Si, 0
Int 7ch
MoV ah, 01 H
Int 21 h
MoV ax, 4c00h
Int 21 h
Int7c:
PUSH AX
Push BX
Push CX
Push DX
Push es
The address y = 160 * (number of rows-1) + number of columns * 2-2, b800: Y
; Cyclically write the strings in the parameters into the memory of the video card, and return the results if 0 is detected.
; BX = 160 * (number of rows-1)
Sub DH, 1 h
MoV Al 160
Mul DH
MoV BX, ax; BX is the offset value calculated based on the number of rows
; AX = number of columns * 2-2
MoV Al, 2
Mul DL
Sub ax, 2; offset value calculated based on the number of Columns
Add Bx, ax; The sum of the number of rows and columns exists in BX.
MoV ax, 0b800h
MoV es, ax
MoV DL, Cl; Save the font color attribute
MoV CH, 0
S_show_str:
MoV Cl, DS: [Si]
MoV ES: [BX], Cl
Jcxz OK _show_str
MoV ES: [bx + 1], DL
INC Si
Add Bx, 2
JMP short s_show_str
OK _show_str:
Pop es
Pop DX
Pop CX
Pop BX
Pop ax
Iret
Int7cend:
NOP
Code ends
End start
; Exp1302t. ASM
; Test procedure of the previous program
; Test 7ch interrupt, display string
Assume Cs: Code
Data Segment
DB "Welcome to MASM 6.11! ", 0
Data ends
Code segment
Start:
MoV ax, Data
MoV ds, ax
MoV DH, 10
MoV DL, 10
MoV Cl, 2
MoV Si, 0
Int 7ch
MoV ax, 4c00h
Int 21 h
Code ends
End start
; Exp1303.asm
Install the 7ch Interrupt Routine
Function: converts all strings starting with DS: Si and ending with 0 to uppercase.
Assume Cs: Code
Data Segment
DB "Welcome to MASM! ", 0
Data ends
Code segment
Start:
; Copy the code to a non-system management area
MoV ax, CS
MoV ds, ax
MoV Si, offset int7c; copy the interrupt code from int7c of CS segment
MoV ax, 0
MoV es, ax
MoV Di, 200 h
MoV CX, offset int7cend-offset int7c
ClD
Rep movsb
; Set the interrupt vector
MoV ax, 0
MoV es, ax
MoV word ptr es: [7ch * 4], 200 h
MoV word ptr es: [7ch * 4 + 2], 0
MoV ax, Data
MoV ds, ax
MoV Si, 0
Int 7ch
MoV ah, 01 H
Int 21 h
MoV ax, 4c00h
Int 21 h
Int7c:
; Compares the characters starting with DS: [Si]. If it is a lowercase letter, converts it to uppercase.
Because it ends with 0, jcxz can be used here
The lower-case letters are in the range of 61h ~ 7ah, 20 h less capital letters than it
And can be judged by JB 61 H and Ja 7ah, and cyclically
Push CX
Push Si
MoV CH, 0
Loop1:
MoV Cl, DS: [Si]
Jcxz loop1end
CMP Cl, 61 H
JB notcase
CMP Cl, 7ah
Ja notcase
Sub Cl, 20 h
MoV DS: [Si], Cl
INC Si
JMP short loop1
Notcase:
INC Si
JMP short loop1
Loop1end:
Pop Si
Pop CX
Iret
Int7cend:
NOP
Code ends
End start
; Exp1303t. ASM
Test exp1303. Use the 7ch interrupt to convert all lowercase letters of DS: [Si] To uppercase letters.
; Show_str is shown below
Note: Using and bytr PTR [Si] And 110111b to uppercase can simplify the process.
Assume Cs: Code
Data Segment
DB "Welcome to MASM! ", 0
Data ends
Stack segment
Stack ends
Code segment
Start:
MoV ax, Data
MoV ds, ax
MoV Si, 0
Int 7ch
MoV ax, Data
MoV ds, ax
MoV Si, 0
MoV DH, 2
MoV DL, 3
MoV Cl, 2
Call show_str
MoV ah, 01 H
Int 21 h
MoV ax, 4c00h
Int 21 h
; Name: show_str
Function: Specify the position and color to display a string ending with 0
; Parameter: (DH) = row number (0--24), (DL) = column number (0--79)
; (CL) = color, DS: Si points to the first address of the string
; Return: None
Show_str:
PUSH AX
Push BX
Push CX
Push DX
Push es
The address y = 160 * (number of rows-1) + number of columns * 2-2, b800: Y
; Cyclically write the strings in the parameters into the memory of the video card, and return the results if 0 is detected.
; BX = 160 * (number of rows-1)
Sub DH, 1 h
MoV Al 160
Mul DH
MoV BX, ax; BX is the offset value calculated based on the number of rows
; AX = number of columns * 2-2
MoV Al, 2
Mul DL
Sub ax, 2; offset value calculated based on the number of Columns
Add Bx, ax; The sum of the number of rows and columns exists in BX.
MoV ax, 0b800h
MoV es, ax
MoV DL, Cl; Save the font color attribute
MoV CH, 0
S_show_str:
MoV Cl, DS: [Si]
MoV ES: [BX], Cl
Jcxz OK _show_str
MoV ES: [bx + 1], DL
INC Si
Add Bx, 2
JMP short s_show_str
OK _show_str:
Pop es
Pop DX
Pop CX
Pop BX
Pop ax
RET
Code ends
End start
; Exp1304.asm
; Use BIOS interrupt and DOS interrupt
Assume Cs: code, DS: Data
Data Segment
DB 'Welcome to ASM! ',' $'
Data ends
Stack segment
Stack ends
Code segment
Start:
; Call BIOS Interrupt Routine
MoV ah, 2
MoV BH, 0
MoV DH, 5
MoV DL, 12
Int 10 h
MoV ah, 9
MoV Al, 'A'
MoV BL, 11001010b
MoV BH, 0
MoV CX, 3
Int 10 h
; Call dos Interrupt Routine
MoV ax, 4c00h
Int 21 h
Code ends
End start
; Exp1305.asm
Assume Cs: code, DS: Data
Data Segment
DB 'Welcome to ASM! ',' $'
Data ends
Stack segment
Stack ends
Code segment
Start:
MoV ah, 2; BIOS light indicator routine
MoV BH, 0; Page 0th
MoV DH, 5; DH row number
MoV DL, 12; dl column number
Int 10 h
MoV ax, data;
MoV ds, ax
MoV dx, 0; DS: DX points to the first address of the string data: 0
MoV ah, 9; Child Program of Interrupt Routine No. 21
Int 21 h
MoV ax, 4c00h
Int 21 h
Code ends
End start
; Exp1306.asm
; Use int 7ch instead of loop function, BX is the offset address, CX is the number of cycles
; 7ch installation interrupted
The key is to convert the Cs: IP address to be jumped to by the current program after int7ch.
When the call is interrupted, several important registers will press the stack. The sequence is: Mark register, Cs, IP
The principle here is to change the IP value in the stack to the starting address of the loop when calling the interrupt 7 CH, and then return the interrupt
; Understand the above two points, this question is OK, otherwise the access will go wrong, encountering the operating system's restricted area
Assume Cs: Code
Code segment
Start:
; Copy the code to the 0: 200 memory Zone
MoV ax, CS
MoV ds, ax
MoV Si, offset int7c
MoV ax, 0
MoV es, ax
MoV Di, 200 h
MoV CX, offset int7cend-offset int7c
ClD
Rep movsb
; Installation interrupt variable
MoV ax, 0
MoV es, ax
MoV word ptr es: [7ch * 4], 200 h
MoV word ptr es: [7ch * 4 + 2], 0
MoV ax, 4c00h
Int 21 h
Int7c:
Push BP
MoV bp, SP
Dec CX
Jcxz offset int7cok
Sub [bp + 2], BX; IP
Int7cok:
Pop BP
Iret
Int7cend:
NOP
Code ends
End start
; Exp1306t
; Use int 7ch instead of loop function, BX is the offset address, CX is the number of cycles
; Display 80' in the middle of the screen '! '
Assume Cs: Code
Code segment
Start:
MoV ax, 0b800h
MoV es, ax
MoV Di, 160*12; 12 rows, right in the middle of the 80*24 Screen
MoV BX, offset se-offset s
MoV CX, 80
S:
MoV byte ptr es: [di], '! '
MoV byte ptr es: [di + 1], 2
Add Di, 2
Int 7ch
SE:
NOP
MoV ax, 4c00h
Int 21 h
Code ends
End start
; Exp1307.asm
Directly address the table and call the bios, DOS interrupt display string
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
Start:
MoV ax, CS
MoV ds, ax
MoV BX, offset s
MoV Si, offset row
MoV CX, 4
OK:
BiOS cursor placement
MoV BH, 0
MoV DH, [Si]
MoV DL, 0
MoV ah, 2
Int 10 h
; Dos display string routine
MoV dx, [BX]
MoV ah, 9
Int 21 h
INC Si; row is dB, one byte
Add Bx, 2; Because DW occupies two bytes, add 2
Loop OK
MoV ax, 4c00h
Int 21 h
Code ends
End start
In this chapter, I have learned more about interrupt. Through debugging and observation, I can better understand the changes in the stack and various registers when I call the int and iret commands...