.12.2 D10DWD (WORD1A WORD1B) (WORD2A WORD2B) (WORD3A WORD3B). : WORD1B BC62 WORD2B 553A : 1119C - .1119C AX. 1. , , ADD ADC (ADd with Carry). , CF , 1: WORD1A 0123 WORD2A 0012 1 : 0136 DEBUG 0136 AX, p 3601 WORD3A 9C11 WORD3B. .12.2 E10DWD . . c, - , . SI, DI BX 2. DEC . SUB reg,02 , .. , . , ADC. CLC (CLear Carry - ) . : 1) , 2) 3) CX . SBB (SuBtract with Borrow - ) ADC. E10DWD (.12.2) ADC SBB, . ------------------------------------------------------------ IBM PC. 12 265 , , , a . , , , , . , . , , , . +32767 +65535. . ADD SUB , . , . 249, - -7: 11111001 249 -7 00000010 2 +2 11111011 251 -5 . , +251 -5 . , . "" , p . "" , CX . , : CF OF 11111100 252 -4 00000101 5 +5 00000001 1 1 1 0 () , : CF OF 01111001 121 +121 00001011 11 +11 10000100 132 -124 0 1 () , : IBM PC. 12 266 CF OF 11110110 246 -10 10001001 137 -119 01111111 127 +127 1 1 () () ------------------------------------------------------------ MUL, - IMUL (Integer MULtiplication - ). . : " ". AL, . AX. p , AH. | AH | AL | | AX | :| || :|| " ". AX, - . , : () DX, () AX. , DX. | AX | | DX || AX | :|| : |.||.| | | MUL IMUL . : MUL MULTR MULTR (DB), AL MULTR. MULTR (DW), AX MULTR. , , : MUL CL ;-: AL, . AX MUL BX ;-: AX, . DX:AX IBM PC. 12 267 : MUL MUL (MULtiplication - ) . . 12.3 C10MUL : , . MUL .80 (128) .47 (64). - .2000 (8192) AX. ------------------------------------------------------------ ------------------------------------------------------------ . 12.3. . MUL . 10000000 p DX:AX. MUL BYTE1 . , AH . ( CBW p AL 0 1). - . 00400000 DX:AX. : IMUL IMUL (Integer MULtiplication - ) . . 12.3 D10IMUL , C10MUL, MUL IMUL. IMUL .80 ( ) .40 ( ). - .E000 AX. , MUL .2000, MUL IMUL. MUL .80 +128, IMUL - -128. -128 +64 -8192 .E000. ( .000 ). IMUL .8000 ( ) .2000 ( ). - .F0000000 DX:AX o . IMUL BYTE1 AX. , CBW AH: .80 p AL .FF80 AX. WORD1 , . : .00400000 IBM PC. 12 268 DX:AX - , MUL, . , , MUL IMUL . , , MUL , IMUL - . , DEBUG . : 2 (2,4,8 ..) . 1 CL. , AL AX: 2: SHL AL,1 8: MOV CL,3 SHL AX,CL : " " " ". , +32767. . . : 1365 12 2730 1365 16380 , . 13 65 12 , c : 13 65 12 12 26 130 13 65 156 780 , 13 , 15600: 15600 IBM PC. 12 269 +780 16380 , ( ) . . E10XMUL .12.4 . , MULTCND, , . 3206 . 2521. (DW) (DD) MOV, AX. MULTPLR . 6400. , PRODUCT, . MUL MULTPLR c MULTCND; - . 0E80 E400 PRODUCT+2 PRODUCT+4. MUL MULTPLR MULTCND, . 138A 5800. : 1: 0000 0E80 E400 2: 138A 5800 : 138A 6680 E400 ADD , c ADC (ADd with Carry). p 8086/8088, PRODUCT 8A13 8066 00E4. , PRODUCT 0000. ------------------------------------------------------------ ------------------------------------------------------------ .12.4. . " ". : 2 2 2 1 1 2 1 1 DX AX . F10XMUL . 12.4. IBM PC. 12 270 MULTCND . 3206 2521, MULTPLR - . 6400 0A26. PRODUCT, . , , ADD/ADC ADC, 0 PRODUCT. , ADC , . ADC 0, , 1, . ADD/ADC ADC, PRODUCT . 138A 687C 8E5C CCE6 PRODUCT . DEBUG. DX:AX ------------------------------------------------------------ p DX:AX . , (, , ) CX. , . 4 MOV CX,04 ; 4 C20: SHL DX,1 ; DX 1 SHL AX,1 ; AX 1 ADC DX,00 ; LOOP C20 ; 4 MOV CX,04 ; 4 D20: SHR AX,1 ; AX 1 SHR DX,1 ; DX 1 JNC D30 ; , OR AH,10000000B ; 1 AH D30: LOOP D20 ; , . CL. 4 , : MOV CL,04 ; SHL DX,CL ; DX 4 MOV BL,AH ; AH BL SHL AX,CL ; AX 4 SHL BL,CL ; BL 4 IBM PC. 12 271 OR DL,BL ; 4 BL DL ------------------------------------------------------------ DIV, a - IDIV. . : " ". AX, - . AH, - AL. ( +255 (.FF) +127 (.7F) ), . | AX | | AH | AL | : | | : ||| " ". DX:AX, - . DX, AX. +32767 (.FFFF) +16383 (.7FFF) . | DX || AX | | AH || AL | :|.||.| :|||| | | DIV IDIV . : DIV DIVISOR DIVISOR (DB), . DIVISOR (DW), . , , 13 3, 4 1/3. 4, - 1. , ( BASIC) 4,333.... (4) (,333). 1/3 333... , 1 . : DIV DIV . .12.5 D10DIV : , , . IBM PC. 12 272 DIV .2000 (8092) .80 (128). 00 AH, .40 (64) - AL. DIV BYTE1 . , AH . - . 12 AH, .05 - AL. DIV . 1000 DX . 0080 AX. DIV WORD1 DX. .0000 DX, . 0002 - AX. ------------------------------------------------------------ ------------------------------------------------------------ .15.5. . : IDIV IDIV (Integer DIVide) . .12.5 E10IDIV , D10DIV, DIV IDIV. IDIV .2000 ( ) .80 ( ). - . 00 AH , - . C0 (-64) - AL. DIV, , +64. : IDIV 2 EE (-18) FB (-5) 3 1000 (4096) 0080 (128) 4 0000 0002 4 , DIV. , , DIV IDIV p. , , DIV , IDIV - . , DEBUG . . 2 (2, 4, ..) . , AX: 2: SHR AX,1 IBM PC. 12 273 8: MOV CL,3 SHR AX,CL DIV IDIV, p. ( , ) . , , . . 1 , , . : - , , (AH) : - , , (DX) . , 1: : : 0123 01 (1)23 : 0001 4026 0001 (1)4026 . , DIV IDIV . p , DIVBYTE - , AX. , DIVWORD - , DX:AX. CMP AH,DIVBYTE CMP DX,DIVWORD JNB JNB DIV DIVBYTE DIV DIVWORD IDIV , , , , NEG . , . , 1. , . c , AX, - BX, CX: IBM PC. 12 274 SUB CX,CX ; C20: CMP AX,BX ; < , JB C30 ; SUB AX,BX ; INC CX ; JMP C20 ; 30: RET ; CX, AX CX , AX - o. . DX:AX, : 1. C20 AX BX DX. 2. SUB SBB DX,00. : . ------------------------------------------------------------ NEG . NEG 1. : NEG AX NEG BL NEG BINAMT ( ) 35- ( ) . , DX:AX 32- . NEG , . NOT: NOT DX ; NOT AX ; ADD AX,1 ; 1 AX ADC DX,0 ; DX : , , , . , , . , , ASCII-. ASCII- , . . IBM PC. 12 275 INTEL 8087 80287 ------------------------------------------------------------ , Intel 8087 ( 80287). 8087 8088, 80287 80286. , . 80- , 10 400 . 100 , . , . MASM, /E /R, , MASM /R. ------------------------------------------------------------ p. -128 +127. ADC . , CLC, 0. MUL DIV IMUL IDIV . . , . , AH ( ) DX ( ). c. SHR SAR . SHL SAL. . , FACTOR (DB), MUL FACTOR AL, DIV FACTOR AX. FACTOR (DW), MUL FACTOR AX, DIV FACTOR DX:AX. IBM PC. 12 276 ------------------------------------------------------------ : DATAX DW 0148H DW 2316H DATAY DW 0237H DW 4052H 12.1. ) DATAX DATAY; ) , DATAX, DATAY. 12.2. : STC MOV BX,DATAX ADC BX,DATAY 12.3. (MUL): ) DATAX DATAY; ) , DATAX, DATAY. 12.4. , , ? 12.5. (DIV): ) DATAX 23; ) , DATAX, DATAY. 12.6. " DX:AX" . . IBM PC. 13 1  13. II: ------------------------------------------------------------ II: ASCII BCD : ASCII BCD . ------------------------------------------------------------ a . 12, , . ASCII c . ASCII. , 23 00010111 .17; ASCII c 25 ASCII- p .3235. - ASCII- ASCII- . , , p 1 12. , BASIC Pascal, () . , () . ( ) (), . ASCII- ------------------------------------------------------------ , , ASCII-, , SAM 53414D, 1234 - . 31323334. , , , . , . 31323334, . ASCII-: IBM PC. 13 2 AAA (ASCII Adjust for Addition - ASCII-) AAD (ASCII Adjust for Division - ASCII-) AAM (ASCII Adjust for Multiplication - ASCII-) AAS (ASCII Adjust for Subtraction - ASCII-) AX. , ASCII , , . ASCII- 8 4 ASCII-: . 38 34 . 6C ASCII-, . , 6 6 .C: .C + 6 = .12 - . , , AAA . , , AX . 0038, BX - .0034. 38 34 ASCII , . : ADD AL,BL ; 34 38 AAA ; ASCII AAA . (4 ) AL. A F AF 1, AL 6, AH 1, AF CF 1. AAA 0 . AL. - AX: ADD: 006C AAA: 0102 , ASCII- , . : OR AX,3030H ; 3132 IBM PC. 13 3 . ASCII- , . , .13.1 ASCII- . : ADC, , () . CLC CF . ------------------------------------------------------------ ------------------------------------------------------------ . 13.1. ASCII-. MOV AH , AAA . ADC p. , XOR SUB o AH CF. , p AH (00 01) . 01020702. OR AAA , CF, p ADC. PUSHF, OR, , , POPF: ADC AL,[DI] ; AAA ; ASCII PUSHF ; OR AL,30H ; POPF ; MOV [BX],AL ; PUSHF POPF LAHF (Load AH with Flags - AH) SAHF (Store AH in Flag register - AH ). LAHF AH SF, ZF, AF, PF CF; SAHF AH . , , AH . ASCII- - OR . ASCII- IBM PC. 13 4 AAS (ASCII Adjust for Subtraction - ASCII-) a AAA. AAS . ( ) AL. A F AF 1, AL 6, AH 1, AF CF 1. AAS 0 . p AL. , ASC1 .38, ASC2 - .34: 1: AX AF MOV AL,ASC1 ;0038 SUB AL,ASC2 ;0034 0 AAS ;0004 0 2: AX AF MOV AL,ASC2 ;0034 SUB AL,ASC1 ;00FC 1 AAS ;FF06 1 1 AAS . 2, AL .C, AAS 6 AL 1 AH 1 AF CF. ( -4) . FF06, .. -4. ASCII- AAM (ASCII Adjust for Multiplication - ASCII ) ASCII AX. , . ASCII-. ( IBM p ). , ASCII- 31323334 01020304. , , , o- ; . AAM AL 10 (. 0A) AH, AL. , AL . 35, CL - .39. AL CL ASCII-: AX: AND CL,0FH ; CL 09 AND AL,0FH ; AL 05 0005 MUL CL ; AL CL 002D IBM PC. 13 5 AAM ; .. 0405 OR AX,3030H ; ASCII-- 3435 MUL 45 (.002D) AX, AAM 10, 04 AH 05 AL. OR p ASCII-