1 / 20

PART D-2

PART D-2. Processing Binary Data. 二进制数运算. 一、 Arithmetic Carry and Overflow ( 算术运算的进位和溢出 ) 1 . The Express Limit of Binary Data Unsigned : 8 位 —— 0 ~ 255 ; 16 位 —— 0 ~ 65535 Signed : 8 位 —— -128 ~ +127 ; 16 位 —— -32768 ~ +32767

binta
Télécharger la présentation

PART D-2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PART D-2 Processing Binary Data 二进制数运算

  2. 一、Arithmetic Carry and Overflow (算术运算的进位和溢出) 1.The Express Limit of Binary Data Unsigned: 8位—— 0~255; 16位—— 0~65535 Signed: 8位—— -128~+127; 16位—— -32768~+32767 2. 运算结果将影响OF(溢出)、CF(进位)等标志位。 For Example 1:

  3. For Example 2:

  4. For Example 3:

  5. For Example 4:

  6. 二、Addition and Subtraction of Binary Data (二进制数的加、减运算) ADD Object,Source ——字节或字相加 ADC Object,Source ——带进位加 INC Object ——字节或字加1 SUB Object,Source ——字节或字相减 SBB Object,Source ——带借位减法(有借位CF=1,否则CF=0) DEC Object ——字节或字减1 NEG Object ——求补(0-目的→目的)

  7. For Example: 从键盘上输入两个一位十进制数字,并将其转换成二进制数,再将它们相加后以两位十进制数字的形式输出结果。 (如,2+3=05 or 9+7=16)

  8. ⑴ Flow Chart: 〖19-8〗

  9. ⑵ Program: CODE SEGMENT ; 数字字符l → BL ASSUME CS:CODE ; 数字字符2 → DH START:MOV DL, ’?’ MOV AH, 02 INT 21H ;显示提示符“?” MOV AH, 01 INT 21H ;键入第一个0~9数字→AL MOV BL, AL SUB BL, 30h ;将第一个数字字符转换成数字 MOV DL,’+’ MOV AH, 02 INT 21H ;显示一个“+”号 MOV AH, 01 INT 21H ;键入第M个0~9数字→AL 〖19-9〗

  10. SUB AL, 30H ;转换成数字 MOV DH, AL MOV DL,’=’ MOV AH, 02 INT 21H ;显示“=” MOV AL, DH ADD AL,BL ;(AL)十(BL)→AL MOV AH, 0 MOV BL, 10 DIV BL ;(AX)÷10的商→AL,余数→AH MOV BL,AH ; 保存余数(个位)→BL MOV DL,AL ;商(十位数)→DL ADD DL,30H ;将其转换成ASCll码 MOV AH, 02 INT 21H ;显示十位数字 MOV DL,BL ;个位数字→DL

  11. ADD DL,30H ;转换成ASCll码 MOV AH,02 INT 21H ;显示个位数 MOV DL,ODH INT 21H ;回车 MOV DL,OAH INT 21H ;换行 MOV AH,4CH INI 21H CODE ENDS END START 〖19-11〗

  12. EXAMPLE: 一个双字相加的实例P.226 WORD1A:WORD1B+WORD2A:WORD2BWRD3A:WORD3B 〖19-12〗

  13. MULTIPLICATION MUL: handles unsigned data IMUL: handles signed data 1. Format: [label:] MUL/IMUL register/memory 2. Logic: AX ← source ×AL ; if source is a byte or DX:AX ← source ×AX ; if source is a word 3. Both instructions affect the carry and overflow flags. 〖19-13〗

  14. The Carry and Overflow flags are set if the upper half of the result (AH for a byte source, DX for a word source) contains any significant digits of the product, otherwise they are cleared. • The example ( P.230) : • Example of MUL instruction • Example of IMUL instruction 〖19-14〗

  15. DIVISION DIV: handles unsigned data IDIV: handles signed data 1. Format: [label:] DIV/IDIV register/memory 2. Logic: AL ← AX÷source ; if source is a byte AH ← remainder ; 余数交AH or AX ← DX:AX÷source ; if source is a word DX ← remainder 〖19-15〗

  16. 3. If the result is too large to fit in the destination (AL or AX), an INT 0 (Divide by Zero) is generated, and the quotient and remainder are undefined (i.e. the result is unpredictable). • The example ( P.237) : • Example of DIV instruction • Example of IDIV instruction 〖19-16〗

  17. 2 INSTRUCTIONS RELATED TO MULTIPLICATION AND DIVISION 1. CBW: Convert Byte to Word Logic: if (AL < 80h) then AH ← 0 else AH ← FFh • CBW extends the sign bit of the AL register into the AH register. 〖19-17〗

  18. 2. CWD: Convert Word to Double word Logic: if (AX < 8000h) then DX ← 0 else DX ← FFFFh • CWD extends the sign bit of the AX register into the DX register. 〖19-18〗

  19. Questions: Page 239 12 - 1 12 - 3 12 - 6 Note: BIN_AMT1 DW 0147H DW 139AH BIN_AMT2 DW 02B3H DW 2D41H

  20. 上机Exercise: 从键盘上输入两个一位十进制数字,并将其 转换成二进制数,再将它们相减后以两位十进制 数字的形式输出结果。 For Example, 5 – 3 = 02 or 3 – 8 = – 5 (注意差为负数的情况)

More Related