¦b¼Æ¾Ç¤W¡A¾ã¼Æ¥i¤À¦¨¥¿¾ã¼Æ¡Bt¾ã¼Æ»P¹s¡A§ÚÌ¥H¡y¡Ï¡z©Î¡y¡Ð¡zªí¥Ü³o¾ã¼Æ¬O¥¿¾ã¼ÆÁÙ¬Ot¾ã¼Æ¡A¦pªG¬O¥¿¼Æ¡A¤@¯ë«e±¤£¥[¤W¥¿¸¹¡C¦Ó¦b¹q¸£¬ì¾Ç¤W¡A§ÚÌ¥u¯à¥Î¼ÆӦ줸ªºÀx¦sªÅ¶¡ ( ¤@¯ë¬O 8¡B16¡B32¡B64 ¦ì¤¸ ) ¨Óªí¥Ü³o¨Ç¾ã¼Æ¡C¤£¹L¦b¤é±`¥Í¬¡¤¤ÁÙ¬O¥H¥¿¾ã¼Æ¸û¬°±`¥Î¡A¦]¦¹¦b¹q¸£¤¤¤j³¡¤ÀÀ³¥ÎùØ¡A§ÚÌÁÙ¬O¼Æ¦r¬Ý¦¨¥¿¼Æ¦Ó©¿²¤¥¿t¸¹¡AºÙ¤§¬°µL¸¹¼Æ ( unsigned numbers )¡C·íµM¤F¡A¦³®É§ÚÌÁÙ¬O§Æ±æ¯à°÷¶i¦æ¥¿¼Æ©Ît¼Æªº¹Bºâ¡C»PµL¸¹¼Æ¤Ï±ªº´N¬O¦³¸¹¼Æ ( signed numbers ) ¤F¡A©Ò¿×¦³¸¹¼Æ¤D¬O«ü¨ã¦³¥¿t¸¹ªº¼Æ¡A§ÚÌ¥H³Ì°ª¦ì¤¸³]©w³oӼƬO¥¿¼ÆÁÙ¬Ot¼Æ¡A·í³Ì°ª¦ì¤¸¬° 0 ®É¡Aªí¥Ü¦¹¼Æ¬°¥¿¼Æ¡F·í³Ì°ª¦ì¤¸¬° 1 ®É¡Aªí¥Ü¦¹¼Æ¬°t¼Æ¡C³o³Ì°ª¦ì¤¸ºÙ¬°²Å¸¹¦ì¤¸¡C
¦]¬°¥Î¤F¤@Ӧ줸¨Óªí¥Ü¥¿t¼Æ¡A©Ò¥H¦P¼Ë¬O 8 ¦ì¤¸¡AµL¸¹¼Æ¥i¥Hªí¥Ü 0¡ã255 ªº½d³ò¡A¦ý¦³¸¹¼Æ©Ò¯àªí¥Üªº¥u¦³ ¡Ð128 ¨ì ¡Ï127¡A¨ä¥Lªº½Ð°Ñ¨£¤Uªí¡G
Àx¦sªÅ¶¡ | µL¸¹¼Æ½d³ò | ¦³¸¹¼Æ½d³ò | ²Õ¦X»y¨¥¤¤ ©Ò¥Î¤À°tªÅ¶¡ |
8 ¦ì¤¸ ( ¦ì¤¸²Õ¡Abyte ) | 0 ¨ì 255 | ¡Ð128 ¨ì ¡Ï127 | DB ©Î BYTE |
16 ¦ì¤¸ ( ¦r²Õ¡Aword ) | 0 ¨ì 65535 | ¡Ð32768 ¨ì ¡Ï32767 | DW ©Î WORD |
32 ¦ì¤¸ ( Âù¦r²Õ¡Adouble word ) | 0 ¨ì 4294967295 | ¡Ð2147483648 ¨ì ¡Ï2147483647 | DD ©Î DWORD |
64 ¦ì¤¸ ( ¥|¦r²Õ¡Aquad word ) | 0 ¨ì 18446744073709551615 | ¡Ð9223372036954775808 ¨ì ¡Ï9223372036954775807 | DQ ©Î QWORD |
¦b¼Æ¾Ç¤W¡A§Ú̪¾¹Dµ¥È¤£µ¥¸¹ªº¨â¼Æ¤¬¬°¬Û¤Ï¼Æ ( ¤°»ò¡H¬Û¤Ï¼Æ¬O¤°»ò¡H¬Û¤Ï¼Æ´N¬O¨â¼Æ¤§©M¬°¹sªÌ§Y¬°¬Û¤Ï¼Æ )¡A¨Ò¦p ¡Ï1 »P ¡Ð1 ¨â¼Æ§Y¬°µ¥È¤£µ¥¸¹¡A¦¹¤G¼Æ¬Û¥[µ²ªG¬°¹s¡C¥Ñ¦¹ì²z¥i±Àª¾¡A°²¦p§ÚÌn©w¸qt¼Æ¡A³Ì¦n¬O²Å¦X¤W±ªº³W«h¡C¸Õ·Q°²¦p§â 1 ¦s¤J AL ¼È¦s¾¹ùØ¡A¨º»ò AL ¥[¤W¦h¤Ö·|Åܦ¨¹s©O¡Hµª®×¬O 0FFH §a¡A¦]¦¹§Ú̧â 0FFH ©w¦¨ ¡Ð1¡A¦P²z§â 0FEH ©w¦¨ ¡Ð2¡K¡K¡A¥i¥H°Ñ¦Ò¤U¹Ï¡G
¦b¤W¹Ï¤¤¤p¤ì°¸§â 0¡ã0FFH ³o 128 Ó¼ÆȱƦ¨¶êÀôª¬¡A¦pªG AL ¼È¦s¾¹ªº¼Æȥѹs¶}©l»¼¼W¨ì 0FFH ( ¨£¬õ¦âªº¼Æ )¡A¦b¤W¤è¥H²HÂŦ⪺¼Æ¦r§Y¬°©Ò¥NªíªºµL¸¹¼Æ¡A¦Ó¤U¤è¥H¶À¦â¼Æ¦r¬°¨ä¦³¸¹¼Æ¡C¥Ñ¹Ï¤W¥i¥H¬Ý¨ì¡A·í AL ¼È¦s¾¹ªº¼Æ鴄 0 ¨ì 7FH ®É¡A¤£ºÞ¬OµL¸¹¼Æ©Î¦³¸¹¼Æ³£¬°¥¿¼Æ¡A§Y 0 ¨ì 127¡F¦ý¬O·í³Ì°ª¦ì¤¸¬° 1 ®É ( ¥Ñ 80H ¨ì 0FFH ®É )¡A«h¦³¸¹¼Æ»PµL¸¹¼Æ©Ò¥Nªíªº·N¸q¬O¤£¦Pªº¡C¥i¯àŪªÌ·|°Ý¡A¬J¬O¦p¦¹¡A¨º»ò¦P¼Ë¤@Ó¤Q¤»¶i¦ì¼Æ¨ì©³¬O¥NªíµL¸¹¼ÆÁÙ¬O¦³¸¹¼Æ©O¡H¥H 0FFH ¬°¨Ò¡A³oÓ°ÝÃD¬O»¡¡A0FFH ¨ì©³¬O¥Nªí 255 ÁÙ¬O ¡Ð1 ©O¡H¨ä¹ê³o¬O¦Ñ°ÝÃD¤F¡A¦b²Õ¦X»y¨¥ùØ¡A¼È¦s¾¹©Î°O¾ÐÅ骺¸ê®Æ¥þ¿àµ{¦¡¦p¦ó¥h¸ÑÄÀ³o¨Ç¸ê®Æ¡C
¤°»ò¬O 2 ªº¸É¼Æ©O¡H²³æªº»¡´N¬O§âì¨Óªº¤G¶i¦ì¤¤ªº¦U¦ì¤¸¤ÏÂà ( ¤ÏÂà¬O«ü 1 Åܦ¨ 0¡F0 Åܦ¨ 1 )¡AµM«á¦A¥[ 1¡C¨Ò¦p 1 ªº 2 ªº¸É¼Æ¬°¦ó¡H¥i¥H³o¼Ëºâ¡G
0000 0001 ¡@¡@¡õ¤ÏÂà¦U¦ì¤¸ 1111 1110 ¡@¡@¡õ¦A¥[ 1 1111 1111
³Ì«á±o¨ì 0FFH¡A´«¥y¸Ü»¡ 1 ©M 0FFH ¤¬¬° 2 ªº¸É¼Æ¡C¹ï·Ó¤W±ªº¹Ï¤ù¡A·í¥iµo²{¤@Ó¤½¦¡¡G¤¬¬° 2 ªº¸É¼Æªº¨â¼Æ«ê¦n¬°¬Û¤Ï¼Æ¡C¤W±ªº¤èªk¬O¥H¤G¶i¦ì¨Ó«ä¦Ò¡A¦pªG¥H¤Q¤»¶i¦ì¨Ó«ä¦Ò¡A¥i¥H¥H 0FH ¥h´î±¼¨C¦ìªº¼ÆÈ¡A³Ì«á¦A¥[¤@¡C¨Ò¦pn¨D 7DH ªº¤Gªº¸É¼Æ¡A¥i¥H³o¼Ë°µ¡G
F-7=8 F-D=2
±o 82H¡A³Ì«á¦A¥[¤@¡A±o 83H¡A¬G 7DH ªº 2 ªº¸É¼Æ¬° 83H¡A¹ï·Ó¤W¹Ï¡A§A¤]¥iµo²{ 7DH(¡Ï125) »P 83H(¡Ð125) ¤]¤¬¬°¬Û¤Ï¼Æ ( §A¤]¥i¥H§ï¦¨¤G¶i¦ì¨Ì¾Ú¤ÏÂà¦U¦ì¤¸¦A¥[¤@Åçºâ¬Ý¬Ý )¡C
¦³Ãö 2 ªº¸É¼ÆÁÙ¦³¤@¶µ©w²z¡A¨º´N¬O 2 ªº¸É¼Æ¹Bºâ¨ã¦³¥i°f©Ê¡A¥ç§Y¤@¼Æ¸g¹L¨â¦¸¤Gªº¸É¼Æ¹Bºâ·|«ì´_ì¼Æ¡C¨Ò¦p¥H¤W± 7DH ¬°¨Ò¡A¥¦¸g¹L 2 ªº¸É¼Æ¹Bºâ«á±o 83H¡A¦A¸g¹L¤@¦¸¹Bºâ¡G
F-8=7 F-3=C
³Ì«á¦A¥[¤@Åܦ¨ 7DH¡A¬O¤£¬O¤S«ì´_ì¼Æ¤F©O¡H¥Ñ©ó 2 ªº¸É¼Æ³o¨âÓ©w²z¡A¨Ï±o§Ú̦b¨D¬Y¤@µL¸¹¼Æªºµ¥È²§¸¹¼Æ®É¡A¥i¥H§Q¥Î 2 ªº¸É¼Æ¨Ó¹Bºâ¡C
¤Gªº¸É¼Æ¤]¥i¥H¥Î¥t¤@ºØ¤èªk¨D±o¡G
¨Ò¦p 0011 0100 ªº¤Gªº¸É¼Æ¥i¥H³o¼Ëºâ¡G¥ý¥Ñ¼Ð¥Ü¬õ¦âªº²Ä¹s¦ì¤¸¶}©l¡A¨ä¤Gªº¸É¼Æ¬° 0¡A¦A¨Ó¬O¥Õ¦âªº¡A¨ä¤Gªº¸É¼Æ¬° 0¡A¦A¨Ó¬OÂŦ⪺¡A¤£¹L³o¦¸¬O 1¡A¦]¦¹§â¥¦¶ñ¤J 1¡A±µ¤U¨Óªº¦ì¤¸¨Ì§Ç¤ÏÂà¡A¦]¦¹³Ì«á±o¨ìªºµª®×¬O 1100 1100¡C
¤W±¤p¤ì°¸¥H 8 ¦ì¤¸¬°¨Ò¡A»¡©ú¤F¦³¸¹¼Æªº©w¸q¥H¤Î¬°¦ó¦p¦¹©w¸q¡A¤]»¡©ú¤F¦p¦ó¨Ï¥Î 2 ªº¸É¼Æ¡C¹ï©ó 16¡B32¡B64 ¦ì¤¸ªº¾ã¼Æ¨ÓÁ¿¡A¤]¬O¤@¼Ëªº¡C
»¡¤F³o»ò¦h¤Gªº¸É¼Æªº¨Dªk§Yì²z¡A¨º»ò¤Gªº¸É¼Æ¨s³º¦³¦ó¥Î³~©O¡Hì¨Ó¤Gªº¸É¼Æ°£¤F¥i¥Î¨Ó¨D¬Û¤Ï¼Æ¤§¥~ ( ©Î»¡¨D¤G¶i¦ìªºt¼Æ )¡AÁÙ¥i¥H¥Î¦b§â´îªk·í¦¨¥[ªk¨Ó¹Bºâ¡C¨Ò¦p 100¡Ð20 ¥i¥H¬Ý¦¨ 100¡Ï(¡Ð20)¡A20 ªº¤Gªº¸É¼Æ¤£´N¬O ¡Ð20 ¶Ü¡H¦]¦¹¦b³]p CPU ªº¹q¸ô¤W¡A¥un¦b CPU ùØ¥[¤W§â¼ÆÈÅܦ¨¤Gªº¸É¼Æªº½u¸ô¡A´N¥i¥H¤£¥Î¥h³]p´îªkªº¹q¸ô¡C
NEG «ü¥O¬O 8086 «ü¥O¶°¤¤ªº¤@Ó«ü¥O¡A³oÓ«ü¥Oªº»yªk¬O¡G
NEG ¥Øªº¹Bºâ¤¸
¦¹«ü¥O§â¥Øªº¹Bºâ¤¸§@ 2 ªº¸É¼Æ¹Bºâ ( §Y§â©Ò¦³¦ì¤¸¤ÏÂà¦A¥[¤@ ) ¤§«áªºµ²ªG¡A¦A¦s¦^¥Øªº¹Bºâ¤¸ùØ¡A¦]¦¹¥Øªº¹Bºâ¤¸·|³Q¯}Ãa¡C¥Øªº¹Bºâ¤¸¥i¥H¬O 8 ©Î 16 ¦ì¤¸ªº¼È¦s¾¹©ÎÅܼơAY¦b 80386 µ¥¯Å¥H¤Wªº CPU¡A¥Øªº¹Bºâ¤¸¥i¥H¨Ï¥Î 32 ¦ì¤¸ªº¼È¦s¾¹©ÎÅܼơC
NOT «ü¥O¤]¬O 8086 «ü¥O¶°¤¤ªº¤@Ó«ü¥O¡A¨ä»yªk¬O¡G
NOT ¥Øªº¹Bºâ¤¸
¦¹«ü¥O§â¥Øªº¹Bºâ¤¸§@ 1 ªº¸É¼Æ¹Bºâ ( §Y§â©Ò¦³¦ì¤¸¤ÏÂà ) ¤§«áªºµ²ªG¡A¦A¦s¦^¥Øªº¹Bºâ¤¸ùØ¡A¦]¦¹¥Øªº¹Bºâ¤¸·|³Q¯}Ãa¡C¥Øªº¹Bºâ¤¸¥i¥H¬O 8 ©Î 16 ¦ì¤¸ªº¼È¦s¾¹©ÎÅܼơAY¦b 80386 µ¥¯Å¥H¤Wªº CPU¡A¥Øªº¹Bºâ¤¸¥i¥H¨Ï¥Î 32 ¦ì¤¸ªº¼È¦s¾¹©ÎÅܼơC
¦pªGn§â¤Q¤»¶i¦ì¦³¸¹¼ÆÂà´«¦¨¤Q¶i¦ì¼Æªº¨BÆJ¦p¤U¡G
¦pªGn§â¤Q¶i¦ì¦³¸¹¼ÆÂà´«¦¨¤Q¤»¶i¦ì¼Æªº¨BÆJ¦p¤U¡G
«e±´£¹L¡A§ÚÌ¥H¼ÆӦ줸¡A¥i¯à¬O¤KÓ¡B16 Ó¡B32 ӬƦܬO 64 Ӧ줸¨ÓÀx¦s¾ã¼Æ¡A¦b³\¦h¹Bºâ¤¤¡A±`±`»Ýn§â³o¨ÇÀx¦sªÅ¶¡Åܤj¡A¨Ò¦p§â¦s¦b AL ¼È¦s¾¹ùتº¥¿¾ã¼Æ©Ît¾ã¼ÆÅܦ¨¦s¦b AX ¼È¦s¾¹ùØ¡C¦³Ãö³o¨Ç¥\¯à¡A80x86 «ü¥O¶°´£¨Ñ¤F¥|ºØ«ü¥O¡G
³oÓ«ü¥Oªº»yªk¬O
CBW
¨ä«á¨S¦³¹Bºâ¤¸¡A¦]¬°¥¦©T©w§â AL ªº²Å¸¹¦ì¤¸«þ¨©¨ì AH ¼È¦s¾¹ùØ ( §ÚÌ¥ç¥i¥H·Q¦¨¡y²Å¸¹ÂX¥R¡z)¡C¨Ò¦pì¨Ó AX ¬° 1B23H¡A¸g CBW ¹Bºâ«á¡AAX Åܬ° 0023H¡F¦pªG AX ì¨Ó¬° 1B89H ( AL¡×¡Ð119d )¡A¸g CBW ¹Bºâ«á¡AAX Åܦ¨ FF89H ( AX¡×¡Ð119d )¡C¬G¨ä CBW ¥i¥H§â¤K¦ì¤¸ªº¼ÆÈ¡AÅܦ¨¤Q¤»¦ì¤¸¥B¨ä¥¿t¸¹¤£ÅÜ¡A^¤å¬°¡yconvert byte to word¡z¡C
³oÓ«ü¥Oªº»yªk¬O
CWD
CWD ¬O§â AX ¼È¦s¾¹ªº²Å¸¹¦ì¤¸ÂX¥R¨ì DX¡A¥ç§Y§â¦s¦b AX ¼È¦s¾¹ªº¦³¸¹¼ÆÂX¥RÅܦ¨ DX:AX¡CCWD ªº^¤å¬O¡yconvert word to doubleword¡z¡C
³oÓ«ü¥Oªº»yªk¬O
CDQ
CDQ ¬O§â EAX ¼È¦s¾¹ªº²Å¸¹¦ì¤¸ÂX¥R¨ì EDX¡A¥ç§Y§â¦s¦b EAX ¼È¦s¾¹ªº¦³¸¹¼ÆÂX¥RÅܦ¨ EDX:EAX¡CCWQ ªº^¤å¬O¡yconvert doubleword to quadword¡z¡A¥¦¥²¶·¦b 80386 µ¥¯Å©Î§ó°ª¯Åªº CPU ¤~¥i¥H¨Ï¥Î¡C
³oÓ«ü¥Oªº»yªk¬O
CWDE
CWDE ¬O§â AX ¼È¦s¾¹ªº²Å¸¹¦ì¤¸ÂX¥R¨ì EAX¡A¥ç§Y§â¦s¦b AX ¼È¦s¾¹ªº¦³¸¹¼ÆÂX¥RÅܦ¨ EAX¡CCWDE «ü¥O»P CWD «ü¥OÂX¥Rªº²Å¸¹¦ì¤¸¬O¤£¦Pªº¡CCWDE ¥²¶·¦b 80386 µ¥¯Å©Î§ó°ª¯Åªº CPU ¤~¥i¥H¨Ï¥Î¡C
¥ú»¡¤£½m¬O¤£¦æªº¡A©³¤U¤p¤ì°¸Á|¤@Ó¨Ò¤l¨Ó»¡©ú¦³¸¹¼Æªº¹Bºâ¡C³oÓ¨Ò¤l¥i¥Ñ¨Ï¥ÎªÌ¿é¤J¤Q¶i¦ìªº¨â¼Æ ( ¥i¬°¥¿©Ît¼Æ )¡Aµ{¦¡·|pºâ¨â¼Æ¤§®t¨ÃÅã¥Ü©ó¿Ã¹õ¤W¡Cµ{¦¡¦p¤U¡G
;SUB¡Ð¥»µ{¦¡¥iÅý¨Ï¥ÎªÌ¿é¤J¨âӼƦr¡AµM«ápºâ¦¹¤G¼Æ¤§®t¡AÅã¥Ü©ó¿Ã¹õ .386 ;*********************************************************** code segment use16 assume cs:code,ds:code org 100h ;----------------------------------------------------------- start: jmp short begin msg0 db 'Input minuend : $' ;¿é¤J³Q´î¼Æ¤Î´î¼Æ¡A¥² msg1 db 0dh,0ah,'Input subtrahend : $' ;¶·¦b-2147483648»P msg2 db 7,'Input error!$' ;2147483647¤§¶¡ answer db 0dh,0ah,40 dup (' ') buffer db 12,13 dup (0) n1 dd ? n2 dd ? begin: mov dx,offset msg0 call input jc error mov n1,edx mov di,offset answer+2 call hex2dec mov al,'-' stosb mov dx,offset msg1 call input jc error mov n2,edx call hex2dec mov al,'=' stosb mov edx,n1 sub edx,n2 call hex2dec mov al,'$' stosb mov dx,offset answer jmp short ok error: mov dx,offset msg2 ok: mov ah,9 int 21h mov ax,4c00h int 21h ;----------------------------------------------------------- input proc near mov ah,9 int 21h mov dx,offset buffer mov ah,0ah int 21h sub eax,eax mov cl,'+' ;CL°O¿ý¨Ï¥ÎªÌ¿é¤Jªº¥¿t¸¹ mov edx,eax ;EDX¬°¨Ï¥ÎªÌ¿é¤Jªº¤Q¤»¶i¦ì¦³¸¹¼Æ mov si,offset buffer+2 ;§â¿é¤Jªº¤Q¶i¦ì¦³¸¹¼Æ¡AÅܦ¨¤Q¤»¶i¦ì¤§µ´¹ïÈ¡A¦s©óEDX ipt0: lodsb cmp al,'-' ;§PÂ_¨Ï¥ÎªÌ¿é¤J¥¿¼ÆÁÙ¬Ot¼Æ jne ipt1 mov cl,al jmp ipt0 ipt1: cmp al,'+' je ipt0 cmp al,0dh je ipt2 cmp al,'0' jb ipt4 cmp al,'9' ja ipt4 sub al,'0' shl edx,1 ;³o¥|¦æ¹Bºâ¨ÏEDX¼¥H10¿ mov ebx,edx shl edx,2 add edx,ebx add edx,eax jmp ipt0 ;Y¨Ï¥ÎªÌ¿é¤Jªº¬°t¼Æ¡A«h§âµ´¹ïÈÅܦ¨2ªº¸É¼Æ ipt2: cmp cl,'-' jne ipt3 neg edx ipt3: clc jmp short ipt5 ipt4: stc ipt5: ret input endp ;----------------------------------------------------------- hex2dec proc near ;§âEDX¤º©Ò¦sªº¤Q¤»¶i¦ì¦³¸¹¼ÆÅܦ¨¤Q¶i¦ì¦³¸¹¼Æ¡A¦s©óDI©Ò«üªº¦ì§} jmp short h2d0 tmp db 10 dup (' ') h2d0: test edx,80000000h ;Àˬd¬O§_¬°t¼Æ jz h2d1 mov al,'-' ;Y¬°t¼Æ¡A«h¨ú¨ä2ªº¸É¼Æ¡A¨Ã neg edx ;©óDI©Ò«ü¦ì§}¦s¤Jt¸¹ stosb h2d1: push di mov ebx,10 ;¨ÏEDX¨C¦¸°£¥H10¡A©Ò±oªº¾l¼Æ mov eax,edx ;¤À§O¬°¤Q¶i¦ìªºÓ¦ì¼Æ¡B¤Q¦ì¼Æ¡B mov di,offset tmp+9 ;¦Ê¦ì¼Æ¡K¡K¡A§â³o¨Ç¾l¼Æ¼È®É¦s©ó mov cx,bx ;tmp¦r¦ê¤¤(¥Ñ°ª¦ì§}¶}©l¦s) h2d2: sub edx,edx div ebx add dl,'0' mov [di],dl or eax,eax jz h2d3 dec di loop h2d2 h2d3: mov si,di ;§âtmp¦r¦ê¤¤ªº¨C¤@¦ì¼Æ¡A¦s¤J pop di ;DI©Ò«ü¦ì§} sub bx,cx mov cx,bx inc cx rep movsb ret hex2dec endp ;----------------------------------------------------------- code ends ;*********************************************************** end start
§â¤Wzì©l½X¦s©ó SUB.ASM ùØ¡AµM«á¥Î MASM 5.x ©Î MASM 6.x ²ÕĶ¡A¦pªG§A¥Î MASM 5.x ²ÕĶªº¸Ü¡A¶·¸g¹L¤TÓ¨BÆJ¡G
E:\HOMEPAGE\SOURCE>masm sub; [Enter] Microsoft (R) Macro Assembler Version 5.00 Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved. 51564 + 336180 Bytes symbol space free 0 Warning Errors 0 Severe Errors E:\HOMEPAGE\SOURCE>link sub; [Enter] Microsoft (R) Personal Computer Linker Version 2.40 Copyright (C) Microsoft Corp 1983, 1984, 1985. All rights reserved. Warning: no stack segment E:\HOMEPAGE\SOURCE>exe2bin sub sub.com [Enter] E:\HOMEPAGE\SOURCE>
¦pªG¨Ï¥Î MASM 6.x ²ÕĶ¡A«h¥u»Ý¤@Ó¨BÆJ¡G
E:\HOMEPAGE\SOURCE>ml /AT sub.asm [Enter]
Microsoft (R) Macro Assembler Version 6.11
Copyright (C) Microsoft Corp 1981-1993. All rights reserved.
Assembling: sub.asm
Microsoft (R) Segmented Executable Linker Version 5.31.009 Jul 13 1992
Copyright (C) Microsoft Corp 1981-1992. All rights reserved.
Object Modules [.obj]: sub.obj/t
Run File [sub.com]: "sub.com"
List File [nul.map]: NUL
Libraries [.lib]:
Definitions File [nul.def]:
E:\HOMEPAGE\SOURCE>
¤£ºÞ¥Î MASM 5.x ©Î MASM 6.x ³£À³¸Ó¯à¶¶§Q²ÕĶ¦¨¥\¡A¦pªG¦³¿ù»~¡A¥i¯à¬O§ä¤£¨ìµ{¦¡¦ì¸m¡A½Ð¥Î path «ü¥O³]¦n MASM.EXE¡BML.EXE¡BLINK.EXE µ¥µ{¦¡©Ò¦b¤l¥Ø¿ý¡C²ÕĶ¦n¤§«á¥i°õ¦æ SUB.COM
E:\HomePage\SOURCE>sub [Enter] Input minuend : 10 [Enter] Input subtrahend : 100 [Enter] 10-100=-90 E:\HomePage\SOURCE>
§Ú·Q©Ò¦³ªºì²z³£¦b¤W±¡yì²z¡zªº¬q¸¨¤¤±Ôz¹L¤F¡A¦]¦¹¤£¦A»¡©ú¤F¡A©³¤U¨Ó½Í½Í·¸¦ì ( overflow ) ªº°ÝÃD¡C
SUB.ASMµ{¦¡¦³¨âÓ¿ù»~ªº¦a¤è¡A¨Ò¦p¡A¦pªG§A¹ï SUB §@¥H¤U¿é¤J¡G
E:\HOMEPAGE\SOURCE>sub [Enter] Input minuend : 3 [Enter] Input subtrahend : -2147483648 [Enter] 3--2147483648=-2147483645¡@¡@¡@¡÷²Ä¤@Ó·¸¦ì¿ù»~ªº¨Ò¤l E:\HOMEPAGE\SOURCE>sub [Enter] Input minuend : 2147483648 [Enter] Input subtrahend : 3 [Enter] -2147483648-3=2147483645¡@¡@¡@¡÷²Ä¤GÓ·¸¦ì¿ù»~ªº¨Ò¤l E:\HOMEPAGE\SOURCE>
¦b¤W±²Ä¤@Ó¨Ò¤l¤¤¡A¥ô¦ó¾Ç¹L°ê¤@¼Æ¾Çªº¤H³£ª¾¹D 3 ´î¥h ¡Ð2147483648 ©Ò±o®tÀ³¬° 2147483651 ¤~¹ï¡A¨Ã«D ¡Ð2147483645¡C¨º»ò¬°¤°»ò·|²£¥Í¿ù»~©O¡Hì¨Ó¥Î 32 ¦ì¤¸ªºªÅ¶¡nªí¥Ü¦³¸¹¼Æ¡A³o¦³¸¹¼Æ¥u¯à¦b ¡Ð2147483648 ¨ì ¡Ï2147483647 ¤§¶¡¡A²{¦b©Ò±oµ²ªG¶W¹L³o½d³ò¤F¡A´N²£¥Í·¸¦ì ( overflow ) ¿ù»~¤F¡C
©Ò¿×·¸¦ì¡A¬O«üpºâªºµ²ªG¶W¹L¼È¦s¾¹©Î°O¾ÐÅé©Ò¯àªí¥Üªº½d³ò¡C¦b 80x86 ®a±Úªº CPU ùØ¡A¦pªG¦³·¸¦ìªº±¡§Î²£¥Í¡ACPU ·|¦Û¦æ±N·¸¦ìºX¼Ð³]¬° 1¡A§Y OV ( ½Ð°Ñ¾\ªþ¿ý¤G )¡C·|µo¥Í·¸¦ìªº±¡§Î¦³¤TºØ¡G
¨â¦P¸¹¼Æ¬Û¥[©Î¨â²§¸¹¼Æ¬Û´î¡A¥i¯à·|²£¥Í·¸¦ì¡A¨Ò¦p¡G
mov eax,2147483647 add eax,2
©Ò±oµ²ªGÀ³¬° 2147483649¡A¦ý¶W¹L¤F 32 ¦ì¤¸¦³¸¹¼Æªº½d³ò¡A¦]¦¹²£¥Í·¸¦ì¡C§ó¸Ô²Óªº¨Ò¤l¦b¦¹³B¡C
¼°£¹Bºâ®É¡A©Ò±oªº¿n©Î°Ó¶W¹L¹Bºâ¤¸¦s©ñ½d³ò¡A¨Ò¦p¡G
mev eax,2147483640 imul eax,2
©Ò±oµ²ªGÀ³¬° 4294967280¡A¤]¶W¹L¤F ¡Ð2147483648 ¨ì ¡Ï2147483647¡A¦]¦¹¤]·|²£¥Í·¸¦ì¡C
¦b²¾¦ì©Î±ÛÂà«ü¥O®É¡A³Ì°ª¦ì¤¸È¨ü¨ì§ó°Ê ( 0 Åܦ¨ 1 ©Î 1 Åܦ¨ 0 ) ®É¡A¨Ò¦p¡G
mov ax,7000h ; AX=0111 0000 0000 0000 shl ax,1
¹Bºâ«á¡AAX Åܦ¨ 1110 0000 0000 0000¡A¦]¦¹¤]·|¨Ï·¸¦ìºX¼Ð³]¬° OV¡C
¤F¸Ñ·¸¦ì²£¥Íªºì¦]«án¸Ñ¨M²Ä¤@Ó°ÝÃD¡AÀ³¸Ó¬O¤£Ãøªº¡C¥un¦b¨â¼Æ¬Û´î¤§«á¡AÀˬd¬O§_¦³·¸¦ì§Y¥i¡C
²Ä¤GÓ¨Ò¤lµo¥Í¿ù»~ªºì¦]¬O¨Ï¥ÎªÌ¿é¤Jªº¦³¸¹¼Æ¶W¹L¤F ¡Ð2147483648 ¨ì ¡Ï2147483647 ½d³ò ( ¨Ï¥ÎªÌ¿é¤J ¡Ï2147483648 )¡A¥HP©ó¦b input °Æµ{¦¡ùØ¡Apºâ¨Ï¥ÎªÌ©Ò¿é¤Jªº¡y2147483648¡z¦r¦ê´«¦¨¦³¸¹¼Æ®É¡A·|Åܦ¨ 80000000h¡AÅܦ¨t¼Æ¤F¡C³o¬O¤@ºØÅÞ¿è¤Wªº¿ù»~¡An¸Ñ¨M³oÓ°ÝÃD¡A¥i¥HÀˬd·í¨Ï¥ÎªÌ¿é¤J¬O¥¿¼Æ®É¡A³Ì°ª¦ì¤¸À³¬° 0¡F¤Ï¤§Y¨Ï¥ÎªÌ¿é¤Jt¼Æ¡A³Ì°ª¦ì¤¸À³¬° 1¡C§ï¼g«áªºµ{¦¡¡ASUB1.ASM ¦p¤U¡G( ¬°¤F¸`¬Ù½g´T¡A¥u¦C¥X¤@³¡¥÷ )
¡K¡K msg2 db 7,0dh,0ah,'Input error!$' ;2147483647¤§¶¡ msg3 db 'ovwerflow!' answer db 0dh,0ah,40 dup (' ') lenmsg3 equ offset answer-offset msg3 buffer db 12,13 dup (0) ¡K¡K mov edx,n1 sub edx,n2 jo ovflow ;Àˬd¨â¦³¸¹¼Æ¬Û´î¡A¬O§_·¸¦ì call hex2dec ;¨Sµo¥Í·¸¦ì¡A¦L¥Xµª®× jmp short ok0 ovflow: mov ecx,lenmsg3 ;·¸¦ìµo¥Íªí¥Üµª®×¬O¿ùªº mov si,offset msg3 rep movsb ok0: mov al,'$' stosb ¡K¡K input proc near mov ah,9 int 21h mov dx,offset buffer mov ah,0ah int 21h sub eax,eax mov cl,'+' mov edx,eax mov si,offset buffer+2 ;§â¿é¤Jªº¤Q¶i¦ì¦³¸¹¼Æ¡AÅܦ¨¤Q¤»¶i¦ì¤§µ´¹ïÈ¡A¦s©óEDX ipt0: lodsb cmp al,'-' ;§PÂ_¨Ï¥ÎªÌ¿é¤J¥¿¼ÆÁÙ¬Ot¼Æ jne ipt1 mov cl,al jmp ipt0 ipt1: cmp al,'+' je ipt0 cmp al,0dh je ipt2 cmp al,'0' jb ipt5 cmp al,'9' ja ipt5 sub al,'0' shl edx,1 ;³o¥|¦æ¹Bºâ¨ÏEDX¼¥H10¿ mov ebx,edx shl edx,2 add edx,ebx add edx,eax jmp ipt0 ;Y¨Ï¥ÎªÌ¿é¤Jªº¬°t¼Æ¡A«h§âµ´¹ïÈÅܦ¨2ªº¸É¼Æ ipt2: cmp cl,'-' jne ipt3 neg edx test edx,80000000h ;Àˬd¨Ï¥ÎªÌ¿é¤Jt¼Æ®É¡A³Ì°ª¦ì¤¸ jz ipt5 ;¬O§_¬°1 jmp short ipt4 ipt3: test edx,80000000h ;Àˬd¨Ï¥ÎªÌ¿é¤J¥¿¼Æ®É¡A³Ì°ª¦ì¤¸ jnz ipt5 ;¬O§_¬°0 ipt4: clc jmp short ipt6 ipt5: stc ipt6: ret input endp ¡K¡K
CPU ¬O¦p¦óª¾¹D¹Bºâµ²ªG¬O§_·¸¦ì©O¡H¤p¤ì°¸·Q¥H¤U±¨Ò¤l¨Ó»¡©ú¡G
0111 1111 ¡× 07FH ¡× 127D ¡Ï 0000 0010 ¡× 002H ¡× 2D ------------------------------------------- 1000 0001 ¡× 081H ¡× 129D(µL¸¹¼Æ) ©Î ¡Ð127D(¦³¸¹¼Æ)
¤W±¬O¤K¦ì¤¸ªº¦³¸¹¼Æ¥[ªk¡A³oÓ¥[ªk¹Bºâ«á©Ò±o¤§©M¶W¹L ¡Ð128 ¨ì ¡Ï127¡A¦]¦¹·¸¦ìºX¼Ð·|³Q³]©w¡CÅý§Ų́ӱ´°Q³o¹Bºâªº¹Lµ{¡C¤G¶i¦ìªº¥[ªk¹Bºâ¤@¦p¤Q¶i¦ì¡A¦^·Q¤Q¶i¦ì¥[ªk¡A¦pªGÓ¦ì¬Û¥[µ²ªG¤p©ó©Îµ¥©ó 9¡A«h¤£¶i¦ì¡F¤Ï¤§¶W¹L 9¡A«h¶È¶È¼g¥X©MªºÓ¦ì¼Æ¦Ó¶i¦ì¡C¨Ò¦p¡G
24 ¡Ï 39 ------ 63
4 ¥[ 9 ±o 13¡A¼g 3 ¶i¤@¡C¤G¶i¦ì¥[ªk¤]¬O¦p¦¹¡A¤W±²Ä 0 ¦ì¤¸¬Û¥[¡A±o 1 ( ¦p¶À¦â¦r )¡A²Ä 1 ¦ì¤¸¬Û¥[¶W¹L 1¡A¼g¤WÓ¦ì¼Æ ( ¦p¬õ¦â¦r ) ¥B¶i¦ì¡A²Ä¤T¦ì¤¸¬Û¥[¦A¥[¤W¶i¦ìªº¤@¡A©Ò±oÁÙ¬O¶W¹L 1¡A¬G¼g¤W 0 ( ÂŦâ¦r ) ¥B¶i¦ì¡A¦p¦¹¬Û¥[¤@ª½¨ì²Ä 7 ¦ì¤¸µ²§ô¬°¤î¡C¥H¤W¬O ADD «ü¥Oªº¹B§@¡A¦ý¬O¦pªG¬O§â³o¬Û¥[ªº¨â¼Æ¬Ý¦¨¦³¸¹¼Æ¡A¦³¸¹¼Æªº²Ä¤C¦ì¤¸¨ä¹ê¶È¥Nªí¥¿t¸¹¡A·Ó²z»¡¤£À³¸Ó§â²Ä¤C¦ì¤¸°µ¥[ªk¹Bºâ¡A¤£¹L ADD «ü¥O¥i¤£ºÞ¨º»ò¦h¡A¤£ºÞ¦³¸¹©ÎµL¸¹¼Æ³£·Ó¼Ë¹Bºâ¡A¦Ó¥B ADD «ü¥O¤£ºÞ¬O¦³¸¹¼ÆÁÙ¬OµL¸¹¼Æ³£¥i¥Hºâ¥X©M¨Ó¡C¦]¦¹±¡§Î½ÆÂø±o¦h¡A¦Ò¼{©Ò¦³¹Bºâªº±¡§Î¥i¤À¦¨¤U¦C¤TºØ±¡§Î¡G
°²¦p¥¿¼Æ»P¥¿¼Æ¬Û¥[¡G³o®É¨â¼Æªº²Ä¤C¦ì¤¸³£¬°¹s¡A¥B©Ò±o¤§©MÀ³¬°¥¿¼Æ ( ¤]´N¬O©Mªº²Ä¤C¦ì¤¸À³¬° 0 )¡A¥i¥H¤À¦¨¨âºØ±¡§Î¨Ó°Q½×¡C²Ä¤@ºØ±¡§Î¬O¨â¼Æ¬Û¥[®É¡A²Ä¤»¦ì¤¸¤£µo¥Í¶i¦ì ( ÂŦ⪺ 1 )¡A¹³¤U¹Ï¥ª¦¡¡A¤S¦]¬°¥»¬O¨â¥¿¼Æ¬Û¥[¡A©Ò¥H²Ä¤C¦ì¤¸¬Û¥[¤´¬°¹s ( ¶À¦âªº 0)¡A³oºØ±¡§Î¬Û¥[¤£·|¦³·¸¦ìµo¥Í¡C
²Ä¤GºØ±¡§Î¬O²Ä¤»¦ì¤¸¬Û¥[µo¥Í¶i¦ì¨ì²Ä¤C¦ì¤¸¡A¹³¤W¹Ï¥k¦¡¡A·Ó²z»¡²Ä¤C¦ì¤¸¬O²Å¸¹¦ì¤¸À³¤£°Ñ»P¹Bºâ¡A©Î¤S¦]¬°¬O¨â¥¿¼Æ¬Û¥[¡A©Mªº²Ä¤C¦ì¤¸À³¬° 0¡A¦ý¦]²Ä¤»¦ì¤¸¶i¦ìµ²ªG©MÅܦ¨ 1¡A©MÅܬ°t¼Æ¡A³o¼Ë´N·|µo¥Í·¸¦ì¡C
°²¦pt¼Æ»Pt¼Æ¬Û¥[¡G³o®É¨â¼Æªº²Ä¤C¦ì¤¸³£¬°¤@¡A¥B©Ò±o¤§©MÀ³¬°t¼Æ ( ¤]´N¬O©Mªº²Ä¤C¦ì¤¸À³¬° 1 )¡A¤]¥i¤À¬°¨âºØ±¡§Î¨Ó°Q½×¡C²Ä¤@ºØ±¡§Î¬O²Ä¤»¦ì¤¸¬Û¥[¤£µo¥Í¶i¦ì¡A¹³¤U¹Ï¥ª¦¡¡A¨º»ò²Ä¤C¦ì¤¸¬Û¥[µ²ªG²Ä¤C¦ì¤¸¬°¹s¡A¥B·|µo¥Í¶i¦ì¡A³oºØ±¡§Î¬O·|µo¥Í·¸¦ì¡C
²Ä¤GºØ±¡§Î¬O²Ä¤»¦ì¤¸¬Û¥[µo¥Í¶i¦ì¡A¹³¤W¹Ï¥k¦¡¡A¤S¦]¬°²Ä¤C¦ì¤¸¬O¨âÓ¤@¬Û¥[¦A¥[¤W¶i¦ì¡Aµ²ªG²Ä¤C¦ì¤¸¤´¬O¤@¡A¥B²Ä¤C¦ì¤¸¤]µo¥Í¶i¦ì¡A³oºØ±¡§Î¤£·|µo¥Í·¸¦ì¡C
°²¦p¥¿¼Æ»Pt¼Æ¬Û¥[¡G¦]¬°¥¿t¼Æ·|¬Û®ø¡A©Ò¥H¤£ºÞ¥¿¼Æµ´¹ïȸû¤jÁÙ¬Ot¼Æµ´¹ïȸû¤j¡A³£¤£·|¦³·¸¦ìªº±¡§Îµo¥Í¡C³o®É¤]¤À¦¨¨âºØ±¡§Î¡C²Ä¤@ºØ±¡§Î¬O²Ä¤»¦ì¤¸¬Û¥[¤£µo¥Í¶i¦ì¡A¹³¤U¹Ï¥ª¦¡¡A³o®É²Ä¤C¦ì¤¸¬O¤@»P¹s¬Û¥[¤]¤£·|¶i¦ì¡C
²Ä¤GºØ±¡§Î¬O²Ä¤»¦ì¤¸¬Û¥[µo¥Í¶i¦ì¡A¹³¤U¹Ï¥k¦¡¡A³o®É²Ä¤C¦ì¤¸¬O¤@»P¹s¬Û¥[¦A¥[¤W²Ä¤»¦ì¤¸¶i¦ìªº¤@¡Aµ²ªG²Ä¤C¦ì¤¸¬Û¥[«á·|µo¥Í¶i¦ì¡C
¾ã²z¤W±©Ò¦³¦³¸¹¼Æ¬Û¥[ªº¤»ºØ±¡§Î¡A±z·í¥iµo²{¡A¦pªG¬O²Ä¤»¦ì¤¸¬Û¥[¤§µ²ªG»P²Ä¤C¦ì¤¸¬Û¥[¤§µ²ªG¡A¦P®É¶i¦ì©Î¦P®É¤£¶i¦ì¡A´N¤£·|µo¥Í·¸¦ì¡F¤Ï¤§¦pªG¤@¬°¶i¦ì¡A¤@¬°¤£¶i¦ì¡A´N·|µo¥Í·¸¦ì¡CCPU ¥i¥HÀË´ú²Ä¤»¦ì¤¸¬Û¥[¤§µ²ªG»P²Ä¤C¦ì¤¸¬Û¥[¤§µ²ªG¬O§_¦P®É¶i¦ì©Î¦P®É¤£¶i¦ì¡A¥Î³N»y¨Ó»¡¡A´N¬O¨Ï³o¨âÓ¶i¦ìȧ@ XOR ¹Bºâ¡A´N¥i§PÂ_¬O§_·¸¦ì¤F¡C
´îªk¡ASUB¡A¥i¥H¬Ý¦¨¬O³Q´î¼Æ»P´î¼Æªº 2 ªº¸É¼Æ¤§©M¡A½Ð¬Ý¤U±´XÓ¨Ò¤l¡G
¡@¡@¡@100¡Ð20¡×100¡Ï(¡Ð20) ¡@¡@¡Ð100¡Ð20¡×¡Ð100¡Ï(¡Ð20) ¡@100¡Ð(¡Ð20)¡×100¡Ï20 ¡Ð100¡Ð(¡Ð20)¡×¡Ð100¡Ï20
¤W±¥|Ó¦¡¤l¤¤¡A«e¨âÓ¦¡¤lªº´î¼Æ¬O 20¡A¨ä 2 ªº¸É¼Æ¬° ¡Ð20¡A¦]¦¹¥i¬Ý¦¨¬O³Q´î¼Æ»P´î¼Æªº 2 ªº¸É¼Æ¤§©M¡C¦Ó³Ì«á¨âӺ⦡¤¤ªº´î¼Æ¡A¡Ð20¡Aªº 2 ªº¸É¼Æ¬O 20¡A¤]¥i¥H¬Ý¦¨¬O³Q´î¼Æ»P´î¼Æªº 2 ªº¸É¼Æ¤§©M¡C¦]¦¹¦b´îªk¤¤¡A·¸¦ìºX¼Ðªº³]©w¥[ªk¬O¤@¼Ëªº¡C
MUL «ü¥O¥u¥Î©óµL¸¹¼Æ¤§¹Bºâ¡A¦]¦¹°õ¦æ§¹ MUL «áªº·¸¦ìºX¼Ð¤£«n±`©¿²¤¡A¨ä»yªk¬°¡G
MUL ¨Ó·½¹Bºâ¤¸
¨Ó·½¹Bºâ¤¸¬O¼¼Æ¡A¥¦¥i¥H¬O 8¡B16 ©Î 32 ¦ì¤¸ªº¼È¦s¾¹©Î¦s©ó 8¡B16 ©Î 32 ¦ì¤¸°O¾ÐÅ骺ÅܼơA¦Ó³Q¼¼Æ«h¬O©M¼¼Æ¤@¼Ëªø«×ªº AL¡BAX¡BEAX¡A80x86 ·|§â³Q¼¼Æ»P¼¼Æ¬Û¼µM«á§â¼¿n¦s©ó AX¡BDX:AX¡BEDX:EAX ùØ¡C¦p¤Uªí¡G
¼ªk¤è¦¡ | ³Q¼¼Æ | ¼¼Æ | ¼¿n | ½d¨Ò | |
¹Bºâ«e | ¹Bºâ«á | ||||
8 ¦ì¤¸ | AL | 8 ¦ì¤¸¼È¦s¾¹ ©ÎÅÜ¼Æ | AX | AX=0105 BX=0106 MUL BL | AX=001E BX=0106 |
16 ¦ì¤¸ | AX | 16 ¦ì¤¸¼È¦s¾¹ ©ÎÅÜ¼Æ | DX:AX | AX=0200¡ADX=FFFF BX=0106 MUL BX | DX=0002¡AAX=0C00 BX=0106 |
32 ¦ì¤¸ ¥u¯à¥Î©ó 386µ¥¯Å¥H¤W | EAX | 32 ¦ì¤¸¼È¦s¾¹ ©ÎÅÜ¼Æ | EDX:EAX | EAX=80000001 EDX=88887777 EBX=00000002 MUL EBX |
EDX=00000001 EAX=00000002 EBX=00000002 |
¨Ò¦p©³¤U 32 ¦ì¤¸¼ªk¡G
mov eax,80000001h mov edx,88887777h mov ebx,00000002h mul ebx
°õ¦æ§¹¡ymul ebx¡z«á¡AEDX ¬° 1¡AEAX ¬° 00000002¡A¬G©Ò±o¼¿n¬° 100000002H¡Aì¨Óªº EDX È·|®ø¥¢¤£¨£¡C¥Ñ¦¹¬Ý¨Ó MUL ¶È¶È°µ EAX »P EBX ¤§¼¿n¡A¥B§â EAX ·í°µ¥¿¼Æ¡CMUL ¹Bºâ§¹«á¦pªG¼¿nªº°ª¦ì¤¸³¡¥÷¤£¬°¹s¡A·¸¦ìºX¼Ð»P¶i¦ìºX¼Ð§¡·|³Q³]¬°¤@¡F¤Ï¤§¡A¦pªG¼¿nªº°ª¦ì¤¸³¡¥÷¬°¹s¡A·¸¦ìºX¼Ð»P¶i¦ìºX¼Ð§¡·|³Q³]¬°¹s¡C¨Ò¦p¤W±ªº¨Ò¤l¡A¦]¬° EDX ¤£¬°¹s¡A¬G·¸¦ìºX¼Ð·|³Q³]©w¡C
¦pnpºâ¦³¸¹¼Æªº¼ªk¡A¥²¶·¥Î IMUL «ü¥O¡AIMUL ªº»yªk»P MUL ¬Û¦P¡A¦ý¬O¥¦·|§â³Q¼¼Æªº²Å¸¹«O¯d¨ì¼¿nùØ¡C¨Ò¦p¤W±ªº¨Ò¤l¡A§â¡yMUL EBX¡z§ï¦¨¡yIMUL EBX¡z¡A©Ò±oµ²ªG¡AEDX:EAX ¬° FFFFFFFF:00000002¡C
IMUL ªº»yªk¦³¤TºØ§Î¦¡¡A¥i¥H¥u±µ¤@Ó¹Bºâ¤¸¡A©Î¨âÓ¡B©Î¤TÓ¹Bºâ¤¸¡G
IMUL ¼È¦s¾¹©Î°O¾ÐÅéÅܼÆ
IMUL 16¦ì¤¸¼È¦s¾¹,16¦ì¤¸¼È¦s¾¹©ÎÅÜ¼Æ IMUL 32¦ì¤¸¼È¦s¾¹,32¦ì¤¸¼È¦s¾¹©ÎÅÜ¼Æ IMUL 16¦ì¤¸¼È¦s¾¹,8©Î16¦ì¤¸±`¼Æ IMUL 32¦ì¤¸¼È¦s¾¹,8©Î32¦ì¤¸±`¼Æ
IMUL 16¦ì¤¸¼È¦s¾¹,16¦ì¤¸¼È¦s¾¹©ÎÅܼÆ,8©Î16¦ì¤¸±`¼Æ IMUL 32¦ì¤¸¼È¦s¾¹,32¦ì¤¸¼È¦s¾¹©ÎÅܼÆ,8©Î32¦ì¤¸±`¼Æ
²Ä¤@ºØ»yªkªº³W«h»P MUL ¬Û¦P¡A´N¤£ÂØz¡C²Ä¤GºØ»yªk IMUL «á±¨âÓ¹Bºâ¤¸¡A²Ä¤@Ó¹Bºâ¤¸ºÙ¬°¥Øªº¹Bºâ¤¸¡A²Ä¤GÓºÙ¬°¨Ó·½¹Bºâ¤¸¡AIMUL ·|§â¥Øªº¹Bºâ¤¸·í¦¨³Q¼¼Æ¡A¨Ó·½¹Bºâ¤¸·í¦¨¼¼Æ¡A¬Û¼¤§«áªº¼¿n¦s©ó¥Øªº¹Bºâ¤¸¡C²Ä¤TºØ»yªk«h¬O¦b IMUL ¤§«á±µ¤TÓ¹Bºâ¤¸¡A²Ä¤@Ó¹Bºâ¤¸¬O¥Øªº¹Bºâ¤¸¡A²Ä¤G¡B¤TÓ¹Bºâ¤¸¬O¨Ó·½ºâºâ¤¸¡AIMUL ¬O§â²Ä¤GÓ¹Bºâ¤¸·í¦¨³Q¼¼Æ¡A²Ä¤TÓ¹Bºâ¤¸·í¦¨¼¼Æ¡A¬Û¼¤§«áªº¼¿n¦s©ó²Ä¤@Ó¹Bºâ¤¸¡A¨âÓ¨Ó·½¹Bºâ¤¸¤£·|³Q¯}Ãa ( ²Ä¤TÓ¹Bºâ¤¸¥²©w¬O±`¼Æ¡A·íµM¤£·|§ïÅÜ )¡C
IMUL ³B²z·¸¦ìºX¼Ðªº¤è¦¡¬O§â¦³¸¹¼Æ¼¿n¦s©ó¤@¼È®ÉÅܼÆùØ¡AµM«á§â¦¹¼È®ÉÅܼƪº¸û§C¦ì¤¸¦s©ó¥Øªº¹Bºâ¤¸ªº§C¦ì¤¸ ( ¦¹³B¸û§C¦ì¤¸«üªº¬O¼¿n©Ò»Ý¦ì¤¸¤§¤@¥b¡A¨Ò¦p¼¼Æ¬O 8 ¦ì¤¸¡A«h³Q¼¼Æ¤]¬O 8 ¦ì¤¸¡A¬G¼¿nÀ³¬° 16 ¦ì¤¸¡A¸û§C¦ì¤¸§Y¼¿n¤§¸û§Cªº 8 ¦ì¤¸ )¡AY¦¹¸û§C¦ì¤¸ªº¥Øªº¹Bºâ¤¸ªº²Å¸¹ÂX¥R¤§«á§Y¬°¼È®ÉÅܼơA«h¶i¦ìºX¼Ð»P·¸¦ìºX¼Ð·|³Q²M°£¡F¤Ï¤§¡A¶i¦ìºX¼Ð»P·¸¦ìºX¼Ð·|³Q³]©w¡C«Ý§¹¦¨ºX¼Ð³]©w«á¡A¦A§â¥¿½T¼¿n¦s©ó¥Øªº¹Bºâ¤¸¡C¨Ò¦p¡G
mov al,30h mov bl,4h imul bl
¹Bºâ«á¤§¼¿n¬° 00C0h¡A¦s©ó¼È®ÉÅܼÆùØ¡A¸û§C¦ì¤¸ C0h ¦s©ó AL ÂX¥R²Å¸¹«á¬° FFC0h ( ¦] AL ªº²Ä¤C¦ì¤¸¬° 1¡AÂX¥R²Å¸¹¤§«á AH ©Ò¦³¦ì¤¸§¡¬°¤@ )¡A»P 00C0h ¤£¦P¡A¬G·¸¦ìºX¼Ð»P¶i¦ìºX¼Ð³£³Q³]©w¡C¦A¬Ý¥t¤@¨Ò¤l¡G
mov eax,30h mov ebx,4h imul ebx
¹Bºâ«á¤§¼¿n¬° 000000C0h¡A¦s©ó¼È®ÉÅܼÆùØ¡A¸û§C¦ì¤¸ 00C0h ¦s©ó AX ÂX¥R²Å¸¹«á¬° 000000C0h¡A»P¼È®ÉÅܼƬۦP¡A¬G·¸¦ìºX¼Ð»P¶i¦ìºX¼Ð³£·|³Q²M°£¡C¦A¬Ý¥t¤@¨Ò¤l¡G
mov eax,0FFFFFFFFh mov ebx,4h imul ebx
¹Bºâ«á¤§¼¿n¬° FFFFFFFCh¡A¦s©ó¼È®ÉÅܼÆùØ¡A¸û§C¦ì¤¸ FFFCh ¦s©ó AX ÂX¥R²Å¸¹«á¬° FFFFFFFCh¡A»P¼È®ÉÅܼƬۦP¡A¬G·¸¦ìºX¼Ð»P¶i¦ìºX¼Ð³£·|³Q²M°£¡C¦A¬Ý¥t¤@¨Ò¤l¡G
mov al,30h mov bl,-4h imul bl
¹Bºâ«á¤§¼¿n¬° FF40h¡A¦s©ó¼È®ÉÅܼÆùØ¡A¸û§C¦ì¤¸ 40h ¦s©ó AL ÂX¥R²Å¸¹«á¬° 0040h ( ¦] AL ªº²Ä¤C¦ì¤¸¬° 0¡AÂX¥R²Å¸¹¤§«á AH ©Ò¦³¦ì¤¸§¡¬° 0 )¡A»P FF40h ¤£¦P¡A¬G·¸¦ìºX¼Ð»P¶i¦ìºX¼Ð³£³Q³]©w¡C
DIV ªº»yªk¦b²Ä¤C³¹¤w¸g´£¹L¡A¦¹³B¤£¦AÂØz¡A³oùبӻ¡»¡·¸¦ìªº±¡§Î¡C·í DIV ¹Bºâ®É¡A¥i¯à·|µo¥Í¨âºØ¿ù»~¡A¤@ºØ¬O°£¥H¹sªº¿ù»~¡F¤@ºØ°Ó¼Æ¤Ó¤j¡A¥HP©óµLªk¦s¤J¥Øªº¹Bºâ¤¸ùØ¡C²Ä¤@ºØ±¡§ÎÅã¦Ó©ö¨£¡A¦b¼Æ¾Ç¤W°£¥H¹s¬OµL·N¸qªº¡A¦]¦¹³oºØ±¡§Î·|³y¦¨¿ù»~µo¥Í¡C²Ä¤GºØ±¡§Î¬O°Ó¼Æ¤Ó¤j¡A¨Ò¦p¤U±ªº¨Ò¤l¡G
mov ax,1000h mov bl,1 div bl
¦b¼Æ¾Ç¤WÁöµM³Ì«á°Ó¼ÆÀ³¸Ó¬O 1000H¡A¦ý¬O¹ï©ó 80x86 ®a±Úªº CPU ¦Ó¨¥¡A³o¬O 8 ¦ì¤¸ªº°£ªk¡A°Ó¼Æ¥u¯à©ñ¦b AL ¼È¦s¾¹ùØ¡AÅãµMªÅ¶¡¬O¤£°÷ªº¡A©Ò¥H·|³y¦¨·¸¦ì¡C¹ï©ó³o¨âºØ¿ù»~¡A80x86 ³£·|²£¥Í INT 0 ªº¿ù»~¡AINT 0 §Y²Ä¹s¸¹¤¤Â_¡A¥¦·|¦b¿Ã¹õ¤W¦L¥X¡yDivide overflow¡z¡AµM«á´Nµ²§ôµ{¦¡¡A¦^¨ì¨t²Î¡C¦p¦óÁקK³o¨âºØ¿ù»~©O¡H¹ï©óÁקK²£¥Í°£¥H¹sªº¿ù»~¡A¥un¦b°µ°£ªk¤§«eÀˬd°£¼Æ¬O§_¬°¹s§Y¥i¡A¨Ò¦p¡G
cmp bl,0 jz no_divide div bl ¡K¡K¡K no_divide:
¹ï©ó¦p¦óÁקK²Ä¤GºØ¿ù»~¡A¦³¤@ºØ¸û¬°®ø·¥ªº¤èªk¡A´N¬O§â°£ªk§ï¦¨¸û¦h¦ì¤¸ªº¹Bºâ¨Ò¦p 32 ¦ì¤¸¡FÁÙ¦³¤@ºØ¤èªk¡A´N¬Oק襤Â_¡A¤p¤ì°¸¥´ºâ¤U¤@³¹¤¶²Ð¡C
IDIV «ü¥Oªº»yªk»P DIV ¬Û¦P¡A©Ò¤£¦Pªº¦a¤è¦b©ó IDIV ¬O¶i¦æ¦³¸¹¼Æªº°£ªk¡A¬J¬O¶i¦æ¦³¸¹¼Æ°£ªk¡A´N±o¦b·N³Q°£¼Æ»P°£¼Æªº²Å¸¹¡A¦³®É¥i¥H¥Î CBW¡BCWD¡BCDQ µ¥«ü¥O¡A«Ü§Öªº§â AL¡BAX¡BEAX ªº²Å¸¹¦ì¤¸ÂX¥R¨ì AX¡BDX:AX¡BEDX:EAX¡A¥H¶i¦æ IDIV ¹Bºâ¡CIDIV ©M DIV ¤@¼Ë¡A¤]¥i¯à·|µo¥Í°£¥H¹s¤Î©Ò±o°Ó¤Ó¤jªº°ÝÃD¡A¸Ñ¨M¤èªk¤]Ãþ¦ü¡C¥t¥~¡AIDIV »P DIV ³£¤£·|¼vÅT¶i¦ìºX¼Ð»P·¸¦ìºX¼Ð¡C