Chapter 1 lab task: Compile the program for handling the No. 0 interruption

Source: Internet
Author: User

Question: Compile the handling of No. 0 interruptionsProgramTo display the string "Divide Error!" in the middle of the screen when division overflow occurs !", Then return to DoS

Requirement: Follow up debugging carefully.

Source code:

Assume Cs: codesg </P> <p> codesg segment <br/> Start: <br/>; Set DS: [Si] points to the <SPAN class = 'wp _ keywordlink '> Code </span> <br/> mov ax, CS <br/> mov ds, ax <br/> mov Si, offset do0; offset do0 is the offset address from program start to do0 to Si </P> <p> mov ax, 0000 <br/> mov es, ax <br/> mov Di, 0200 h; Set ES: [di] points to the target location of the program to be copied </P> <p> mov CX, offset do0end-offset do0; sets the number of replication cycles, here, the number of cycles is to copy the start address of the program to the end address of the Program </P> <p> CLD; set Si and Di to increase by 1 </P> <p> rep movsb; to replicate the cycle Process </P> <p>; set the interrupt vector table. Because the number N is interrupted, the segment address is placed in the unit 0000: [N * 4, the offset address is placed in the cell 0000: [N * 4 + 2. Therefore, the segment address of the program to be interrupted is placed in the unit of 0000: [N * 4], and the offset address is set to 0000: [N * 4 + 2. <Br/> mov word ptr es: [0*4], 200 h <br/> mov word ptr es: [0*4 + 2], 0000 </P> <p>; here is the written test program. Of course, it can also be written and executed during debug <br/>; MoV ax, 1000 h <br/>; moV BH, 1 <br/>; Div BH </P> <p> mov ax, 4c00h <br/> int 21 h </P> <p>; here is the Interrupt Processing Program <br/> do0: <br/>. At the beginning, it is a string that defines the output and cannot be executed, therefore, the system jumps to do0start and runs <br/> JMP short do0start <br/> db'divide error! '</P> <p> do0start: <br/> mov ax and CS <br/> mov DS and ax <br/> mov Si, 0202 h; Set DS: [Si] points to the defined string 'divide error! '</P> <p> mov ax, 0b800h <br/> mov es, ax <br/> mov Di, 12*160 + 36*2; Set ES: [di] pointing to the center of the screen </P> <p> mov CX, 13; set the number of cycles for displaying strings </P> <p> S: <br/> mov Al, DS: [Si] <br/> mov ah, 02 h; set the displayed font color <br/> mov ES: [di], ax <br/> Add Di, 2 <br/> Inc Si <br/> loop S </P> <p> mov ax, 4c00h <br/> int 21 h <br/> do0end: <br/> NOP <br/> codesg ends <br/> end start </P> <p>

debugging process:

-R </P> <p> AX = 0000 BX = 0000 Cx = 005c dx = 0000 sp = 0000 BP = 0000 Si = 0000 di = 0000 <br/> DS = 0b75 es = 0b75 Ss = 0b85 cs = 0b85 IP = 0000 NV up ei pl nz Na Po NC <br/> 0b85: 0000 8cc8 movax, CS <br/>-u </P> <p> 0b85: 0000 8cc8 movax, CS <br/> 0b85: 0002 8ed8 movds, ax <br/> 0b85: 0004 be2800 movsi, 0028 <br/> 0b85: 0007 b80000 movax, 0000 <br/> 0b85: 000a 8ec0 moves, ax <br/> 0b85: 000c bf0002 movdi, 0200 <br/> 0b85: 000f b93300 movcx, 0033 <br /> 0b85: 0012 fc cld <br/> 0b85: 0013 F3 repz <br/> 0b85: 0014 A4 movsb <br/> 0b85: 0015 26 ES: <br/> 0b85: 0016 c70600000002 movword PTR [0000], 0200 <br/> 0b85: 001c 26 ES: <br/> 0b85: 001d c70602000000 movword PTR [0002], 0000 <br/>-T </P> <p> AX = 0b85 BX = 0000 Cx = 005c dx = 0000 sp = 0000 BP = 0000 Si = 0000 di = 0000 <br /> DS = 0b75 es = 0b75 Ss = 0b85 cs = 0b85 IP = 0002 NV up ei pl nz Na Po NC <br/> 0b85: 0002 8ed8 movds, ax <br/>-T </ P> <p> AX = 0b85 BX = 0000 Cx = 005c dx = 0000 sp = 0000 BP = 0000 Si = 0000 di = 0000 <br/> DS = 0b85 es = 0b75 SS = 0b85 cs = 0b85 IP = 0004 NV up ei pl nz Na Po NC <br/> 0b85: 0004 be2800 movsi, 0028 <br/>-T </P> <p> AX = 0b85 BX = 0000 Cx = 005c dx = 0000 sp = 0000 BP = 0000 Si = 0028 di = 0000 <br /> DS = 0b85 es = 0b75 Ss = 0b85 cs = 0b85 IP = 0007 NV up ei pl nz Na Po NC <br/> 0b85: 0007 b80000 movax, 0000 <br/>-T </P> <p> AX = 0000 BX = 0000 Cx = 005c dx = 0000 sp = 0000 BP = 0000 Si = 0028 di = 0000 <br/> DS = 0b85 es = 0b75 Ss = 0b85 cs = 0b85 IP = 000a NV up ei pl nz Na Po NC <br/> 0b85: 000a 8ec0 moves, ax <br/>-T </P> <p> AX = 0000 BX = 0000 Cx = 005c dx = 0000 sp = 0000 BP = 0000 Si = 0028 di = 0000 <br /> DS = 0b85 es = 0000 Ss = 0b85 cs = 0b85 IP = 000c NV up ei pl nz Na Po NC <br/> 0b85: 000c bf0002 movdi, 0200 <br/>-T </P> <p> AX = 0000 BX = 0000 Cx = 005c dx = 0000 sp = 0000 BP = 0000 Si = 0028 di = 0200 <br /> DS = 0b85 es = 0000 Ss = 0b85 cs = 0b85 IP = 000f NV up ei pl nz Na Po NC <br/> 0b85: 000f b93300 movcx, 0033 <br/>-T </P> <p> AX = 0000 BX = 0000 Cx = 0033 dx = 0000 sp = 0000 BP = 0000 Si = 0028 di = 0200 <br /> DS = 0b85 es = 0000 Ss = 0b85 cs = 0b85 IP = 0012 NV up ei pl nz Na Po NC <br/> 0b85: 0012 fc cld <br/>-T </P> <p> AX = 0000 BX = 0000 Cx = 0033 dx = 0000 sp = 0000 BP = 0000 Si = 0028 di = 0200 <br/> DS = 0b85 es = 0000 Ss = 0b85 cs = 0b85 IP = 0013 NV up ei pl nz Na Po NC <br/> 0b85: 0013 F3 repz <br/> 0b85: 0014 A4 movsb <br/>-P </P> <p> AX = 0000 BX = 0000 Cx = 0000 dx = 0000 sp = 0000 BP = 0000 Si = 005b di = 0233 <br/> DS = 0b85 es = 0000 Ss = 0b85 cs = 0b85 IP = 0015 NV up ei pl nz Na Po NC <br/> 0b85: 0015 26 ES: <br/> 0b85: 0016 c7060042602 movword PTR [0000], 0200 ES: 0000 = 1068 <br/>-T </P> <p> AX = 0000 BX = 0000 Cx = 0000 dx = 0000 sp = 0000 BP = 0000 Si = 005b di = 0233 <br/> DS = 0b85 es = 0000 Ss = 0b85 cs = 0b85 I P = 001c NV up ei pl nz Na Po NC <br/> 0b85: 001c 26 ES: <br/> 0b85: 001d c70602000000 movword PTR [0002], 0000 ES: 0002 = 00a7 <br/>-T </P> <p> AX = 0000 BX = 0000 Cx = 0000 dx = 0000 sp = 0000 BP = 0000 Si = 005b di = 0233 <br/> DS = 0b85 es = 0000 Ss = 0b85 cs = 0b85 IP = 0023 NV up ei pl nz Na Po NC <br/> 0b85: 0023 b8004c movax, 4c00 <br/>-T </P> <p> AX = 4c00 BX = 0000 Cx = 0000 dx = 0000 sp = 0000 BP = 0000 Si = 005b di = 0233 <br /> DS = 0b85 es = 0000 Ss = 0b85 cs = 0b85 IP = 0026 NV up ei pl nz Na Po NC <br/> 0b85: 0026 cd21 int21 <br/>-D :0200 </P> <p> :0200 EB 0d 44 49 56 49 44 45-20 45 52 52 4f 52 21 8C .. divide Error !. <Br/> :0210 C8 8e D8 be 02 B8 00-b8 8e C0 BF C8 07 B9 0d ................ <br/> running :0220 00 8A 04 B4 02 26 89 05-83 C7 02 46 E2 F3 B8 00 ..... &..... F .... <br/> 4C CD 21 00 00 00 00 00-00 00 00 00 00 00 00 00 00 00 00 l .!............. <Br/> Jun :0240 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ <br/> Jun :0250 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ <br/> 0000: 0260 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ <br/> 0000: 0270 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ <br/>-T

Test procedure:

Then write the following command in debug and execute

MoV ax, 1000 h <br/> mov BH, 1 <br/> Div BH

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.