³oÓ¼ÐÃD¬O²¤Æ«áªº¡A¥¦¨ä¹ê¬O«ü¡u¦b DOS µ{¦¡¤¤¨Ï¥Î¤T¤Q¤G¦ì¤¸ 80386 «ü¥O¤Î¼È¦s¾¹¡v¡CDOS ¬O¤Q¤»¦ì¤¸ªº§@·~¨t²Î¡A¬O§_¯uªº¯à¨Ï¥Î¤T¤Q¤G¦ì¤¸ªº 80386 CPU «ü¥O©O¡Hµª®×¬OªÖ©wªº¡A¥un¥J²Ó³]©w¦n©w§}¤è¦¡¡A¨Ã³B²z¦n¼È¦s¾¹ªº¼e«×°ÝÃD¡A·Ó¼Ë¥i¥H¨Ï¥Î¤T¤Q¤G¦ì¤¸ªº 80386¡A¬Æ¦Ü§ó°ª¶¥ªº CPU¡C
¨Æ¹ê¤W¡A^¯Sº¸¦Û¥Á°ê 74 ¦~¡]¦è¤¸ 1985 ¦~¡^±À¥X 80386 ¤§«á¡A¦b±µ¤U¨Óªº¤G¤Q¦~¤º³°Äò±À¥X 80486¡BPentium¡A¤@ª½¨ì Pentium 4¡B Pentium M¡A³o¤@¨t¦Cªº¤T¤Q¤G¦ì¤¸ CPU ¦XºÙ¬°¡uIA¡Ð32¡v¡]Intel Architecture 32-bit¡^¡C¥t¥~¨ä¥L¼t°Ó³c°âªº CPU¡A¥]§t AMD ªº Am386¡BAm486¡K¡K¤@ª½¨ì Athlon XP¡A¥H¤Î Cyrix¡]ÁÉ·ç§J´µ¡^¤½¥qªº Cyrix 486SRX2¡BCyrix MII µ¥¡A³£ºâ¬O¡uIA¡Ð32¡v¤¤ªº¤@û¡C
IA¡Ð32 ¬O¤@ºØ«ü¥O¶°¬[ºc¡A¦]¦¹¼s¸q¤W¨Ó»¡¡Ax86 ®a±Úªº¡u«e½ú¡v¡A¨Ò¦p 8086¡B8088¡B80286¡A¤]·|²Å¦X¦¹ºØ¬[ºc¡C^¯Sº¸ªº¨Ï¥Î¤â¥U¤W¡A¤]±N³o¤TºØ CPU ÂkÃþ©ó IA¡Ð32¡C¦ý³o«Ü®e©öÅý¤H²V²c¡A²¦³º³o¤TªÌ¬O¤Q¤»¦ì¤¸ªº CPU¡C¥»³¹©Ò»¡ªº IA¡Ð32 ¨Ã¤£¥]§t³o¤TºØ CPU¡C
¤T¤Q¤G¦ì¤¸ªº CPU ¤£¶È¯à°õ¦æ 8086/8088 ªº«ü¥O¡A¦P®É¤S¼W¥[¤@¨Ç·sªº«ü¥O¡A¤]±j¤Æ¬Y¨Ç«ü¥O¡CÁ|¨Ò¨Ó»¡¡A8086/8088 CPU ªº¼ªk«ü¥O¡AMUL¡A³Q¼¼Æ³Ì¦h¬°¤Q¤»¦ì¤¸¡A¼¼Æ¤]¬O¤Q¤»¦ì¤¸¡A©Ò±oªº¼¿n³Ìªø´N¬O¤T¤Q¤G¦ì¤¸¡C¦ý¦pªG§ï¥Î 80386 ©Î¬O¨ä¥L IA¡Ð32 ªº CPU¡A´N¯à¨Ï¥Î±j¤Æ«áªº MUL «ü¥O¡A¥¦¥i¥H¶i¦æ¤T¤Q¤G¦ì¤¸ªº¼Æ¼¥H¤T¤Q¤G¦ì¤¸ªº¼Æ¡A³Ì¦h¥i¹F¤»¤Q¥|¦ì¤¸¡C
°£¤F¹Bºâ¯à¤O¼W±j¥~¡A§ó°ªµ¥¯Åªº CPU «ü¥O¶°¤ñ 8086/8088 «ü¥O¶°ÁÙ¦h¡A¨Ï¥Î¤W§ó¤è«K¡A¦P®É MASM 6.1 ¤]¤ä´© Pentium «ü¥O¡C°ò©ó¤WzºØºØì¦]¡A¨º»ò¬°¦ó¤£¨Ï¥Î 80386 ©Î§ó°ª¶¥ªº CPU «ü¥O©O¡H¥»³¹¦]¦¹½Ï¥Í¡C
¦b DOS µ{¦¡¤¤n¨Ï¥Î 80386 «ü¥O¡A¶·ª`·N©³¤Uªº¨Æ¶µ¡C
ML.EXE ¦b²ÕĶ®É¡A¹w³]¨Ï¥Î 8086/8088 «ü¥O¶°¡A¦pªGn¨Ï¥Î 80386 «ü¥O¶°¡A¨º´N¥²¶·¦bì©lµ{¦¡¶}©l¤§³B«Å§i ¡u.386¡v¡A¬Æ¦Ü¤]¥i¥H³]©w¡u.486¡v©Î§ó°ª¶¥ªº CPU «ü¥O¶°¡C³o¨Ç°²«ü¥O³£¤w¦b²Ä¤³¹´£¹L¡A½Ð«ö³oùؾ\Ū¡C
ÁöµM¨Ï¥Î¤T¤Q¤G¦ì¤¸ªº 80386 CPU «ü¥O¡A¦ý¬O DOS ªº©w§}¤è¦¡¤´¬O¤Q¤»¦ì¤¸¡A©Ò¥H¨ä°Ï¬q¤´n³]¬°¤Q¤»¦ì¤¸ªº°Ï¬q¡C¦³¨âºØ¤è¦¡¯à³]©w°Ï¬q¬O¤Q¤»¦ì¤¸©Î¤T¤Q¤G¦ì¤¸¡G
①¡G¡u.MODEL¡v°²«ü¥O¬O¥Î¨Ó³]©w°O¾ÐÅé¼Ò¦¡ ( memory model )¡B»y¨¥Ãþ«¬ ( language type ) µ¥¡A°£¦¹¤§¥~¡AÁÙ¦³¶µ¥\¯à¡C¥¦»P¡u.386¡vªº¶¶§Ç¯à¨M©w¨Ï¥Î°Ï¬q¬O¤Q¤»¦ì¤¸¡A§í©Î¤T¤Q¤G¦ì¤¸¡C
⑴¡G¡u.MODEL¡v¦b«e¡A¡u.386¡v¦b«á¡A¨º»ò·|¨Ï¥Î¤Q¤»¦ì¤¸ªº°Ï¬q¡A³o¬O¦b DOS ¨t²Î¤¤ªºµ{¦¡¨Ï¥Îªº¤è¦¡
⑵¡G¡u.386¡v¦b«e¡A¡u.MODEL¡v¦b«á¡A¨º»ò·|¨Ï¥Î¤T¤Q¤G¦ì¤¸ªº°Ï¬q¡A³o¬O¦b Windows ¨t²Î¤¤ªºµ{¦¡¨Ï¥Îªº¤è¦¡¡C
②¡G¦pªG¤£¥Î¤W±¤è¦¡¨M©w°Ï¬q¬O¤Q¤»¦ì¤¸ÁÙ¬O¤T¤Q¤G¦ì¤¸¡A¨º»ò¤]¥i¥H¥Î§¹¾ãªº¤è¦¡«Å§i°Ï¬q¡C¨º´N¬O¥Î SEGMENT/ENDS °²«ü¥O¡A¨ä¤¤¥i¥H³]©w USE16 ¨M©w¦¹°Ï¬q¬O¤Q¤»¦ì¤¸¡A©Î¬O³]©w USE32 ¨M©w¦¹°Ï¬q¬O¤T¤Q¤G¦ì¤¸¡C¨£²Ä¤Q¤@³¹¥H§¹¾ã¤è¦¡«Å§i°Ï¬q¡C
¦pªG«Å§i¤F¡u.386¡v©Î§ó°ª¶¥ªº CPU «ü¥O¶°¡A¨º»ò´N¥i¥H¨Ï¥Î¤T¤Q¤G¦ì¤¸ªº¼È¦s¾¹¤F¡C80386 ªº¼È¦s¾¹¤À¦¨¥|Ãþ¡G
①¡G¤KÓ¤T¤Q¤G¦ì¤¸ªº³q¥Î¼È¦s¾¹¡]general-purpose registers¡^¡A¨ä¦WºÙ¤À§O¬O EAX¡BEBX¡BECX¡BEDX¡BESP¡BEBP¡BESI¡BEDI¡C¥¦Ìªº¦WºÙ©M 8086/8088 ³q¥Î¼È¦s¾¹¦WºÙ«Ü¬Û¦ü¡A«e±ªº¡uE¡vªí¥Ü¡uextended¡v¡A©µ¦ù¤§·N¡A¨ä¹ê´N¬O§âì¨Ó¤Q¤»¦ì¤¸ªº¼È¦s¾¹ÂX¥R¬°¤T¤Q¤G¦ì¤¸¡C
EAX¡BEBX¡BECX¡BEDX ³o¥|ӼȦs¾¹¤¤¡A¨C¤@Ó¸û§Cªº¦r²Õ¤S¥i¿W¥ß¨Ï¥Î¡A¦WºÙ»P 8086 ¬Û¦P¡A´N¬O AX¡BBX¡BCX¡BDX¡C³Ì§Cªº¤Q¤»Ó¦ì¤¸¡A¤S¥i¤À¦¨¨âÓ¤K¦ì¤¸ªº¼È¦s¾¹¡C¨Ò¦p²Ö¥[¾¹ EAX ¸û§C¦r²Õªº 16 ¦ì¤¸¬° AX ¼È¦s¾¹¡AAX ¤S¥i¤À¦¨ AH »P AL ¨âÓ¤K¦ì¤¸ªº¼È¦s¾¹¡A¦ý¬O EAX ¸û°ª¦r²Õªº 16 ¦ì¤¸¡]¤]´N¬O²Ä 16¡ã31 ¦ì¤¸¡^µLªk³æ¿W¨Ï¥Î¤F¡A¤]¨S¯S®íªº¦WºÙ¡A¨£¤U¹Ï¡C¦Ü©ó EBX¡BECX¡BEDX ªº±¡ªp¤]©M EAX ¬Û¦P¡A¥i¥H¤À¦¨¤@Ó¤Q¤»¦ì¤¸©M¨âÓ¤K¦ì¤¸¸û¤pªº¼È¦s¾¹¡C
ESP¡BEBP¡BESI¡BEDI ¥i¥H§â¸û§Cªº¦r²Õ³æ¿W¨Ï¥Î¡A¦WºÙ¤]»P 8086 ¬Û¦P¡A´N¬O SP¡BBP¡BSI¡BDI¡F¦ý¬O¤£¯à©î¦¨¨âÓ¤K¦ì¤¸ªº¼È¦s¾¹¡A¦P®É°ª¦r²Õ¤]¤£¯à³æ¿W¨Ï¥Î¡A¤]¨S¦³¦WºÙ¡C
②¡G¤»Ó°Ï¬q¼È¦s¾¹¡A°£¤F 8086/8088 ì¨Óªº CS¡BDS¡BES¡BSS ¤§¥~¡A¤S¦h¤F¨âӰϬq¼È¦s¾¹¡A¥¦Ì¬O FS »P GS¡A¤@¯ë¥Î¨Ó§@¬°¦s©ñ¸ê®Æªº°Ï¬q¡C³o¤»Ó°Ï¬q¼È¦s¾¹³£¬O¤Q¤»¦ì¤¸ªº¡C
③¡G©µ¦ùºX¼Ð¼È¦s¾¹¡]EFLAGS Register¡^¡AIA¡Ð32 ªº©µ¦ùºX¼Ð¼È¦s¾¹¥u¦³¤@Ó¡Aªø«×¬O 32 ¦ì¤¸¡A¥¦¬O 8086/8088 ºX¼Ð¼È¦s¾¹ªº©µ¦ù¡A©µ¦ùªº³¡¤À´X¥G»P«OÅ@¼Ò¦¡¦³Ãö¡A³]p DOS µ{¦¡®É¥Î¤£¨ì¡C
④¡G«ü¥O«ü¼Ð¼È¦s¾¹¡]instruction pointer¡^¡A32 ¦ì¤¸ªº¼È¦s¾¹¡A¦WºÙ¬O EIP¡A¬O 8086/8088 ªº IP ªº©µ¦ù¡A¥\¯à³£¬O«ü¦V±Nn°õ¦æªº«ü¥O¦ì§}¡C
¦b 8086/8088 CPU ¤¤¡A¯à¥Î©ó©w§}ªº CPU ¥u¦³ BX¡BBP¡BSP¡BDI¡BSI¡A¦ý¬O¦b IA¡Ð32 CPU ¤¤¡A©Ò¦³ªº³q¥Î¼È¦s¾¹³£¥i¥H¥Î¨Ó©w§}¡C¦Ó¥B©w§}ªº¤è¦¡¤]¤ñ 8086/8088 ¨Ó±o¦h¡C©³¤U¨Ó¬Ý¬Ý¨âÓ¨Ò¤l¡A²Ä¤@Ó¨Ò¤l¬O¨Ï¥Î¥[±jªº 32 ¦ì¤¸ MUL «ü¥O¡A²Ä¤GÓ¨Ò¤l¬O¨Ï¥Î³q¥Î¼È¦s¾¹©w§}¡C
©³¤Uªº MUL32_1.ASM µ{¦¡¯à§Q¥Î IA¡Ð32 CPU ªº MUL «ü¥O¶i¦æ¤T¤Q¤G¦ì¤¸ªº¼ªk¡A¥|¤Q»õ¼¥H¤T¤Q»õ¡C¥|¤Q»õ´«ºâ¦¨¤Q¤»¶i¦ì¬O 0EE6B 2800H¡A¤T¤Q»õ«h¬O 0B2D0 5E00H¡]¥|¤Q»õ¡B¤T¤Q»õÂà´«¦¨¤Q¤»¶i¦ì¼Æ¡A¥i¥H¥Î¤pºâ½L¶i¦æ´«ºâ¡^¡A¨â¼Æ§¡»Ý¥H¤T¤Q¤G¦ì¤¸ªí¥Ü¤~¯à®e¯Ç±o¤U¡C¡]¤T¤Q¤G¦ì¤¸ªí¥Üªº¥¿¾ã¼Æ³Ì¤j¥i¥H¥|¤Q¤G»õ¡A½d³ò¬O 0¡ã4294967295¡^
¤T¤Q¤G¦ì¤¸ªº¼Æ¼¥H¤T¤Q¤G¦ì¤¸ªº¼Æ¡A³Ì¦h¥i¹F¤»¤Q¥|¦ì¤¸¡]¤»¤Q¥|¦ì¤¸ªº¼Æ¬O¥|¦r²Õ¡A¥H QWORD ªí¥Ü¡^¡A³oì²z¦b²Ä¤Q³¹´¿´£¹L¡C¦ý©³¤Uªº MUL32_1.ASM ²Ä 8 ¦æ¡AÀx¦s¼¿nªºÅܼơAproduct¡A«o¥Î¨âÓÂù¦r²Õªí¥Ü¡A²z¥Ñ¬O¨Ï¥Î MUL «ü¥O®É¡A©Ò±oªº¼¿n¦s©ó EDX:EAX¡A¥¦Ì³£¬O¤T¤Q¤G¦ì¤¸ªº¼È¦s¾¹¡C
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20 |
.MODEL SMALL
.386
.STACK
;*********************************************************************
.DATA
x DD 4000000000 ;³Q¼¼Æ¡×¥|¤Q»õ
y DD 3000000000 ;¼¼Æ¡×¤T¤Q»õ
product DD ?,? ;¼¿n
;*********************************************************************
.CODE
;---------------------------------------------------------------------
.STARTUP
xor edx,edx
mov eax,x
mul y ;°õ¦æx¡Ñy
mov product,eax ;§â¼¿n¦s¤Jproduct¤¤
mov product[4],edx
.EXIT 0
;*********************************************************************
END |
±N MUL32_1.ASM ¦s¤J¡uE:\HomePage\SOURCE\DOS\MUL32\¡v¤l¥Ø¿ýùØ¡AµM«á¿é¤J¤U±«ü¥O²ÕĶ¨Ã³sµ²¡G
E:\DOS\MUL32>ml mul32_1.asm [Enter] Microsoft (R) Macro Assembler Version 6.11 Copyright (C) Microsoft Corp 1981-1993. All rights reserved. Assembling: mul32_1.asm Microsoft (R) Segmented Executable Linker Version 5.31.009 Jul 13 1992 Copyright (C) Microsoft Corp 1984-1992. All rights reserved. Object Modules [.obj]: mul32_1.obj Run File [mul32_1.exe]: "mul32_1.exe" List File [nul.map]: NUL Libraries [.lib]: Definitions File [nul.def]: E:\DOS\MUL32>mul32_1 [Enter] ¡÷°õ¦æ MUL32_1.EXE E:\DOS\MUL32>
°õ¦æ MUL32_1.EXE «á·|µo²{¿Ã¹õ¤W²@µL°ÊÀR¡A³o¬O¦]¬° MUL32_1 ¨Ã¨S¦³§âµ²ªG¦L¦b¿Ã¹õ¤W¡A¥²¶·¥Î°£¿ù¾¹Æ[¹îÆ[¹î¡C¥H DEBUG ¤Î SYMDEB ¤À§O¸ü¤J MUL32_1.EXE Æ[¹î¦p¤Uªí¡A¥ªÃä¬O¥Î DEBUG Æ[¹îªºµ²ªG¡A¥kÃä¬O SYMDEB Æ[¹îªºµ²ªG¡G
¥Î DEBUG Æ[¹î | ¥Î SYMDEB Æ[¹î |
E:\DOS\MUL32>debug mul32_1.exe [Enter] -u 0 28 [Enter] 0E28:0000 B82A0E MOV AX,0E2A 0E28:0003 8ED8 MOV DS,AX 0E28:0005 8CD3 MOV BX,SS 0E28:0007 2BD8 SUB BX,AX 0E28:0009 C1 DB C1 ¡÷¥X²{©_©Çªºµ{¦¡½X 0E28:000A E304 JCXZ 0010 0E28:000C 8ED0 MOV SS,AX 0E28:000E 03E3 ADD SP,BX 0E28:0010 66 DB 66 ¡÷¥X²{©_©Çªºµ{¦¡½X 0E28:0011 33D2 XOR DX,DX 0E28:0013 66 DB 66 ¡÷¥X²{©_©Çªºµ{¦¡½X 0E28:0014 A10A00 MOV AX,[000A] 0E28:0017 66 DB 66 ¡÷¥X²{©_©Çªºµ{¦¡½X 0E28:0018 F7260E00 MUL WORD PTR [000E] 0E28:001C 66 DB 66 ¡÷¥X²{©_©Çªºµ{¦¡½X 0E28:001D A31200 MOV [0012],AX 0E28:0020 66 DB 66 ¡÷¥X²{©_©Çªºµ{¦¡½X 0E28:0021 89161600 MOV [0016],DX 0E28:0025 B8004C MOV AX,4C00 0E28:0028 CD21 INT 21 - |
E:\DOS\MUL32>symdeb mul32_1.exe [Enter] Microsoft (R) Symbolic Debug Utility Version 4.00 Copyright (C) Microsoft Corp 1984, 1985. All rights reserved. Processor is [80286] -u 0 28 [Enter] 1176:0000 B87811 MOV AX,1178 ¡÷¸ê®Æ°Ï¬q¦ì©ó 1178 1176:0003 8ED8 MOV DS,AX 1176:0005 8CD3 MOV BX,SS 1176:0007 2BD8 SUB BX,AX 1176:0009 C1E304 SHL BX,04 1176:000C 8ED0 MOV SS,AX 1176:000E 03E3 ADD SP,BX 1176:0010 66 DB 66 ¡÷¥X²{©_©Çªºµ{¦¡½X 1176:0011 33D2 XOR DX,DX 1176:0013 66 DB 66 ¡÷¥X²{©_©Çªºµ{¦¡½X 1176:0014 A10A00 MOV AX,[000A] ¡÷x¦b¦ì§}000A 1176:0017 66 DB 66 ¡÷¥X²{©_©Çªºµ{¦¡½X 1176:0018 F7260E00 MUL Word Ptr [000E] 1176:001C 66 DB 66 ¡÷¥X²{©_©Çªºµ{¦¡½X 1176:001D A31200 MOV [0012],AX 1176:0020 66 DB 66 ¡÷¥X²{©_©Çªºµ{¦¡½X 1176:0021 89161600 MOV [0016],DX 1176:0025 B8004C MOV AX,4C00 1176:0028 CD21 INT 21 - |
¦ì§} 0000¡ã000E ªºµ{¦¡½X¬O¦]¬° .STARTUP °²«ü¥O²£¥Íªº¡A¸Ô²Ó±¡§Î¨£²Ä¤Q¤@³¹¡C¦ì§} 0025¡ã0028 ªºµ{¦¡½X¬O¥Ñ .EXIT °²«ü¥O²£¥Íªº¡C¥u¦³ 0010¡ã0021 ªºµ{¦¡½X¤~ MUL32_1 ªº¥D¨¤¡C
§A·|µo²{¡A¤£ºÞ¥Îþ¤@ºØ°£¿ù¾¹¡A³£·|¥X²{©_©Çªºµ{¦¡½X¡]¥H²HÂŦâ¼Ð¥Ü¡^¡C¦ý¦pªG¤ñ¸û¤§«á¡A§A¤S·|µo²{¡G①¥¦Ìªº¾÷±ñ½X¬O¤@¼Ëªº¡B②SYMDEB ¯à¶¶§Q¤Ï²ÕĶ¡uSHL BX,04¡v¡A¦ý¬O DEBUG «o¤£¦æ¡]¦b¦ì§} CS:0009 ³B¡^¡C³oì¦]À³¸Ó«Ü®e©ö²z¸Ñ¡A¦b³]p DEBUG ®É¡A80286 ¤Î§ó°ª¶¥ªº CPU ©|¥¼³]p¥X¨Ó¡A©Ò¥H DEBUG ¥u¯à¤Ï²ÕĶ 8086/8088 «ü¥O¡A¦Ó¡uSHL ¹Bºâ¤¸,¥ß§YÈ¡v¬O 80286 ¤Î¨ä¥H«á¤~·s¼Wªº¡AÃø©Ç DEBUG »{¤£±o¡A¥u¯à¥Î¾÷±ñ½Xªí¥Ü¡C
¥Ñ¦¹¥i¥H±À½×¡A¨º¨Ç³Ñ¤Uªº¡u©_©Çµ{¦¡½X¡v¤]¬O DEBUG ¥H¤Î SYMDEB ³£»{¤£¥X¨Óªº«ü¥O¡C¨S¿ù¡Aªº½T¦p¦¹¡C¨Æ¹ê¤W¡A66H ¬O¥Î¨Ó¤Á´«¹Bºâ¤¸ªø«×ªº¾÷±ñ½X¡C¦pªG¬O¦b¤Q¤»¦ì¤¸°Ï¬q¥X²{ 66H¡A¨º»ò¹Bºâ¤¸ªø«×´NÅܦ¨¤T¤Q¤G¦ì¤¸¡F¦pªG¬O¦b¤T¤Q¤G¦ì¤¸°Ï¬q¥X²{ 66H¡A¨º»ò¹Bºâ¤¸ªø«×´NÅܦ¨¤Q¤»¦ì¤¸¡]¸Ô±¡¨£²Ä 24 ³¹¹Bºâ¤¸«e¸m½X¡^¡C¨Ò¦p¦b¦ì§} 0010¡ã0011 ªºµ{¦¡½X¬O
DB 66 XOR DX,DX
¨ä¹ê¬O¡uXOR EDX,EDX¡v¡CÁöµM°£¿ù¾¹µLªk¥¿½T¤Ï²ÕĶ³o¨Ç¾÷±ñ½X¡A¦ý¤£·|¼vÅT CPU °õ¦æ¡A©³¤U¨Ó¬Ý¬Ý MUL32_1.EXE °õ¦æµ²ªG¡Cèè´£¹L¡AMUL32_1.EXE ¨S¦³¿é¥X¡A©Ò¥H¥u¯à¥Î°£¿ù¾¹Æ[¹î¡C¤£ºÞ¥Îþ¤@Ó°£¿ù¾¹¡A¥ý¬Ý¬Ý¸ê®Æ°Ï¬qªº x¡By¡Bproduct ¤§È¡C°²³]¥H SYMDEB Æ[¹î¡G
-d 1178:0 l20 [Enter] 1178:0000 66 89 16 16 00 B8 00 4C-CD 21 00 28 6B EE 00 5E f....8.LM!.(kn.^ 1178:0010 D0 B2 00 00 00 00 00 00-00 00 36 B8 4A 1C 50 90 P2........68J.P. -g 25 [Enter] AX=0000 BX=0020 CX=003A DX=906B SP=0420 BP=0000 SI=0000 DI=0000 DS=1178 ES=1166 SS=1178 CS=1176 IP=0025 OV UP EI NG NZ NA PE CY 1176:0025 B8004C MOV AX,4C00 -d 0 l20 [Enter] 1178:0000 66 89 16 16 00 B8 00 4C-CD 21 00 28 6B EE 00 5E f....8.LM!.(kn.^ 1178:0010 D0 B2 00 00 B0 D8 6B 90-88 A6 36 B8 4A 1C 50 90 P2..0Xk..&68J.P. -
¤W±²HÂŦ⪺¬O x¡A¾í¦âªº¬O y¡Aµµ¦âªº¬O product¡C°õ¦æ§¹«á¡Aproduct ¤wÅܦ¨ 0A688 906B D8B0 0000H¡]¥Õ¦â¦r¡^¡A³o¬O¤@Ó¤»¤Q¥|¦ì¤¸ªøªº¥¿¾ã¼Æ¡A´«ºâ¦¨¤Q¶i¦ì¬O¤@¤d¨â¦Ê¨Ê¡]1.2¡Ñ1019¡^¡C
¥ý½Æ²ß 8086/8088 ªº©w§}¤è¦¡¡C¤jP¤À¦¨¨âºØ¡G
①¡Gª½±µ©w§}¡C³oºØ¤è¦¡»¡¬ï¤F´N¬O¥H¤@ÓÅÜ¼Æ·í°µ°O¾ÐÅé¦ì§}¡A¨Æ¹ê¤W¡A¦bì©lµ{¦¡¤¤©Ò©w¸qªº¥ô¦óÅܼơA³£¬O¬YÓ°O¾ÐÅé¦ì§}¡C¨Ò¦p¦b MUL32_1.ASM ¤¤©w¸qªº x ÅܼơA¨ä¹ê x ¬O¦b¬YÓ°O¾ÐÅé¦ì§}¤W¡A¦Ó¦s¨ú¥¦Ìªº¤èªk¬O
mov eax,x
¤Ï²ÕĶ«á¬O
mov eax,[000A]
¤W±ªºµ{¦¡½X¬O»¡Åª¨ú°O¾ÐÅé¦ì§} 000A ¤ºªº¼ÆÈ¡AµM«á¦s¤J EAX ¼È¦s¾¹ùر¡C¦]¬°¤£¥²¦A¸g¨ä¥L¤âÄò¡Aª½±µªí©ú¤F³oÓ¦ì§}´N¬O 000A¡A©Ò¥HºÙ¡uª½±µ©w§}¡v¡C
[ reg ]
-d ds:0 l10 [Enter] ¡÷Æ[¹îDS:0000¡ãDS:000Fªº°O¾ÐÅ餺®e 2000:0000 00 01 02 03 04 05 0A 8B-56 08 8B 46 06 D1 E9 D1 ........V..F.QiQ -d es:0 l10 [Enter] 3000:0000 0A 0B 0C 0D 0E 0F 00 00-00 00 00 00 00 00 00 00 ................ -d ss:0 l10 [Enter] 4000:0000 11 22 33 44 55 66 00 00-00 00 00 00 00 00 00 00 ."3DUf.......... -r [Enter] ¡÷ª`·N¡IBX¡BSI¡BDI¡BBP¤§È¨Ì§Ç¬O0¡B1¡B2¡B3 AX=4000 BX=0000 CX=005A DX=0000 SP=FFFE BP=0003 SI=0001 DI=0002 DS=2000 ES=3000 SS=4000 CS=1166 IP=0150 NV UP EI PL NZ NA PO NC 1166:0150 8A07 MOV AL,[BX] DS:0000=00 -u 150 158 [Enter] 1166:0150 8A07 MOV AL,[BX] 1166:0152 8A24 MOV AH,[SI] 1166:0154 8A0D MOV CL,[DI] 1166:0156 8A6E00 MOV CH,[BP+00] ¡÷CH±NÅܦ¨¦s©ó¦ì§}SS:0003ªº°O¾ÐÅ餺®e¡A44¡]¨£¤W±¤E¦æªºµµ¦â¦r¡^ -g=150 159 [Enter] AX=0100 BX=0000 CX=4402 DX=0000 SP=FFFE BP=0003 SI=0001 DI=0002 DS=2000 ES=3000 SS=4000 CS=1166 IP=0159 NV UP EI PL NZ NA PO NC 1166:0159 90 NOP -
⑵¡Gµy·L½ÆÂø¤@ÂIªº¶¡±µ©w§}¬O¦b¡u[ ]¡v¤º°£¤F¼È¦s¾¹¤§¥~¡A¦A¥[¤W°¾²¾¦ì§}¡C¦bì©lµ{¦¡¤¤¡A°¾²¾¦ì§}³q±`¬OÅܼƦWºÙ¡AÅܼƦWºÙ¥i¥H¦b¡u[ ]¡v¤º¡A¤]¥i¥H¦b¡u[ ]¡v¤§«e¡C¦b°£¿ùµ{¦¡¤¤¡A°¾²¾¦ì§}±`¥H¼ÆȪí¥Ü¡A¥²¶·©ñ¦b¡u[ ]¡v¤º¡C³oºØ©w§}¤è¦¡ªº»yªk¦p¤U¡G
var [ reg ] [ var¡Ïreg ]
¤W±¨â¦æµ{¦¡·N¸q¬Û¦P¡Avar ¬OÅܼƦWºÙ¡A¦b²ÕĶ®É·|§âÅܼƦWºÙÂàÅܦ¨°¾²¾¦ì§}¡C¦b¡u[ ]¡v¤ºªº reg ¥Nªí¼È¦s¾¹¡A¥u¯à¬O BX¡BSI¡BDI¡BBP ¤¤ªº¨ä¤¤¤@ºØ¡A¸ò¤W±¤@¼Ë¡A¥u¦³¨Ï¥Î BP ®É¡A¦s¨ú SS °Ï¬q¡A¨ä¾l³£¦s¨ú DS °Ï¬q¡C³oºØ¶¡±µ©w§}ªº¤èªk¡A³Ì±`¥Î¦b°}¦C¤¤¡C¨Ò¦p©³¤Uªº prime2 ¬O¤p©ó 50 ªº½è¼Æ©Ò§Î¦¨ªº°}¦C¡An¨Ï AX Åܦ¨²Ä 3 Ó¤¸¯À¡]±q²Ä¹sÓ¤¸¯À¶}©l¡^¡Aµ{¦¡¦p¤U¡G
prime2 DW 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47 mov bx,3 ;n¨ú±o²Ä 3 Ó¤¸¯À shl bx,1 ;¡uSHL BX,1¡v¬Û·í©ó¨ÏBX¼¥H2¡A¦]¬°¨CÓ¤¸¯À¦û¨âӦ줸²Õ mov ax,prime2[bx] ;¬Û·í©ó prime2[6]¡A«á¨ÓAX·|Åܦ¨7
var [ reg1¡Ïreg2 ] var [reg1] [reg2] [ var¡Ïreg1¡Ïreg2 ]
¤W±¤T¦æµ{¦¡¬O¤@¼Ëªº¡Areg1¡Breg2 ¥Nªí¨âӼȦs¾¹¡A¨ä¤¤¤@Ó¥²¶·¬O BX¡BBP ¤GªÌ¤¤ªº¤@Ó¡A¥t¤@Ó¥²¶·¬O SI¡BDI ¤GªÌ¤¤ªº¤@Ó¡C¤]´N¬O»¡¦b¡u[ ]¡v¤º¦pªG¦³¨âӼȦs¾¹¡A¨º»ò¥²¶·¤@Ó¬O¯Á¤Þ¼È¦s¾¹¡]SI¡BDI¡^¡A¥t¤@Ó¬O°ò©³¼È¦s¾¹¡]BX¡BBP¡^¡A¤£¯à¦P®É¬O¯Á¤Þ¼È¦s¾¹¡A©Î¦P®É¬O°ò©³¼È¦s¾¹¡C¦pªG¨S¦³â¶V°Ï¬q¡A¨Ã¥B¨ä¤¤¦³¤@ӼȦs¾¹¬O BP¡A¨º»ò´N·|¦s¨ú SS °Ï¬q¡A§_«h¦s¨ú DS °Ï¬q¡Cvar ¬OÅܼƦWºÙ¡A¥i¬Ý¦¨°¾²¾¦ì§}¡A¦p¤£»Ýn¥i¥H¬Ù²¤¡C¥H¤U±ªº¨Ò¤l»¡©ú¡G
prime2 DW 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47 mov si,2 mov di,si mov bx,4 mov ax,prime2[bx][si] ;⒜¡CBX¡ÏSI¡×6¡A¥Ñ prime2 ¶}©lºâ°_¡A mov cx,prime2[bx+si] ;⒝¡C¤»Ó¦ì¤¸²Õªº°O¾ÐÅé¸Ì±¦s©ñªº¬O7 mov dx,[prime2+bx+si] ;⒞ mov ax,prime2[si+di] ;⒟
¹ï¤p¤ì°¸¨Ó»¡¡A²ßºD¥Î¡umov dx,prime2[bx+si]¡vªº¼gªk¡A¦ý¬O ML.EXE ¤@¼Ë¯à±µ¨ü¨ä¥L¨âºØ¼gªk¡A²ÕĶ«áªºµ²ªG¤]¤@¼Ë¡C¤W±µ{¦¡¤¤ªº⒟¡umov ax,prime2[si+di]¡v¬O¿ù»~ªº x86 «ü¥O¡A¦]¬°¤£¯à¦P®É¨Ï¥Î¨âÓ¯Á¤Þ¼È¦s¾¹¡C
IA¡Ð32 CPU ¸û 8086/8088 ¥ý¶i¡A¥u¦³ ESP µy¦³¨î¡A¨ä¾l¥ô¦ó¤@Ó¤T¤Q¤G¦ì¤¸ªº³q¥Î¼È¦s¾¹³£¯à¥Î©ó©w§}¡CIA¡Ð32 ªº©w§}¤è¦¡¤@¼Ë°Ï¤À¦¨①ª½±µ©w§}»P②¶¡±µ©w§}¡C«eªÌ»P 8086/8088 ¬Û¦P¡A¦ý«áªÌ«o²³æ±o¦h¡C¤U±¬O IA¡Ð32 ªº¶¡±µ©w§}¼Ò¦¡¡AÁöµM¦C¥X¤F¤TºØªí¥Ü¤èªk¡A¦ý¥¦Ì³£¤@¼Ë¡A©Ò¥H¨ä¹ê¥u¦³¤@ºØ¡G
var [ reg1¡Ïreg2*n ] var [reg1] [reg2*n ] [ var¡Ïreg1¡Ïreg2*n ]
¨ä¤¤ var ¬O¬OÅܼƦWºÙ©Î°}¦C¦WºÙ¡A²ÕĶ«á·|Åܦ¨°¾²¾¦ì§}¡Creg1 »P reg2 ¬O¤T¤Q¤G¦ì¤¸ªº¼È¦s¾¹¡Areg1 ¥i¥H¬O EAX¡BEBX¡BECX¡BEDX¡BEBP¡BESI¡BEDI¡BESP ¤KºØ¼È¦s¾¹¤¤ªº¨ä¤¤¤@ºØ¡Freg2 ¥i¥H¬O EAX¡BEBX¡BECX¡BEDX¡BEBP¡BESI¡BEDI ¤CºØ¼È¦s¾¹¤¤ªº¨ä¤¤¤@ºØ¡Areg2 ¤£¯à¬O ESP¡Cn ¥i¥H¬O 1¡B2¡B4¡B8 ¥|Ó¾ã¼Æ¤¤ªº¨ä¤¤¤@Ó¡A¦pªG¬O 1¡A¥i¥H¬Ù²¤¡C
³Ì«á¦b IA¡Ð32 CPU ªº¶¡±µ©w§}¤¤¡AÁÙ¦³¤@¨Ç³W«h¡A¦p¤U¡G
©³¤Uªº¨Ò¤l¡ASCR.ASM ¥Î EDX ¼È¦s¾¹©w§}¡A±N¸ê®Æ¼g¤Jµø°T°O¾ÐÅé¡C¦³Ãöµø°T°O¾ÐÅ骺¸ê®Æ¡A½Ð¾\Ū²Ä¤Q¤T³¹¡A³oùؤ£±Ôzì²z¡CSCR.ASM ·|¦L¥X¨â¦C¦r¦ê¡G¡u0123¡K¡K9ABCDEF¡v¡A³o¨Ç¦r¤¸ªºÃC¦â¤ÎI´º¦â§¡¤£¦P¡CSCR.ASM ì©lµ{¦¡¦p¤U¡G
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20
21 22 23 24
25 26 27 28
29 30 31 32
33 34 35 |
.MODEL SMALL
.386
x EQU 2 ;²Ä¤G¦æ
y EQU 20 ;²Ä¤G¤Q¦C
.STACK
;*********************************************************************
screen SEGMENT AT 0b800h ;±m¦â¿Ã¹õªºµø°T°O¾ÐÅé°Ï¬q¦ì§}
screen ENDS
;*********************************************************************
.DATA
string DB "0123456789ABCDEF"
;*********************************************************************
.CODE
;---------------------------------------------------------------------
.STARTUP
mov ax,screen ;¨ú¥Xµø°T°O¾ÐÅé°Ï¬q¦ì§}
mov fs,ax ;FS «ü¦Vµø°T°O¾ÐÅé°Ï¬q¦ì§}
cld
lea si,string
mov bx,0f00h ;BH¡×²Ä21¦C¤å¦rÃC¦â
mov edx,x ;BL¡×²Ä20¦C¤å¦rÃC¦â
mov cx,SIZEOF string
next: lodsb
mov ah,bl
mov fs:[160*y+2*edx],ax
shl ah,4 ;²Ä21¦C¤å¦rI´º¦â
or ah,bh
mov fs:[160*(y+1)+2*edx],ax
inc bl
inc dx
dec bh
loop next
.EXIT 0
;*********************************************************************
END |
SCR.ASM ªº²ÕĶ»P³sµ²¹Lµ{¡A¥H¤Î°õ¦æµe±¦p¤U¹Ï¡G
SCR.ASM ªº²Ä 25 ¦æ¬O¡umov fs:[160*y+2*edx],ax¡v¡A¨ä¤¤ y ¬O 10 ªí¥Ü²Ä¤G¤Q¦C¡C¹q¸£¿Ã¹õ¥Ñ¥ª©¹¥kºÙ¬°¤@¦C¡A³Ì¤W±¬O²Ä¹s¦C¡A©¹¤U¨Ì§Ç¬O²Ä¤@¦C¡B²Ä¤G¦C¡K¡K¤@ª½¨ì²Ä 24 ¦C¡C¨C¦C³Ì¦hÅã¥Ü 80 Ó¦r¤¸¡A¦Ó¨CÓ¦r¤¸ªºÃC¦â¤ÎI´º¦â¦û¤@Ӧ줸²Õ¡A¨C¤@¦C¦³ 160 Ӧ줸²Õ¡C¦¡¤¤ªº 160*y ´N¬O²Ä¤G¤Q¦C²Ä¹sÓ¦r¤¸ªº¦ì§}¡C
EDX ¬O²Ä´XÓ¦r¤¸¡A¦]¨CÓ¦r¤¸¥]§t¦r¤¸¥»¨¤ÎÃC¦â»PI´º¦â¡A¦@¦û¨âӦ줸²Õ¡A©Ò¥Hn¼¥H¤G¡C¡umov fs:[160*y+2*edx],ax¡v¤¤ªº¡uFS:¡v¡A±j¢§â AX ¤ºªº¸ê®Æ¼g¤J¨ì FS °Ï¬q¤º¡A³o¼Ëªº±¡§ÎºÙ¬°¡uâ¶V°Ï¬q¡v¡C¦pªG¨S¦³¡uFS:¡v¡A¨º»ò CPU ·|§â AX ¤ºªº¸ê®Æ¼g¤J DS °Ï¬q¤º¡C³Ì«áÁ`µ²¡A¡ufs:[160*y¡Ï2*edx]¡v´N¬O¿Ã¹õ¤W²Ä y ¦C¡B²Ä EDX Ó¦r¤¸ªº¦ì§}¡C
Æ[¹î¤W¹Ï¡A§A·|µo²{¦L¥X¨Óªº¨â¦C¤å¦r¡A²Ä¤G¤Q¦CªºI´º§¡¬°¶Â¦â¡A¤å¦rÃC¦â«h¬O¤£¦P¡C³o¬O¦]¬°I´º¦â¬O¥ÑÃC¦âªº¸û°ª¥|Ӧ줸±±¨î¡A¤å¦rÃC¦â«h¬O¥Ñ¸û§Cªº¥|Ӧ줸±±¨î¡A¦Ó BL ¸û°ªªº¥|Ӧ줸³£¬O 0¡A¬GI´º³£¬O¶Â¦â¡C¦Ó BH ªº¸û°ª¥|Ӧ줸»P¸û§C¥|Ӧ줸¡A·|ÀHµÛ°j°é¨C°õ¦æ¤@¦¸´N§ïÅܤ@¦¸¡A¬G¨CÓ¤å¦rÃC¦â¡BI´º¦â³£¤£¬Û¦P¡C
¦b SCR.ASM ªº²Ä 3¡B4 ¦æ¡A¨Ï¥Î EQU ¨Ó³]©w¤å¦rn¦L¦b¿Ã¹õªºþ¤@Ó¦ì¸m¤W¡C¤U±¨Ó»¡©ú EQU «ü¥O¡C
EQU »P = ¥Î¨Ó§â¤@ӲŸ¹«Å§i¬°¤@Ó¾ã¼Æ¡A¦Ó¨Ï±o¨ä«áªºµ{¦¡¯à¥Î¦¹²Å¸¹¥N´À¸Ó¾ã¼Æ¡C¥¦Ìªº»yªk¬O¡G
²Å¸¹ EQU ºâ³N¹Bºâ¦¡ ²Å¸¹ = ºâ³N¹Bºâ¦¡
¦¹³Bªººâ³N¹Bºâ¦¡¬O«ü¥i¥H¬O¥Îºâ³Npºâªº¼Æ¾Ç¦¡¤l¡A¨ä¹Bºâ¤¸À³¸Ó³£¬OÅܼƩμÆÈ¡C¹³©³¤Uªº¨Ò¤l¡A«Å§i¨âӲŸ¹¡A¤@Ó¯x§Îªº length¡]ªø¡^¬° 12¡Awidth¡]¼e¡^¬° 5¡G
length EQU 12 width EQU 5 area EQU length*width
³o¼Ëªº¸Ü area¡]±¿n¡^·|µ¥©ó 60¡C
EQU »P = ªº®t§O¦³¤G¡G
¦pªGn§â²Å¸¹«Å§i¬°¦r¦ê¡A¨ä»yªk¬O
²Å¸¹ EQU <¦r¦ê>
ÁöµM¥H EQU §â¬YӲŸ¹«ü©w¬°¬Y¼Æ¡A¸Ó²Å¸¹µLªkקאּ¥t¤@Ó¼ÆÈ¡F¦ý¬O¥H EQU §â¬YӲŸ¹«ü©w¬°¬Y¦r¦ê¡A«o¬O¥i¥Hק令¥t¤@Ó¦r¦ê¡C
¥H³o¨âÓ°²«ü¥O«Å§i²Å¸¹¡A¦³¨âÓ¦n³B¡G
°£¤F¤W±ªº¦n³B¤§¥~¡A¨Æ¹ê¤W¡AEQU »P = ¥i¥H¥Î¦b¥¨¶°¤¤³]©wÅܼơA¥Î©ó¦b¥¨¶°¤¤¹Bºâ¡C¨£²Ä¤G¤Q¤³¹¥¨¶°¤¤ªºÅܼơC
¥»³¹²Ä¤@Ó½d¨Ò¡AMUL32_1.ASM ¨Ã¨S¦³§âpºâµ²ªGÅã¥Ü¦b¿Ã¹õ¤W¡A¦h¤Ö¦³¤@¨Ç¿ò¾Ñ¡A©Ò¥H¼¶¼g¤F MUL32_2.ASM¡A¥HÀ±¸É³oÓ¯ÊÂI¡C
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20
21 22 23 24
25 26 27 28
29 30 31 32
33 34 35 36
37 38 39 40
41 42 43 44
45 46 47 48
49 50 51 52
53 54 55 56
57 58 59 60
61 62 63 64
65 66 67 68
69 70 71 72
73 74 75 76
77 78 79 80
81 82 83 84
85 86 87 88 |
.MODEL SMALL,C
.386
.STACK
;*********************************************************************
.DATA
x DD 4000000000,0 ;³Q¼¼Æ¡×¥|¤Q»õ
y DD 3000000000,0 ;¼¼Æ¡×¤T¤Q»õ
product DD ?,? ;¼¿n
;*********************************************************************
.CODE
;---------------------------------------------------------------------
;§ï¨}¦¡°£ªk¡Adivide¡A¯à¾¨¶qÁקK°£ªk·¸¦ì¡C
;divide¨Ïdivident°£¥Hdivisor¡A©Ò±oªº°Ó¦s©óptr_qut©Ò«üªº¦ì§}¡A¦¹¦ì§}¬°
;¤@¥|¦r²ÕÅܼơF¾l¼Æ¦s©óptr_rmd©Ò«ü¦ì§}¡A¦¹¬°¦ì§}¤@¥|¦r²ÕÅܼơC
divide PROC divident:QWORD,divisor:QWORD,ptr_qut:WORD,ptr_rmd:WORD
mov eax,DWORD PTR divident[4]
xor edx,edx
mov si,ptr_qut
div DWORD PTR divisor
mov [si+4],eax
mov eax,DWORD PTR divident
div DWORD PTR divisor
mov [si],eax
mov si,ptr_rmd
mov [si],edx
mov DWORD PTR [si+4],0
ret
divide ENDP
;---------------------------------------------------------------------
;§â¥|¦r²Õ¤Q¤»¶i¦ìµL¸¹¼ÆÂà´«¦¨¤Q¶i¦ì¼ÆÈ¡A¨Ã¦L¦b¿Ã¹õ¤W
;¿é¤J¡Gvalue¡Ð¥|¦r²Õ¤Q¤»¶i¦ìµL¸¹¼ÆÈ
;¿é¥X¡G¦b¿Ã¹õ¤W¦L¥X¤Q¶i¦ì¼Æ
hex_to_dec PROC value:QWORD
LOCAL ten:QWORD
LOCAL rmd:QWORD,qut:QWORD
LOCAL buffer[24]:BYTE
;§âbuffer¦r¦êÅܬ°23 DUP ("0"),"$"
mov cx,SIZEOF buffer
lea bx,buffer
dec cx
next: mov BYTE PTR [bx],"0"
inc bx
loop next
mov BYTE PTR [bx],"$"
;§âten³]¬°10
mov DWORD PTR ten,10
mov DWORD PTR ten[4],0
;§âqut³]¬°value
mov eax,DWORD PTR value
mov edx,DWORD PTR value[4]
mov DWORD PTR qut,eax
mov DWORD PTR qut[4],edx
;¨C¦¸qut°£¥H10¤§«á¡A©Ò±oªº°Ó¦s©óqut¡A¾l¼Æ¦s©órmd¤¤¡C
;¤U¦¸°£ªkªº³Q°£¼Æ¬O¦¹¦¸°£ªkªº°Ó¼Æ¡Aª½¦Ü°Ó¼Æ¬°¹s¤~°±¤î
mov cx,20 ;¥|¦r²ÕµL¸¹¼ÆÅܦ¨¤Q¶i¦ì³Ì¦h¦³20¦ì¼Æ
lea bx,buffer
add bx,SIZEOF buffer-2
.WHILE cx
invoke divide,qut,ten,ADDR qut,ADDR rmd
mov dl,BYTE PTR rmd
add [bx],dl
.BREAK .IF DWORD PTR qut==0
dec bx
dec cx
.ENDW
mov dx,bx
mov ah,9
int 21h
ret
hex_to_dec ENDP
;---------------------------------------------------------------------
.STARTUP
invoke hex_to_dec,QWORD PTR x
mov dl,"*"
mov ah,2
int 21h
invoke hex_to_dec,QWORD PTR y
mov dl,"="
mov ah,2
int 21h
mov eax,x ;§âEAX³]¬°¥|¤Q»õ
mul y ;EDX:EAX¡×x¡Ñy
mov product,eax
mov product[4],edx
invoke hex_to_dec,QWORD PTR product
.EXIT 0
;*********************************************************************
END |
±N MUL32_2.ASM ¦s¤J¡uE:\HomePage\SOURCE\DOS\MUL32\¡v¤l¥Ø¿ýùØ¡AµM«á¿é¤J¤U±«ü¥O²ÕĶ¨Ã³sµ²¡G
E:\DOS\MUL32>ml mul32_2.asm [Enter] Microsoft (R) Macro Assembler Version 6.11 Copyright (C) Microsoft Corp 1981-1993. All rights reserved. Assembling: mul32_2.asm Microsoft (R) Segmented Executable Linker Version 5.31.009 Jul 13 1992 Copyright (C) Microsoft Corp 1984-1992. All rights reserved. Object Modules [.obj]: mul32_2.obj Run File [mul32_2.exe]: "mul32_2.exe" List File [nul.map]: NUL Libraries [.lib]: Definitions File [nul.def]: E:\DOS\MUL32>mul32_2 [Enter] ¡÷°õ¦æ MUL32_2.EXE 4000000000*3000000000=12000000000000000000 E:\DOS\MUL32>
MUL32_2 n¯à¦L¥XÃþ¦ü¡u4000000000*3000000000=12000000000000000000¡vªº¦¡¤l¡C©Ò¥H MUL32_2.ASM ¤¤±on¦³Ó°Æµ{¦¡¡A¯à§â쥻¦s©ó°O¾ÐÅ餤ªº¤Q¤»¶i¦ì¼ÆÈ¡AÅܦ¨¤Q¶i¦ì¼Æ¡AµM«á¦L¦b¿Ã¹õ¤W¡C³oӰƵ{¦¡ºÙ¬° hex_to_dec¡A¥¦¥u¦³¤@ӰѼơA´N¬On¦L¦b¿Ã¹õ¤Wªº¼Æ¡A³oӰѼƪø«×¥²¶·¬O¥|¦r²Õ¡]QWORD¡^¡C©I¥s hex_to_dec ®É¡A´N¥Î¤U±¤è¦¡©I¥s¡G
invoke hex_to_dec,¥|¦r²ÕÅܼÆ
³o¬O¦]¬°¤T¤Q¤G¦ì¤¸ªº¼Æ¼¥H¤T¤Q¤G¦ì¤¸ªº¼Æ¡A©Ò±oªº¼¿n³Ì¦h¥i¹F¤»¤Q¥|¦ì¤¸¡A¤]´N¬O¥|¦r²Õ¡C¦A¥[¤W¯à§â¤»¤Q¥|¦ì¤¸ªº¼Æ¦L¥X¨Óªº°Æµ{¦¡¡A·íµM¤]¯à§â¤T¤Q¤G¦ì¤¸ªº¼Æ¦L¥X¨Ó¡A©Ò¥H¥un±N°Ñ¼Æ³]¬°¥|¦r²Õ´N¥i¥H¡C
¦ý¬O¬Ý²Ä 5¡ã8 ¦æªº¸ê®Æ°Ï¬q¡Ax¡By¡Bproduct ³£©w¸q¦¨¨âÓÂù¦r²Õ¡]Âù¦r²Õ¬O DWORD¡Aªø 32 Ӧ줸¡^¡A¹³¤U±ªºµ{¦¡½X¡G
x DD 4000000000,0 ;³Q¼¼Æ¡×¥|¤Q»õ y DD 3000000000,0 ;¼¼Æ¡×¤T¤Q»õ product DD ?,? ;¼¿n
¬°¤°»ò³o¼Ë©w¸q©O¡Hì¦]¬O¤T¤Q¤G¦ì¤¸ªº¼ªk¡A³Q¼¼Æ¥²¶·¦b EAX¡A¼¼Æ¬O¬YÓÅܼƩμȦs¾¹¡A¥¦Ì³£¬O¤T¤Q¤G¦ì¤¸ªº¡A³o¬O x86 ¼ªk«ü¥O¡AMUL¡A©Ò³W©wªº¡C©Ò¥H§â x¡By ©w¸q¦¨¨âÓÂù¦r²Õ¡A¦Ó¥B¨ä¸û°ª¦ì§}ªºÂù¦r²Õ§¡¬°¹s¡C¤§©Ò¥H§â¸û°ª¦ì§}ªºÂù¦r²Õ³]¬°¹s¡A¬O¦]¬°¨âÓì¦]¡G①¥¦Ì¥»¨Ó´N¬O¹s¡A¦ý¤£¥i¤£³]¡A¤£¥i¤£³]ªºì¦]¸ò¤UÓì¦]¦³Ãö¡F②°Ñ¼Æ¬°¥|¦r²Õ®É¡A©I¥s®É¦³ÂI¨à³Â·Ð¡C
³oӳ·ЬO IA¡Ð32 CPU µLªk¤@¦¸±N¥|¦r²Õ¸ê®Æ±À¤J°ïÅ|¡A¥²¶·¤À¨â¦¸°µ¡A²Ä¤@¦¸¥ý§â°ª¦ì§}ªºÂù¦r²Õ±À¤J°ïÅ|¡A²Ä¤G¦¸¦A§â§C¦ì§}ªºÂù¦r²Õ±À¤J°ïÅ|¡C³o¤]²Å¦X x86 ¬Û®e¾÷ºØªº©Ê½è¡A°ª¦ìªº¼ÆÈ©ñ¦b°ª¦ì§}¡A§C¦ìªº¼ÆÈ©ñ¦b§C¦ì§}¡A³o´N¬O©Ò¿×¤p§ÇºÝ¡C
ÁöµM ML.EXE ·|³B²z¦n³o¥ó¨Æ±¡¡C¦Ó§ÚÌn°µªº´N¬O¦b©I¥s hex_to_dec ®É¡A¥[¤W¡uQWORD PTR¡v¡A±j¢ ML.EXE ±N¥¦Ìµø¬°¥|¦r²Õ¡]¹³ MUL32_2.ASM ²Ä 73¡B77¡B85 ¦æ¡^¡C¦¹¥~¦b©w¸q³o¨Ç°Ñ¼Æ®É¡A¨ä¸ê®ÆÃþ«¬³]¬°¨âÓÂù¦r²Õ¡A¥B°ª¦ì§}ªºÂù¦r²Õ¬°¹s¡AÅý invoke ®É¡A¯à¥ý±N³oÓ¹s±À¤J°ïÅ|¡AµM«á¤~¬O§C¦ì§}ªºÂù¦r²Õ¡C
¦pªG¹³¤U±¤è¦¡©w¸q x¡By
x DD 4000000000 ;³Q¼¼Æ¡×¥|¤Q»õ y DD 3000000000 ;¼¼Æ¡×¤T¤Q»õ
¨º»ò¦b§â x¡By ·í°µ°Ñ¼Æ¶Çµ¹ hex_to_dec ®É¡A°ª¦ì§}ªºÂù¦r²Õ·|²£¥Í¿ù»~¡C¨Ò¦p¦b§â x §@¬°°Ñ¼Æ¶Çµ¹ hex_to_dec ®É¡A²Ä¤@¦¸·|§â y ±À¤J°ïÅ|¡AµM«á¦A§â x ±À¤J°ïÅ|¡A³o¬O¦]¬° y «ê¦n¦b x °ª¦ì§}ªºÂù¦r²Õ¤W¡A³o¼Ë´N·|µo¥Í¿ù»~¡C
¦pªG±N x¡By¡Bproduct ©w¸q¦¨¥|¦r²Õ¡A¹³¤U±¨º¼Ë¡A¤]¥¼¹Á¤£¥i¡C¦ý©I¥s hex_to_dec ®É¡A´N¤£¶·¦b°Ñ¼Æ«e¥[¤W¡uQWORD PTR¡v¤F¡C
x DQ 4000000000 ;³Q¼¼Æ¡×¥|¤Q»õ y DQ 3000000000 ;¼¼Æ¡×¤T¤Q»õ product DQ ? ;¼¿n
¤Ï¦Ó¦b²Ä 83¡B84 ¦æªº product n¥[¤W¡uDWORD PTR¡v¡A¹³¤U±¨º¼Ë¡G
mov DWORD PTR product,eax mov DWORD PTR product[4],edx
divide °Æµ{¦¡¨ä¹ê¬O°£ªk«ü¥O DIV ªº§ï¨}¡CÁöµM¦b¤T¤Q¤G¦ì¤¸ªº°£ªk¤¤¡A³Q°£¼Æ¥»´N¬O¤»¤Q¥|¦ì¤¸¡A¥H EDX:EAX ªí¥Ü¡F°Ó¬O¤T¤Q¤G¦ì¤¸¡A¦s©ó EAX¡C°²¦p³Q°£¼Æ«Ü¤j¦Ó°£¼Æ«Ü¤p®É¡A¦³¥i¯à©Ò±oªº°Ó·|¶W¹L¤T¤Q¤G¦ì¤¸ªº EAX ©Ò®e¯Çªº½d³ò¡A´N·|µo¥Í·¸¦ì¡CÁ|Ó·¥ºÝªº¨Ò¤l¡A¨Ò¦p 7FFF FFFF FFFF FFFF °£¥H 1¡A©Ò±oªº°Ó¤´¬O¤»¤Q¥|¦ì¤¸¡A³o¼Ë´Nµo¥Í·¸¦ì¡C
¦b hex_to_dec °Æµ{¦¡¤¤»Ýn°µ³sÄò°£¥H 10 ªº°£ªk¡A¦]¬°°£¼Æ¤£¤j¡A«Ü®e©ö³y¦¨·¸¦ì¡A©Ò¥H¤~·|¥Î divide °Æµ{¦¡¨ú¥N DIV «ü¥O¡CÃö©ó divide ¨¾¤î·¸¦ìªº¤èªk¡A¦b²Ä¤C³¹µù¤@´£¹L¡Adivide ¥u¬O±N¨äÂX¥R¦¨¤T¤Q¤G¦ì¤¸ªºª©¥»¡C
DEBUG »P SYMDEB µLªk¥¿½T¦aÅã¥Ü¤T¤Q¤G¦ì¤¸ªºµ{¦¡½X¡AÁöµM¤£¼vÅT°õ¦æµ²ªG¡A¦ý²×¨s¦³¨Ç¿ò¾Ñ¡C¨º»ò¦b DOS §@·~¨t²Î¤§¤U¡A¦³¨S¦³¯à¥¿½T³B²z¤T¤Q¤G¦ì¤¸µ{¦¡½Xªº°£¿ù¾¹©O¡HÁÙ¯uªº¦³©O¡I¨º´N¬O DEBUG32¡C
°²¦p§A«ö·Ó¦bªþ¿ý¤@¤¤ªº¤è¦¡¡A¤w¸g¦w¸Ë¦n Virtual PC 2007 SP1¡A¨Ã¥B¤]¤w¦w¸Ë¦n MS¡ÐDOS µêÀÀ¾÷¾¹¡A¨º»ò¥i¥HÀˬd¬O§_¤]¤w¸g¤U¸ü¦n¤p¤ì°¸·Ç³Æªº¤u¨ãµ{¦¡¡ÐTOOLS.IMA¡C¥¦¬O³nºÐ¤ùªº¼v¹³ÀÉ¡Aùرªº¡u\TOOLS\¡v¤l¥Ø¿ý¦³ DEBUG32.EXE °£¿ùµ{¦¡¡A¥i¥H«ö·Óªþ¿ý¤@³]©w¶}¾÷¤Î²ÕĶÀô¹Ò¤¤©Ò´£¨ìªº¤èªk±N¨ä«þ¨©¨ì MS¡ÐDOS µêÀÀ¾÷¾¹¤¤¡A´N¯à¨Ï¥Î¤F¡C
DEBUG32 ªº¨Ï¥Î¤èªk»P DEBUG ´X¥G¤@¼Ë¡A¥Î DEBUG32 °£¿ù¬YÓµ{¦¡®É¡A»yªk¦p¤U¡G
DEBUG32 µ{¦¡¦WºÙ
«ö¤U Enter Á䤧«á¡A´N¶i¤J DEBUG32 µ{¦¡ùØ¡A¹q¸£ªº±±¨îÅv´N¥Ñ DEBUG32 ±µºÞ¡CDEBUG32 ªº´£¥Ü²Å¸¹¬O¡u-¡v¡A¥X²{¦¹²Å¸¹´Nªí¥Ü DEBUG32 ¤w·Ç³Æ¦n±µ¨ü¨Ï¥ÎªÌªº«ü¥O¤F¡C¦pªG¥u³æ¯Â°õ¦æ DEBUG32¡A¤£¶i¦æ°£¿ù¡A¨º»ò¡uµ{¦¡¦WºÙ¡v¥i¥H¬Ù²¤¡C²{¦b°²³]§ÚÌn¹ï MUL32_1.EXE ¶i¦æ°£¿ù¡A¨Ì¤U±¨BÆJ¿é¤J¡uC:\TOOLS\DEBUG32 MUL32_1.EXE¡v¡G
E:\DOS\MUL32>C:\TOOLS\DEBUG32 MUL32_1.EXE [Enter]
Debug32 - Version 1.0 - Copyright (C) Larson Computing 1994
CPU = 686, Virtual 8086 Mode, Id/Step = 06C3, A20 enabled
-
¥ý¨Ó¬Ý¬Ý DEBUG32 ¬O§_¯à¥¿½T¤Ï²ÕĶ¡A¿é¤J¡uU¡v«ü¥O¡CDEBUG32 «ü¥O¤£°Ï¤À¤j¤p¼g¡A©Ò¥H¿é¤J¡uU¡v©Î¡uu¡v¡A³£¬O¤@¼Ë¡C¡uU¡v«ü¥O¬O¤Ï²ÕĶ¡]unassemble ©Î disassemble¡^ªº·N«ä¡A»yªk¬O¡uU [°_©l¦ì§} [µ²§ô¦ì§}]]¡v¡A¦pªG¬Ù²¤°_©l¦ì§}¡A¨º»ò DEBUG32 ·|±q IP ©Ò«ü¦ì§}¶}©l¤Ï²ÕĶ¡C
-u 0 28 [Enter]
2364:0000 B86623 MOV AX,2366h
2364:0003 8ED8 MOV DS,AX
2364:0005 8CD3 MOV BX,SS
2364:0007 2BD8 SUB BX,AX
2364:0009 C1E304 SHL BX,04
2364:000C 8ED0 MOV SS,AX
2364:000E 03E3 ADD SP,BX
2364:0010 6633D2 XOR EDX,EDX
2364:0013 66A10A00 MOV EAX,[000A]
2364:0017 66F7260E00 MUL Dword Ptr [000E]
2364:001C 66A31200 MOV [0012],EAX
2364:0020 6689161600 MOV [0016],EDX
2364:0025 B8004C MOV AX,4C00h
2364:0028 CD21 INT 21
-
¬Ý¬Ý¼È¦s¾¹ªº¤º®e¡A¿é¤J¡uR¡v«ü¥O¡G
-r [Enter]
AX=0000 BX=0000 CX=003A DX=0000 SP=0400 BP=0000 SI=0000 DI=0000
DS=2354 ES=2354 SS=2368 CS=2364 IP=0000 NV UP DI PL NZ NA PO NC
2364:0000 B86623 MOV AX,2366h
R «ü¥Oªº¥Îªk¸ò DEBUG Ãþ¦ü¡A¤]¥i¥H¥Î¥¦¨Óקï¼È¦s¾¹ªº¤º®e¡A¦ý¬O¬JµM¬O¯à°£¿ù¤T¤Q¤G¦ì¤¸ªºµ{¦¡¡A·íµM¤]n¯àÅã¥Ü¤T¤Q¤G¦ì¤¸ªº¼È¦s¾¹¡C©Ò¥H DEBUG32 °w¹ï R «ü¥O¶i¦æ¤F¥[±j¡A¥i¥H¿é¤J¡uR32¡v©Î¡uR16¡v¡A¤Á´«Åã¥Ü¤T¤Q¤G¦ì¤¸©Î¤Q¤»¦ì¤¸ªº¼È¦s¾¹¡C¨Ó¸Õ¸Õ¬Ý¡uR32¡v¡G
-r32 [Enter]
EAX=00000000 EBX=00000000 ECX=0000003A EDX=00000000 EBP=00000000
ESI=00000000 EDI=00000000 FS=2354 GS=2354 SS=2368 ESP=00000400
DS=2354 ES=2354 CS=2364 EIP=00000000 NV UP DI PL NZ NA PO NC
2364:0000 B86623 MOV AX,2366h
-
ªGµMÅܦ¨¤FÅã¥Ü¤T¤Q¤G¦ì¤¸¼È¦s¾¹¤§È¡C²{¦b¸U¨ÆѳơA¥i¥H¸Õ¸Õ¬Ý³æ¨B°lÂÜ¡A¡uT¡v«ü¥O¡G
-t [Enter] EAX=00002354 EBX=00000000 ECX=0000003A EDX=00000000 EBP=00000000 ESI=00000000 EDI=00000000 FS=2354 GS=2354 SS=2368 ESP=00000400 DS=2354 ES=2354 CS=2364 EIP=00000003 NV UP DI PL NZ NA PO NC 2364:0003 8ED8 MOV DS,AX Trace Interrupt -
§A·|µo²{¡ADEBUG32 ·|§â³æ¨B°lÂܪº°õ¦æµ²ªG¡A¥H¤Ï¥Õªí¥Ü¡A¦³§Q©ó²M·¡¬Ý¨£§ïÅܤF¤°»ò¡C
¥t¥~¡A¦³¤@ÂIȱo»¡©ú¡C¨Ï¥Î DEBUG ©Î SYMDEB °£¿ù®É¡A¦pªGµ{¦¡¦³¿é¥X¸ê®Æ¡A´N·|¦û¾Ú¿Ã¹õ¤@¶ô°Ï°ì¡A¦Ó¨Ï±o±µ¤U¨ÓªºÅã¥Üµe±¤£·|·Óì¨Ó³]pªº¤è¦¡±Æª©¡Aµe±Åܱo«Ü¶Ã¡CDEBUG32 §ï¨}¤F³oÓ°ÝÃD¡ADEBUG32 ªº°õ¦æµe±»P°£¿ùµe±¬O¤À¶}¨Óªº¡C©Ò¥H¦pªG³Q°£¿ùªºµ{¦¡¦³¿é¥X¸ê®Æªº¸Ü¡A¥²»Ý¤Á´«¨ì°õ¦æµe±¤~Æ[¹î±o¨ì¡CnÆ[¹î°õ¦æµe±¥i¥H¿é¤J¡uFL¡v«ü¥O¡CFL «ü¥O¬O Flip ªº·N«ä¡C¦pªGn¤Á¦^°£¿ùµe±®É¡A«ö¤U¥ô·NÁä´N¥i¥H¤F¡C
¨ä¥LÁÙ¦³³\¦h«ü¥O¡A¨Ò¦p³]©w¤¤Â_ÂI¡BÂ÷¶} DEBUG32 µ¥µ¥³£»P DEBUG ©Î SYMDEB ¬Û¦ü¡A¤]¥i¥H©ó DEBUG32 ´£¥Ü²Å¸¹¤§«á¡A¿é¤J¡u?¡v±o¨ì«ü¥Oªº»¡©ú¡C