Microsoft PowerPoint - C15_LECTURE_NOTE_05.ppt

Similar documents
Microsoft PowerPoint - C15_LECTURE_NOTE_05.ppt

Microsoft PowerPoint - C15_LECTURE_NOTE_04.ppt

Microsoft PowerPoint - C15_LECTURE_NOTE_04.ppt

,768 32,767 32K JMP Jnnn (386+) LOOP CALL [Label:] JMP short/near/far address L10: jmp jmp L20: L10 L20

幻灯片 1

untitled

Microsoft PowerPoint - C15_LECTURE_NOTE_06

Microsoft PowerPoint - C15_LECTURE_NOTE_06

<4D F736F F F696E74202D20B5DAD2BBD5C228B4F2D3A1B0E6292E BBCE6C8DDC4A3CABD5D>

SuperMap 系列产品介绍

Microsoft PowerPoint - C15_LECTURE_NOTE_11

Microsoft PowerPoint - STU_EC_Ch08.ppt

Microsoft PowerPoint - STU_EC_Ch04.ppt

<4D F736F F D20C7B6C8EBCABDCFB5CDB3C9E8BCC6CAA6B0B8C0FDB5BCD1A75FD1F9D5C22E646F63>

(Load Project) (Save Project) (OffLine Mode) (Help) Intel Hex Motor

Microsoft PowerPoint - CA_02 Chapter5 Part-I_Single _V2.ppt

1 CPU

(Microsoft Word - \246D\252k\267\247\255n_\275\306\277\357_.docx)

2/80 2


<4D F736F F F696E74202D20BCC6A6ECA874B2CEBEC9BDD7C1BFB871B2C4A440B3B9>

穨control.PDF

CC213

els0xu_zh_nf_v8.book Page Wednesday, June, 009 9:5 AM ELS-0/0C.8

Microsoft PowerPoint - lecture4--Signal Processing on DSPs.ppt

Bus Hound 5

$$% % $ (%) % %$ $ ( *+,)(-)-./0-1//0- %) %) % - $%2)33%0 $ % ((3./. 3/3 )3 / % (()33(1 % (()3(/ %89856%:;< % (()3 0()0 3 (. <<=330(<</ 3 3. ()

(2) Function 0BH: Function 0CH: (pixel, picture element) Function 0DH: Function 0FH: Function 13H:

(Guangzhou) AIT Co, Ltd V 110V [ ]! 2

1 2 / 3 1 A (2-1) (2-2) A4 6 A4 7 A4 8 A4 9 A ( () 4 A4, A4 7 ) 1 (2-1) (2-2) ()

6-1 Table Column Data Type Row Record 1. DBMS 2. DBMS MySQL Microsoft Access SQL Server Oracle 3. ODBC SQL 1. Structured Query Language 2. IBM

4 / ( / / 5 / / ( / 6 ( / / / 3 ( 4 ( ( 2

C++ 程式設計

Microsoft PowerPoint - os_4.ppt

Important Notice SUNPLUS TECHNOLOGY CO. reserves the right to change this documentation without prior notice. Information provided by SUNPLUS TECHNOLO

bingdian001.com

数 学 高 分 的 展 望 一 管 理 类 联 考 分 析 第 一 篇 大 纲 解 析 篇 编 写 : 孙 华 明 1 综 合 能 力 考 试 时 间 :014 年 1 月 4 日 上 午 8:30~11:30 分 值 分 配 : 数 学 :75 分 逻 辑 :60 分 作 文 :65 分 ; 总

Microsoft PowerPoint - C15_LECTURE_NOTE_10.ppt

Microsoft PowerPoint - C15_LECTURE_NOTE_15

組譯與連結(Ver6

. v dx v d () () l s dl s d (_) d () v s v s () a dv a d (_) ( ) ( ) x- = v- = = v 0 = m/s a = = m/s 2 a- = ( ) x- v- a- Page 2 of 20

Visualize CMap

K301Q-D VRT中英文说明书141009

Chapter 3

Improved Preimage Attacks on AES-like Hash Functions: Applications to Whirlpool and Grøstl

例 009 年高考 全国卷Ⅱ 理 8 如 图 直 三 棱 柱 ABC ABC 中 AB AC D E 分 别为 AA BC 的中点 DE 平面 BCC 证明 AB AC 设二面角 A BD C 为 0o 求 BC 与平面 BCD 所 成角的大小 图 - 略 证明 以 D 为坐标原点 DA DC DD

Microsoft PowerPoint - chap3.ppt

C/C++语言 - C/C++数据

!!""# $ %#" & $$ % $()! *% $!*% +,-. / 0 %%"#" 0 $%1 0 * $! $#)2 "

untitled

+ 0!"#$ "#% $ % % & $ % % ( 3*&, % &2 $ $ 1 2% +2 $ +# - 4 # $5 # % &", % % $% ( "! "4+ "! " &" " " 5&+ 4"+ 404!8+ 54

168 健 等 木醋对几种小浆果扦插繁殖的影响 第1期 the view of the comprehensive rooting quality, spraying wood vinegar can change rooting situation, and the optimal concent

Microsoft Word - Final Exam Review Packet.docx


/ / (FC 3)...

PowerPoint Presentation

lan03_yen

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

Microsoft PowerPoint - notes3-Simple-filled12

AVR单片机指令系统.PDF

一、注意事项

T stg -40 to 125 C V cc 3.8V V dc RH 0 to 100 %RH T a -40 to +125 C -0.3 to 3.6V V -0.3 to VDD+0.3 V -10 to +10 ma = 25 = 3V) VDD

Microsoft Word - template.doc

.

入學考試網上報名指南

E170C2.PDF

untitled

第 15 章 程 式 編 写 語 言 15.1 程 式 編 写 語 言 的 角 色 程 式 編 寫 語 言 是 程 式 編 寫 員 與 電 腦 溝 通 的 界 面 語 法 是 一 組 規 則 讓 程 式 編 寫 員 將 字 詞 集 合 起 來 電 腦 是 處 理 位 元 和 字 節 的 機 器, 與

第五章 重叠、流水和现代处理器技术

Panaboard Overlayer help

2006年国家公务员招录考试行测真题(A)

<4D F736F F D20C1E3B5E3CFC2D4D8C4A3B0E52E646F63>


微處理機期末專題

(Microsoft Word - Motion Program \270\305\264\272\276\363 \307\245\301\366 \271\327 \270\361\302\367.doc)

逢 甲 大 學

Program Guide(中文).PDF

Windows XP

6 C51 ANSI C Turbo C C51 Turbo C C51 C51 C51 C51 C51 C51 C51 C51 C C C51 C51 ANSI C MCS-51 C51 ANSI C C C51 bit Byte bit sbit

1 VLBI VLBI 2 32 MHz 2 Gbps X J VLBI [3] CDAS IVS [4,5] CDAS MHz, 16 MHz, 8 MHz, 4 MHz, 2 MHz [6] CDAS VLBI CDAS 2 CDAS CDAS 5 2

VASP应用运行优化

錄...1 說...2 說 說...5 六 率 POST PAY PREPAY DEPOSIT 更

科学计算的语言-FORTRAN95

GSA Media Retention Web File xlsx

iml88-0v C / 8W T Tube EVM - pplication Notes. IC Description The iml88 is a Three Terminal Current Controller (TTCC) for regulating the current flowi

<4D F736F F D C4EAB9FABCD2B9ABCEF1D4B1D0D0D5FEC4DCC1A6B2E2D1E9A3A841C0E0A3A92E646F63>

untitled

Ps22Pdf

Ps22Pdf

51 C 51 isp 10 C PCB C C C C KEIL

3.1 num = 3 ch = 'C' 2

Microsoft Word - 最新正文.doc

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File

星河33期.FIT)

Eaton kVA 用户指南

TCP/IP TCP/IP OSI IP TCP IP IP TCP/IP TCP/IP

2

untitled

untitled

Transcription:

8088/8086 MICROPROCESSOR PROGRAMMING INTEGER INSTRUCTIONS AND COMPUTATIONS 8088/8086 MICROPROCESSOR PROGRAMMING INTEGER INSTRUCTIONS AND COMPUTATIONS 5.1 Data-Transfer Instructions 5.2 Arithmetic Instructions 5.3 Logic Instructions 5.4 Shift Instructions 5.5 Rotate Instructions 611 37100 微處理機原理與應用 Lecture 05-2 1

5.1 Data-Transfer Instructions The data-transfer functions provide the ability to move data either between its internal registers or between an internal register and a storage location in memory. The data-transfer functions include MOV (Move byte or word) XCHG (Exchange byte or word) XLAT (Translate byte) LEA (Load effective address) LDS (Load data segment) LES (Load extra segment) 611 37100 微處理機原理與應用 Lecture 05-3 5.1 Data-Transfer Instructions The MOVE Instruction The move (MOV) instruction is used to transfer a byte or a word of data from a source operand to a destination operand. Mnemonic Meaning Format Operation Flags affected MOV Move MOV D, S (S) (D) None e.g. MOV DX, CS MOV [SUM], AX 611 37100 微處理機原理與應用 Lecture 05-4 2

5.1 Data-Transfer Instructions The MOVE Instruction Note that the MOV instruction cannot transfer data directly between external memory. Destination Accumulator Seg-reg Seg-reg Reg16 Source Accumulator Immediate Immediate Reg16 Mem16 Seg-reg Seg-reg Allowed operands for MOV instruction 611 37100 微處理機原理與應用 Lecture 05-5 5.1 Data-Transfer Instructions The MOVE Instruction MOV DX, CS 0100 IP 0100 CS 0200 DS SS ES Address 01100 01101 01102 Content 8C CA Instruction MOV DX, CS Next instruction AX BX CX DX 02000 02001 SP BP SI DI 8088/8086 MPU Before execution 611 37100 微處理機原理與應用 Lecture 05-6 3

5.1 Data-Transfer Instructions The MOVE Instruction MOV DX, CS 0102 IP 0100 CS 0200 DS SS ES Address 01100 01101 01102 Content 8C CA Instruction MOV DX, CS Next instruction AX BX CX 0100 DX 02000 02001 SP BP SI DI 8088/8086 MPU After execution 611 37100 微處理機原理與應用 Lecture 05-7 5.1 Data-Transfer Instructions What is the effect of executing the instruction MOV CX, [SOURCE_MEM] Where SOURCE_MEM equal to 20 16 is a memory location offset relative to the current data segment starting at 1A000 16. ((DS)0+20 16 ) (CL) ((DS)0+20 16 +1 16 ) (CH) Therefore CL is loaded with the contents held at memory address 1A000 16 + 20 16 = 1A020 16 and CH is loaded with the contents of memory address 1A000 16 + 20 16 +1 16 = 1A021 16 611 37100 微處理機原理與應用 Lecture 05-8 4

5.1 Data-Transfer Instructions Use the DEBUG the verify the previous example. 611 37100 微處理機原理與應用 Lecture 05-9 5.1 Data-Transfer Instructions The XCHG Instruction The exchange (XCHG) instruction can be used to swap data between two general-purpose registers or between a generalpurpose register and a storage location in memory. Mnemonic Meaning Format Operation Flags affected XCHG Exchange XCHG D, S (D) (S) None e.g. XCHG AX, DX Destination Accumulator Source Reg16 611 37100 微處理機原理與應用 Lecture 05-10 Allowed operands for XCHG instruction 5

5.1 Data-Transfer Instructions What is the result of executing the following instruction? XCHG [SUM], BX Where SUM = 1234 16, (DS)=1200 16 ((DS)0+SUM) (BX) PA = 12000 16 + 1234 16 =13234 16 Execution of the instruction performs the following 16-bit swap: (13234 16 ) (BL) (13235 16 ) (BH) So we get (BX) = 00FF 16 (SUM) = 11AA 16 611 37100 微處理機原理與應用 Lecture 05-11 5.1 Data-Transfer Instructions The XCHG Instruction XCHG [SUM], BX 0101 IP 1100 CS 1200 DS SS ES Address 11101 11102 11103 11104 11105 Content 87 1E 34 12 Instruction XCHG [SUM],BX Next instruction AX 11 AA BX CX DX SP BP SI DI 8088/8086 MPU 12000 12001.... 13234 13235 FF 00 Variable SUM Before execution 611 37100 微處理機原理與應用 Lecture 05-12 6

5.1 Data-Transfer Instructions The XCHG Instruction XCHG [SUM], BX 0105 IP 1100 CS 1200 DS SS ES Address 11101 11102 11103 11104 11105 Content 87 1E 34 12 Instruction XCHG [SUM],BX Next instruction AX 00 FF BX CX DX SP BP SI DI 8088/8086 MPU 12000 12001.... 13234 13235 AA 11 Variable SUM After execution 611 37100 微處理機原理與應用 Lecture 05-13 5.1 Data-Transfer Instructions Use the DEBUG program to verify the previous example. 611 37100 微處理機原理與應用 Lecture 05-14 7

5.1 Data-Transfer Instructions Use the DEBUG program to verify the previous example. 611 37100 微處理機原理與應用 Lecture 05-15 5.1 Data-Transfer Instructions The XLAT Instruction The translate (XLAT) instruction is used to simplify implementation of the lookup-table operation. Execution of the XLAT replaces the contents of AL by the contents of the accessed lookup-table location. Mnemonic Meaning Format Operation Flags affected XLAT Translate XLAT ((AL)+(BX)+(DS)0) (AL) None e.g. PA = (DS)0 + (BX) + (AL) = 03000 16 + 0100 16 + 0D 16 = 0310D 16 (0310D 16 ) (AL) 611 37100 微處理機原理與應用 Lecture 05-16 8

5.1 Data-Transfer Instructions The LEA, LDS, and LES Instructions The LEA, LDS, LES instructions provide the ability to manipulate memory addresses by loading either a 16-bit offset address into a general-purpose register or a register together with a segment address into either DS or ES. Mnemonic Meaning Format Operation Flags affected LEA Load effective address LEA Reg16, EA EA (Reg16) None LDS Load register and DS LDS Reg16, Mem32 (Mem32) (Reg16) (Mem32+2) (DS) None LES Load register and ES LES Reg16,Mem32 (Mem32) (Reg16) (Mem32+2) (ES) None e.g. LEA SI, [DI+BX+5H] 611 37100 微處理機原理與應用 Lecture 05-17 5.1 Data-Transfer Instructions The LEA, LDS, and LES Instructions LDS SI, [200H] 0100 IP 1100 CS 1200 DS SS ES Address 11100 11101 11102 11103 11104 Content C5 36 00 02 Instruction LDS SI, [200H] Next instruction AX BX CX DX SP BP SI DI 12000 12001.. 12200 12201 12202 12203 20 00 00 13 8088/8086 MPU Before execution 611 37100 微處理機原理與應用 Lecture 05-18 9

5.1 Data-Transfer Instructions The LEA, LDS, and LES Instructions LDS SI, [200H] 0104 IP 1100 CS 1300 DS SS ES Address 11100 11101 11102 11103 11104 Content C5 36 00 02 Instruction LDS SI, [200H] Next instruction AX BX CX DX SP BP 0020 SI DI 8088/8086 MPU After execution 611 37100 微處理機原理與應用 Lecture 05-19 12000 12001.. 12200 12201 12202 12203.. 13000 13001 20 00 00 13 New data segment 5.1 Data-Transfer Instructions Verify the following instruction using DEBUG program. LDS SI, [200H] 611 37100 微處理機原理與應用 Lecture 05-20 10

5.1 Data-Transfer Instructions Initializing the internal registers of the 8088 from a table in memory. MOV AX, [INIT_TABLE] MOV SS, AX LDS SI, [INIT_TABLE+02H] LES DI, [INIT_TABLE+06H] MOV AX, [INIT_TABLE+0AH] MOV BX, [INIT_TABLE+0CH] MOV CX, [INIT_TABLE+0EH] MOV DX, [INIT_TABLE+10H] 611 37100 微處理機原理與應用 Lecture 05-21 5.2 Arithmetic Instructions The arithmetic instructions include Addition Subtraction Multiplication Division Data formats Unsigned binary bytes Signed binary bytes Unsigned binary words Signed binary words Unpacked decimal bytes Packed decimal bytes ASCII numbers 611 37100 微處理機原理與應用 Lecture 05-22 11

5.2 Arithmetic Instructions ADDITION ADD Add byte or word ADC Add byte or word with carry INC Increment byte or word by 1 AAA ASCII adjust for addition DAA Decimal adjust for addition SUBTRACTION SUB Subtract byte or word SBB Subtract byte or word with borrow DEC Decrement byte or word by 1 NEG Negate byte or word AAS ASCII adjust for subtraction DAS Decimal adjust for subtraction MULTIPLICATION MUL Multiply byte or word unsigned IMUL Integer multiply byte or word AAM ASCII adjust for multiply DIVISION DIV Divide byte or word unsigned IDIV Integer divide byte or word AAD ASCII adjust for division CBW Convert byte to word CWD Convert word to doubleword 611 37100 微處理機原理與應用 Lecture 05-23 5.2 Arithmetic Instructions Addition Instructions: ADD, ADC, INC, AAA, DAA Mnemonic Meaning Format Operation Flags affected ADD Addition ADD D, S (S) +(D) (D) Carry (CF) OF, SF, ZF, AF, PF, CF ADC Add with carry ADC D, S (S) +(D)+(CF) (D) Carry (CF) OF, SF, ZF, AF, PF, CF INC Increment by 1 INC D (D) +1 (D) OF, SF, ZF, AF, PF AAA ASCII adjust for addition AAA AF, CF OF, SF, ZF, PF undefined DAA Decimal adjust for addition DAA SF, ZF, AF, PF, CF, OF undefined 611 37100 微處理機原理與應用 Lecture 05-24 12

5.2 Arithmetic Instructions Addition Instructions: ADD, ADC, INC, AAA, DAA Destination Accumulator Source Immediate Immediate Immediate Destination Reg16 Reg8 Allowed operands for ADD and ADC instructions Allowed operands for INC instruction 611 37100 微處理機原理與應用 Lecture 05-25 5.2 Arithmetic Instructions Assume that the AX and BX registers contain 1100 16 and 0ABC 16, respectively. What is the result of executing the instruction ADD AX, BX? (BX)+(AX)= 0ABC 16 + 1100 16 =1BBC 16 The sum ends up in destination register AX. That is (AX) = 1BBC 16 611 37100 微處理機原理與應用 Lecture 05-26 13

5.2 Arithmetic Instructions Addition Instructions: ADD, ADC, INC, AAA, DAA ADD AX, BX 0100 IP 1100 CS 1200 DS SS ES Address 11100 11101 11102 Content 03 C3 Instruction ADD AX, BX Next instruction 1100 AX 0ABC BX CX DX 12000 12001 SP BP SI DI 8088/8086 MPU Before execution 611 37100 微處理機原理與應用 Lecture 05-27 5.2 Arithmetic Instructions Addition Instructions: ADD, ADC, INC, AAA, DAA ADD AX, BX 0102 IP 1100 CS 1200 DS SS ES 1BBC AX 0ABC BX CX DX SP BP SI DI 8088/8086 MPU After execution 611 37100 微處理機原理與應用 Lecture 05-28 Address 11100 11101 11102 12000 12001 Content 03 C3 Instruction ADD AX, BX Next instruction 14

5.2 Arithmetic Instructions Verify the previous example using DEBUG program. 611 37100 微處理機原理與應用 Lecture 05-29 5.2 Arithmetic Instructions The original contents of AX, BL, word-size memory location SUM, and carry flag (CF) are 1234 16, AB 16, 00CD 16, and 0 16, respectively. Describe the results of executing the following sequence of instruction? ADD AX, [SUM] ADC BL, 05H INC WORD PTR [SUM] (AX) (AX)+(SUM) = 1234 16 + 00CD 16 =1301 16 (BL) (BL)+imm8+(CF) = AB 16 + 5 16 +0 16 = B0 16 (SUM) (SUM)+ 1 16 = 00CD 16 + 1 16 = 00CE 16 611 37100 微處理機原理與應用 Lecture 05-30 15

5.2 Arithmetic Instructions What is the result of executing the following instruction sequence? ADD AL, BL AAA Assuming that AL contains 32 16 (ASCII code for 2) and BL contains 34 16 (ASCII code 4), and that AH has been cleared. (AL) (AL)+(BL)= 32 16 + 34 16 =66 16 The result after the AAA instruction is (AL) = 06 16 (AH) = 00 16 with both AF and CF remain cleared 611 37100 微處理機原理與應用 Lecture 05-31 5.2 Arithmetic Instructions Perform a 32-bit binary add operation on the contents of the processor s register. (DX,CX) (DX,CX)+(BX,AX) (DX,CX) = FEDCBA98 16 (BX,AX) = 01234567 16 MOV DX, 0FEDCH MOV CX, 0BA98H MOV BX, 01234H MOV AX, 04567H ADD CX, AX ADC DX, BX 611 37100 微處理機原理與應用 Lecture 05-32 ; Add with carry 16

5.2 Arithmetic Instructions Subtraction Instructions: SUB, SBB, DEC, AAS, DAS, and NEG Mnemonic Meaning Format Operation Flags affected SUB Subtract SUB D, S (D)-(S) (D) Borrow (CF) OF, SF, ZF, AF, PF, CF SBB Subtract with borrow SBB D, S (D)-(S)-(CF) (D) OF, SF, ZF, AF, PF, CF DEC Decrement by 1 DEC D (D)-1 (D) OF, SF, ZF, AF, PF NEG Negate NEG D 0-(D) (D) 1 (CF) OF, SF, ZF, AF, PF,CF DAS Decimal adjust for subtraction DAS SF, ZF, AF, PF, CF, OF undefined AAS ASCII adjust for subtraction AAS AF,CF OF,SF, ZF,PF undefined 611 37100 微處理機原理與應用 Lecture 05-33 5.2 Arithmetic Instructions Subtraction Instructions: SUB, SBB, DEC, AAS, DAS, and NEG Destination Source Accumulator Immediate Immediate Immediate Destination Reg16 Reg8 Destination Allowed operands for SUB and SBB instructions Allowed operands for DEC instruction Allowed operands for NEG instruction 611 37100 微處理機原理與應用 Lecture 05-34 17

5.2 Arithmetic Instructions Assuming that the contents of register BX and CX are 1234 16 and 0123 16, respectively, and the carry flag is 0, what is the result of executing the instruction SBB BX, CX? (BX)-(CX)-(CF) (BX) We get (BX) = 1234 16 0123 16 0 16 = 1111 16 the carry flag remains cleared. 611 37100 微處理機原理與應用 Lecture 05-35 5.2 Arithmetic Instructions Verify the previous example using DEBUG program. 611 37100 微處理機原理與應用 Lecture 05-36 18

5.2 Arithmetic Instructions Assuming that the register BX contains 003A 16, what is the result of executing the following instruction? NEG BX (BX) = 0000 16 -(BX)=0000 16 +2 complement of 003A 16 = 0000 16 +FFC6 16 = FFC6 16 Since no carry is generated in this add operation, the carry flag is complemented to give (CF) = 1 611 37100 微處理機原理與應用 Lecture 05-37 5.2 Arithmetic Instructions Verify the previous example using DEBUG program. 611 37100 微處理機原理與應用 Lecture 05-38 19

5.2 Arithmetic Instructions Perform a 32-bit binary subtraction for variable X and Y. MOV SI, 200H MOV DI, 100H MOV AX, [SI] SUB AX, [DI] MOV [SI],AX MOV AX, [SI]+2 SBB AX, [DI]+2 MOV [SI]+2, AX ; Initialize pointer for X ; Initialize pointer for Y ; Subtract LS words ; Save the LS word of result ; Subtract MS words ; Save the MS word of result 611 37100 微處理機原理與應用 Lecture 05-39 5.2 Arithmetic Instructions Multiplication Instructions: MUL, DIV, IMUL, IDIV, AAM, AAD, CBW, and CWD Mnemonic MUL DIV IMUL IDIV Meaning Multiply (unsigned) Division (unsigned) Integer multiply (signed) Integer divide (signed) Format MUL S DIV S IMUL S IDIV S Operation (AL) (S8) (AX) (AX) (S16) (DX)(AX) (1)Q((AX)/(S8)) (AL) R((AX)/(S8)) (AH) (2)Q((DX,AX)/(S16)) (AX) R((DX,AX)/(S16)) (DX) If Q is FF 16 in case (1) or FFFF 16 in case (2), then type 0 interrupt occurs (AL) (S8) (AX) (AX) (S16) (DX)(AX) (1)Q((AX)/(S8)) (AL) R((AX)/(S8)) (AH) (2)Q((DX,AX)/(S16)) (AX) R((DX,AX)/(S16)) (DX) If Q is positive and exceeds 7FFF 16 or if Q is negative and become less than 8001 16, then type 0 interrupt occurs Flags affected OF, CF SF,ZF, AF, PF undefined OF, SF, ZF, AF, PF, CF undefined OF, CF SF,ZF, AF, PF undefined OF, SF, ZF, AF, PF, CF undefined 611 37100 微處理機原理與應用 Lecture 05-40 20

5.2 Arithmetic Instructions Multiplication Instructions: MUL, DIV, IMUL, IDIV, AAM, AAD, CBW, and CWD Mnemonic AAM AAD CBW CWD Meaning Adjust AL for multiplication Adjust AX for division Convert byte to word Convert word to double word Format Operation AAM Q((AL)/10) (AH) R((AL)/10) (AL) AAD (AH) 10+(AL) (AL) 00 (AH) CBW (MSB of AL) (All bits of AH) CWD (MSB of AX) (All bits of DX) Flags affected SF,ZF,PF OF,AF,CF undefined SF,ZF,PF OF,AF,CF undefined None None Destination Reg8 Reg16 Mem8 Mem16 Allowed operands 611 37100 微處理機原理與應用 Lecture 05-41 5.2 Arithmetic Instructions The 2 s-complement signed data contents of AL are 1 and that of CL are 2. What result is produced in AX by executing the following instruction? MUL CL and IMUL CL (AL) = -1 (as 2 s complement) = 11111111 2 = FF 16 (CL) = -2 (as 2 s complement) = 11111110 2 = FE 16 Executing the MUL instruction gives (AX) = 11111111 2 x11111110 2 =1111110100000010 2 =FD02 16 Executing the IMUL instruction gives (AX) = -1 16 x -2 16 = 2 16 = 0002 16 611 37100 微處理機原理與應用 Lecture 05-42 21

5.2 Arithmetic Instructions Verify the previous example using DEBUG program. 611 37100 微處理機原理與應用 Lecture 05-43 5.2 Arithmetic Instructions What is the result of executing the following instructions? MOV AL, 0A1H CBW CWD (AL) = A1 16 = 10100001 2 Executing the CBW instruction extends the MSB of AL (AH) = 11111111 2 = FF 16 or (AX) = 1111111110100001 2 Executing the CWD instruction, we get (DX) = 1111111111111111 2 = FFFF 16 That is, (AX) = FFA1 16 (DX) = FFFF 16 611 37100 微處理機原理與應用 Lecture 05-44 22

5.3 Logic Instructions The logic instructions include AND OR XOR (Exclusive-OR) NOT Mnemonic Meaning Format Operation Flags affected AND Logical AND AND D, S (S) (D) (D) OF, SF, ZF, PF, CF AF undefined OR Logical Inclusive-OR OR D, S (S) (D) (D) OF, SF, ZF, PF, CF AF undefined XOR Logical exclusive-or XOR D, S (S) (D) (D) OF, SF, ZF, PF, CF AF undefined NOT Logical NOT NOT D (NOT D) (D) None 611 37100 微處理機原理與應用 Lecture 05-45 5.3 Logic Instructions Logic instructions : AND, OR, XOR, NOT Destination Accumulator Source Immediate Immediate Immediate Destination Allowed operands for AND, OR, and XOR instructions Allowed operands for NOT instruction 611 37100 微處理機原理與應用 Lecture 05-46 23

5.3 Logic Instructions Describe the results of executing the following instructions? MOV AL, 01010101B AND AL, 00011111B OR AL, 11000000B XOR AL, 00001111B NOT AL (AL)=01010101 2 00011111 2 = 00010101 2 =15 16 Executing the OR instruction, we get (AL)= 00010101 2 +11000000 2 = 11010101 2 =D5 16 Executing the XOR instruction, we get (AL)= 11010101 2 00001111 2 = 11011010 2 =DA 16 Executing the NOT instruction, we get (AL)= (NOT)11011010 2 = 00100101 2 =25 16 611 37100 微處理機原理與應用 Lecture 05-47 5.3 Logic Instructions Masking and setting bits in a register. Mask off the upper 12 bits of the word of data in AX AND AX, 000F 16 Setting B 4 of the byte at the offset address CONTROL_FLAGS MOV AL, [CONTROL_FLAGS] OR AL, 10H MOV [CONTROL_FLAGS], AL Executing the above instructions, we get (AL)= 2 +00010000 2 = X1 2 611 37100 微處理機原理與應用 Lecture 05-48 24

5.4 Shift Instructions Shift instructions: SHL, SHR, SAL, SAR Mnemonic SAL/SHL SHR SAR Meaning Shift arithmetic left / Shift logical left Shift logical right Shift arithmetic right Format SAL D, Count SHL D, Count SHR D, Count SAR D, Count Operation Shift the (D) left by the number of bit positions equal to Count and fill the vacated bits positions on the right with zeros Shift the (D) right by the number of bit positions equal to Count and fill the vacated bits positions on the left with zeros Shift the (D) right by the number of bit positions equal to Count and fill the vacated bits positions on the left with the original most significant bits Flags affected CF, PF, SF, Z AF undefined OF undefined if count 1 CF, PF, SF, Z AF undefined OF undefined if count 1 CF, PF, SF, Z AF undefined OF undefined if count 1 611 37100 微處理機原理與應用 Lecture 05-49 5.4 Shift Instructions Shift instructions: SHL, SHR, SAL, SAR Destination Count 1 CL 1 CL Allowed operands for shift instructions 611 37100 微處理機原理與應用 Lecture 05-50 25

5.4 Shift Instructions Shift instructions: SHL, SHR, SAL, SAR SHL AX, 1 SHR AX, CL SAR AX, CL 611 37100 微處理機原理與應用 Lecture 05-51 5.4 Shift Instructions Assume that CL contains 02 16 and AX contains 091A 16. Determine the new contents of AX and the carry flag after the instruction SAR AX, CL is executed. (AX)=0000001001000110 2 =0246 16 and the carry flag is (CF)=1 2 611 37100 微處理機原理與應用 Lecture 05-52 26

5.4 Shift Instructions Verify the previous example using DEBUG program. 611 37100 微處理機原理與應用 Lecture 05-53 5.4 Shift Instructions Isolate the bit B 3 of the byte at the offset address CONTROL_FLAGS. MOV AL, [CONTROL_FLAGS] MOV CL, 04H SHR AL, CL Executing the instructions, we get (AL)=0000B 7 B 6 B 5 B 4 and (CF)=B 3 611 37100 微處理機原理與應用 Lecture 05-54 27

5.5 Rotate Instructions Rotate instructions: ROL, ROR, RCL, RCR Mnemonic ROL ROR RCL Meaning Rotate left Rotate right Rotate left through carry Format ROL D, Count ROR D, Count RCL D, Count Operation Rotate the (D) left by the number of bit positions equal to Count. Each bit shifted out from the leftmost bit goes back into the rightmost bit position. Rotate the (D) right by the number of bit positions equal to Count. Each bit shifted out from the rightmost bit goes back into the leftmost bit position. Same as ROL except carry is attached to (D) for rotation. Flags affected CF OF undefined if count 1 CF OF undefined if count 1 CF OF undefined if count 1 RCR Rotate right through carry RCR D, Count Same as ROR except carry is attached to (D) for rotation. CF OF undefined if count 1 611 37100 微處理機原理與應用 Lecture 05-55 5.5 Rotate Instructions Rotate instructions: ROL, ROR, RCL, RCR Destination Count 1 CL 1 CL Allowed operands for rotate instructions 611 37100 微處理機原理與應用 Lecture 05-56 28

5.5 Rotate Instructions Rotate instructions: ROL, ROR, RCL, RCR ROL AX, 1 ROR AX, CL (CL)=4 611 37100 微處理機原理與應用 Lecture 05-57 5.5 Rotate Instructions Rotate instructions: ROL, ROR, RCL, RCR For RCL, RCR, the bits are rotate through the carry flag 611 37100 微處理機原理與應用 Lecture 05-58 29

5.5 Rotate Instructions What is the result in BX and CF after execution of the following instructions? RCR BX, CL Assume that, prior to execution of the instruction, (CL)=04 16, (BX)=1234 16, and (CF)=0 The original contents of BX are (BX) = 0001001000110100 2 = 1234 16 Execution of the RCR command causes a 4-bit rotate right through carry to take place on the data in BX, the results are (BX) = 1000000100100011 2 = 8123 16 (CF) = 0 2 611 37100 微處理機原理與應用 Lecture 05-59 5.5 Rotate Instructions Verify the previous example using DEBUG program. 611 37100 微處理機原理與應用 Lecture 05-60 30

5.5 Rotate Instructions Disassembly and addition of 2 hexadecimal digits stored as a byte in memory. MOV AL, [HEX_DIGITS] MOV BL, AL MOV CL, 04H ROR BL, CL AND AL, 0FH AND BL, 0FH ADD AL, BL 611 37100 微處理機原理與應用 Lecture 05-61 31