Microsoft PowerPoint - C15_LECTURE_NOTE_06

Similar documents
Microsoft PowerPoint - C15_LECTURE_NOTE_06

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

untitled

Microsoft PowerPoint - C15_LECTURE_NOTE_05.ppt

Microsoft PowerPoint - C15_LECTURE_NOTE_04.ppt

Microsoft PowerPoint - C15_LECTURE_NOTE_05.ppt

Microsoft PowerPoint - C15_LECTURE_NOTE_04.ppt

幻灯片 1

<4D F736F F D20C7B6C8EBCABDCFB5CDB3C9E8BCC6CAA6B0B8C0FDB5BCD1A75FD1F9D5C22E646F63>

Microsoft PowerPoint - C15_LECTURE_NOTE_11


学习MSP430单片机推荐参考书

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

Microsoft PowerPoint - os_4.ppt

幻灯片 1

2/80 2

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

1 CPU

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

目 录

Microsoft PowerPoint - CA_02 Chapter5 Part-I_Single _V2.ppt

Microsoft PowerPoint - CH 04 Techniques of Circuit Analysis

1 TPIS TPIS 2 2

Microsoft PowerPoint - Lecture7II.ppt

Microsoft PowerPoint - STU_EC_Ch08.ppt

Bus Hound 5

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

Panaboard Overlayer help

穨control.PDF

AL-M200 Series

untitled

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

K7VT2_QIG_v3

lan03_yen

三維空間之機械手臂虛擬實境模擬

微型计算机原理及应用试题 机电96


PowerPoint Presentation

Gerolor Motors Series Dimensions A,B C T L L G1/2 M8 G1/ A 4 C H4 E

入學考試網上報名指南

Microsoft Word - template.doc

<4D F736F F F696E74202D20B5DAD2BBD5C228B4F2D3A1B0E6292E BBCE6C8DDC4A3CABD5D>

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

1.ai

AN INTRODUCTION TO PHYSICAL COMPUTING USING ARDUINO, GRASSHOPPER, AND FIREFLY (CHINESE EDITION ) INTERACTIVE PROTOTYPING

untitled

國 立 政 治 大 學 教 育 學 系 2016 新 生 入 學 手 冊 目 錄 表 11 國 立 政 治 大 學 教 育 學 系 博 士 班 資 格 考 試 抵 免 申 請 表 論 文 題 目 申 報 暨 指 導 教 授 表 12 國 立 政 治 大 學 碩 博 士 班 論

06721 main() lock pick proc() restart() [2][4] MINIX minix2.0 GDT, IDT irq table[] CPU CPU CPU CPU (IDTR) idt[] CPU _hwint00:! Interrupt

3.1 num = 3 ch = 'C' 2

RS-232C [11-13] 1 1 (PLC) (HMI) Visual Basic (PLC) 402

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

Microsoft PowerPoint - C15_LECTURE_NOTE_15

中国人民大学商学院本科学年论文

<4D F736F F D C4EAC0EDB9A4C0E04142BCB6D4C4B6C1C5D0B6CFC0FDCCE2BEABD1A15F325F2E646F63>

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

. 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

WinMDI 28

IP505SM_manual_cn.doc

12232A LED LED LED EL EL CCFL EL CCF

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

Gerotor Motors Series Dimensions A,B C T L L G1/2 M G1/ A 4 C H4 E

Microsoft PowerPoint - notes3-Simple-filled12

東吳大學

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

C/C++ 语言 - 循环

A Preliminary Implementation of Linux Kernel Virus and Process Hiding


C++ 程式設計

ENGG1410-F Tutorial 6

TX-NR3030_BAS_Cs_ indd

Chn 116 Neh.d.01.nis

4. 每 组 学 生 将 写 有 习 语 和 含 义 的 两 组 卡 片 分 别 洗 牌, 将 顺 序 打 乱, 然 后 将 两 组 卡 片 反 面 朝 上 置 于 课 桌 上 5. 学 生 依 次 从 两 组 卡 片 中 各 抽 取 一 张, 展 示 给 小 组 成 员, 并 大 声 朗 读 卡

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

<4D F736F F D203033BDD7A16DA576B04FA145A4ADABD2A5BBACF6A16EADBAB6C0ABD2A4A7B74EB8712E646F63>

2015 Chinese FL Written examination

ebook121-20

綜合社會保障援助指引

ansoft_setup21.doc

iml v C / 0W EVM - pplication Notes. IC Description The iml8683 is a Three Terminal Current Controller (TTCC) for regulating the current flowin

iml v C / 4W Down-Light EVM - pplication Notes. IC Description The iml8683 is a Three Terminal Current Controller (TTCC) for regulating the cur

Microsoft Word doc

Cadence SPB 15.2 VOICE Cadence SPB 15.2 PC Cadence 3 (1) CD1 1of 2 (2) CD2 2of 2 (3) CD3 Concept HDL 1of 1

Edge-Triggered Rising Edge-Triggered ( Falling Edge-Triggered ( Unit 11 Latches and Flip-Flops 3 Timing for D Flip-Flop (Falling-Edge Trigger) Unit 11

微處理機期末專題

構 築 4 列 牌 陣 從 剩 餘 的 牌 庫 頂 抽 4 張 牌, 面 朝 上 排 列 在 桌 子 中 央 這 4 張 牌 就 是 牌 陣 的 起 始 牌, 包 括 這 張 起 始 牌 在 內, 每 一 列 最 多 只 能 容 納 5 張 牌 將 剩 餘 的 牌 暫 時 置 於 一 旁, 在 下

2005 5,,,,,,,,,,,,,,,,, , , 2174, 7014 %, % 4, 1961, ,30, 30,, 4,1976,627,,,,, 3 (1993,12 ),, 2

OVLFx3C7_Series_A3_bgry-KB.pub

第1章 簡介

Preface This guide is intended to standardize the use of the WeChat brand and ensure the brand's integrity and consistency. The guide applies to all d

untitled

User ID 150 Password - User ID 150 Password Mon- Cam-- Invalid Terminal Mode No User Terminal Mode No User Mon- Cam-- 2

Guide to Install SATA Hard Disks

Windows XP

HCD0174_2008

VASP应用运行优化

Microsoft Word - HC20138_2010.doc

第5章修改稿

Microsoft PowerPoint - C15_LECTURE_NOTE_09

Transcription:

61 Flag-Control 8088/8086 MICROPROCESSOR PROGRAMMING CONTROL FLOW INSTRUCTIONS AND PROGRAM STRUCTURES LAHF SAHF CLC STC CMC CLI STI Load AH from flags Store AH into flags Clear carry flag Set carry flag Complement carry flag Clear interrupt flag Set interrupt flag (AH) () () (AH) (CF) 0 (CF) 1 (CF) NOT (CF) (IF) 0 (IF) 1 SF,ZF,AF,PF,CF CF CF CF IF IF 7 0 AH SF ZF - AF - PF - CF 611 37100 微處理機原理與應用 Lecture 06-4 SF = Sign flag ZF = Zero flag AF = Auxiliary PF = Parity flag CF = Carry flag - = Undefined (do not use) 8088/8086 MICROPROCESSOR PROGRAMMING CONTROL FLOW INSTRUCTIONS AND PROGRAM STRUCTURES 61 Flag-Control 62 Compare 63 Control Flow and Jump 64 Subroutines and Subroutine-Handling 65 The Loop and the Loop-Handling 66 String and String-Handling 61 Flag-Control Write an sequence to save the current contents of the 8088 s flags in the memory location at offset MEM1 of the current data segment and then reload the flags with the contents of the storage location at offset MEM2 LAHF ; Load AH from flags MOV [MEM1], AH ; Move content of AH to MEM1 MOV AH, [MEM2] ; Load AH from MEM2 SAHF ; Store content of AH into flags 611 37100 微處理機原理與應用 Lecture 06-2 611 37100 微處理機原理與應用 Lecture 06-5 61 Flag-Control 61 Flag-Control The flag-control s, when executed, directly affect the state of the flags These s include: LAHF (Load AH from flags) SAHF (Store AH into flags) CLC (Clear carry) STC (Set carry) CMC (Complement carry) CLI (Clear interrupt) STI (Set interrupt) 611 37100 微處理機原理與應用 Lecture 06-3 611 37100 微處理機原理與應用 Lecture 06-6

61 Flag-Control 61 Flag-Control 611 37100 微處理機原理與應用 Lecture 06-7 611 37100 微處理機原理與應用 Lecture 06-10 61 Flag-Control Of the three carry flag s CLC, STC, and CMC, only one is really independent That is, the operation that it provides cannot be performed by a series of the other two s Determine which one of the carry is the independent CLC STC followed by a CMC STC CLC followed by a CMC Therefore, only CMC is the independent 62 Compare Instruction The Compare Instruction: The compare operation enable us to determine the relationship between two numbers CMP Compare CMP D, S Destination Memory Memory Accumulator (D)-(S) is used in setting or resetting the flags Source Memory Immediate Immediate Immediate CF, AF, OF, PF, SF, ZF 611 37100 微處理機原理與應用 Lecture 06-8 611 37100 微處理機原理與應用 Lecture 06-11 Allowed operands for compare 61 Flag-Control Verify the operation of the following s that affect the carry flag, CLC STC CMC by executing them with the DEBUG program Start with CF flag set to 1 (CY) 62 Compare Instruction Describe what happens to the status flags as the sequence of s that follows is executed MOV AX, 1234H MOV BX, 0ABCDH CMP AX, BX (AX) = 1234 16 = 0001001000110100 2 (BX) = ABCD 16 = 1010101111001101 2 (AX) (BX) = 0001001000110100 2-1010101111001101 2 = 0110011001100111 2 Therefore, ZF = 0, SF = 0, OF = 0, PF = 0 CF = 1, AF = 1 611 37100 微處理機原理與應用 Lecture 06-9 611 37100 微處理機原理與應用 Lecture 06-12

62 Compare Instruction The Compare Instruction: 63 Control Flow and Jump Unconditional and conditional jump Condition met? Yes No AA Part I Jcc AA XXXXXX Part II XXXXXX Part III Conditional jump Next executed If condition not met Locations skipped due to jump Next executed if condition met Conditional jump program sequence 611 37100 微處理機原理與應用 Lecture 06-13 611 37100 微處理機原理與應用 Lecture 06-16 63 Control Flow and Jump Unconditional jump Conditional jump Branching structure IF-THEN Loop program structure REPEAT-UNTIL and WHILE-DO Applications using the loop and branch software structures 611 37100 微處理機原理與應用 Lecture 06-14 63 Control Flow and Jump Unconditional jump JMP Unconditional jump 611 37100 微處理機原理與應用 Lecture 06-17 JMP Operand Jump is initiated to the address specified by the operand Operands Short-label Near-label Far-label Memptr16 Regptr16 Memptr32 Allowed operands for JMP 63 Control Flow and Jump Unconditional and conditional jump Part I JMP AA Unconditional jump 63 Control Flow and Jump Verify the operation of the JMP BX using the DEBUG program Let the contents of BX be 0010 16 Part II Locations skipped due to jump AA XXXXXX Part III Next executed Unconditional jump program sequence 611 37100 微處理機原理與應用 Lecture 06-15 611 37100 微處理機原理與應用 Lecture 06-18

63 Control Flow and Jump Use the DEBUG program to observe the operation of the JMP [BX] 611 37100 微處理機原理與應用 Lecture 06-19 63 Control Flow and Jump Conditional jump JNC JNE JNG JNGE JNL JNLE JNO JNP JNS JNZ JO JP JPE JPO JS JZ Not carry Not equal Not greater Not greater nor equal Not less Not less or nor equal Not overflow Not parity Not sign Not zero Overflow Parity Parity even Parity odd Sign Zero 611 37100 微處理機原理與應用 Lecture 06-22 Condition CF=0 ZF=0 ((SF xor OF) or ZF)=1 (SF xor OF)=1 SF=OF ZF=0 and SF=OF OF=0 PF=0 SF=0 ZF=0 OF=1 PF=1 PF=1 PF=0 SF=1 ZF=1 63 Control Flow and Jump Conditional jump 63 Control Flow and Jump Branch program structure IF-THEN Jcc Conditional jump Jcc Operand If the specified condition cc is true the jump to the address specified by the operand is initiated; otherwise the next is executed CMP AX, BX JE EQUAL --- --- ; Next if (AX) (BX) EQUAL: --- --- ; Next if (AX)=(BX) --- --- IF-THEN branch program structure using a flag-condition test 611 37100 微處理機原理與應用 Lecture 06-20 611 37100 微處理機原理與應用 Lecture 06-23 63 Control Flow and Jump Conditional jump Condition JA Above CF=0 and ZF=0 JAE Above or equal CF=0 JB Below CF=1 JBE Below or equal CF=1 or ZF=1 JC Carry CF=1 JCXZ CX register is zero (CF or ZF)=0 JE Equal ZF=1 JG Greater ZF=0 and SF=OF JGE Greater or equal SF=OF JL Less (SF xor OF)=1 JLE Less or equal ((SF xor OF) or ZF)=1 JNA Not above CF=1 or ZF=1 JNAE Not above nor equal CF=1 JNB Not below CF=0 JNBE Not below nor equal CF=0 and ZF=0 Type of conditional jump s 國立台灣大學生物機電系 611 37100 微處理機原理與應用 Lecture 06-21 林達德 63 Control Flow and Jump Branch program structure IF-THEN AND AL, 04H JNZ BIT2_ONE --- --- ; Next if B2 of AL=0 BIT2_ONE: --- --- ; Next if B2 of AL=1 --- --- IF-THEN branch program structure using register-bit test 611 37100 微處理機原理與應用 Lecture 06-24

63 Control Flow and Jump Branch program structure IF-THEN MOV CL, 03H SHR AL, CL JC BIT2_ONE --- --- ; Next if B2 of AL=0 BIT2_ONE: --- --- ; Next if B2 of AL=1 --- --- 63 Control Flow and Jump Loop program structures WHILE-DO Start Initialize repeat count AGAIN Loop done? NO Loop program statements Decrement repeat count YES IF-THEN branch program structure using an alternative register-bit test Repeat NEXT 611 37100 微處理機原理與應用 Lecture 06-25 611 37100 微處理機原理與應用 Lecture 06-28 WHILE-DO program sequence 63 Control Flow and Jump Loop program structures REPEAT-UNTIL Start REPEAT-UNTIL program sequence 611 37100 微處理機原理與應用 Lecture 06-26 Initialize repeat count AGAIN Loop program statements Decrement repeat count NO Loop done? (cc=false) (cc=true) YES Continue 63 Control Flow and Jump Loop program structures WHILE-DO MOV CL, COUNT ; Set loop repeat count AGAIN: JZ NEXT ; Loop is complete is CL=0 (ZF=1) --- --- ; First of loop --- --- ; Second of loop --- --- ; nth of loop DEC CL ; Decrement repeat count by 1 JMP AGAIN ; Repeat from AGAIN NEXT: --- --- ; First executed after the ; loop is complete Typical WHILE-DO sequence 國立台灣大學生物機電系 611 37100 微處理機原理與應用 Lecture 06-29 林達德 63 Control Flow and Jump Loop program structures REPEAT-UNTIL 63 Control Flow and Jump Example The block-move program Start MOV CL, COUNT ; Set loop repeat count AGAIN: --- --- ; First of loop --- --- ; Second of loop --- --- ; nth of loop DEC CL ; Decrement repeat count by 1 JNZ AGAIN ; Repeat from AGAIN if (CL) 00H and (ZF)=0 --- --- ; First executed after the loop is ;complete, (CL) =00H and (ZF)=1 Typical REPEAT-UNTIL sequence 611 37100 微處理機原理與應用 Lecture 06-27 Establish the data segment, source block and destination block Set up a counter for the points to be removed NXTPT Move the next source point to NO the accumulator Move the accumulator to the next destination point Update counter, source pointer, and destination pointer NO All points Moved? YES Stop 611 37100 微處理機原理與應用 Lecture 06-30 Initialization Data movement Update Test

63 Control Flow and Jump Example The block-move program NXTPT: MOV AX, DATASEGADDR MOV SI, BLK1ADDR MOV DI, BLK2ADDR MOV CX, N MOV AH, [SI] MOV [DI], AH INC SI INC DI DEC CX JNZ NXTPT HLT 64 Subroutines and Subroutine- Handling Main program Call subroutine A Next Call subroutine A Next Subroutine A First Return 611 37100 微處理機原理與應用 Lecture 06-31 611 37100 微處理機原理與應用 Lecture 06-34 Subroutine concept 63 Control Flow and Jump Implement an sequence that calculates the absolute difference between the contents of AX and BX and places it in DX CMP AX, BX JC DIFF2 DIFF1: MOV DX, AX SUB DX, BX ; (DX)=(AX)-(BX) JMP DONE DIFF2: MOV DX, BX SUB DX, AX ; (DX)=(BX)-(AX) DONE: NOP 611 37100 微處理機原理與應用 Lecture 06-32 64 Subroutines and Subroutine- Handling The CALL CALL Subroutine call CALL Operand Operands Near-proc Far-proc Memptr16 Regptr16 Memptr32 Allowed operands for CALL 611 37100 微處理機原理與應用 Lecture 06-35 Execution continues from the address of the subroutine specified by the operand Information required to return back to the main program such as IP and CS are saved on the stack 64 Subroutines and Subroutine- Handling A subroutine is a special program that can be called for execution from any point in a program A subroutine is also known as a procedure A return must be included at the end of the subroutine to initiate the return sequence to the main program environment CALL and RET s PUSH and POP s 64 Subroutines and Subroutine- Handling The RET RET Return RET or RET Operand Operands Disp16 Allowed operands for RET Return to the main program by restoring IP (and CS for farproc) If Operand is present, it is added to the contents of SP 611 37100 微處理機原理與應用 Lecture 06-33 611 37100 微處理機原理與應用 Lecture 06-36

64 Subroutines and Subroutine- Handling TITLE 610 PAGE,132 STACK_SEG SEGMENT STACK 'STACK' DB 64 DUP(?) STACK_SEG ENDS CODE_SEG SEGMENT 'CODE' EX610 PROC FAR ASSUME CS:CODE_SEG, SS:STACK_SEG ;To return to DEBUG program put return address on the stack PUSH DS MOV AX, 0 PUSH AX ;Following code implements Example 610 CALL SUM RET SUM PROC NEAR MOV DX, AX ADD DX, BX ; (DX)=(AX)+(BX) RET SUM ENDP EX610 ENDP CODE_SEG ENDS END EX610 64 Subroutines and Subroutine- Handling 611 37100 微處理機原理與應用 Lecture 06-37 611 37100 微處理機原理與應用 Lecture 06-40 64 Subroutines and Subroutine- Handling 64 Subroutines and Subroutine- Handling The PUSH and POP s To save registers and parameters on the stack Main body of the subroutine PUSH XX PUSH YY PUSH ZZ To restore registers and Parameters from the stack POP ZZ POP YY POP XX Return to main program RET 611 37100 微處理機原理與應用 Lecture 06-38 611 37100 微處理機原理與應用 Lecture 06-41 Structure of a subroutine 64 Subroutines and Subroutine- Handling 64 Subroutines and Subroutine- Handling The PUSH and POP s PUSH Push word onto stack PUSH S ((SP)) (S) (SP) (SP)-2 POP Pop word off stack POP D (D) ((SP)) (SP) (SP)+2 Operands (S or D) Seg-reg (CS illegal) Memory 611 37100 微處理機原理與應用 Lecture 06-39 Allowed operands for PUSH and POP 611 37100 微處理機原理與應用 Lecture 06-42

64 Subroutines and Subroutine- Handling Write a procedure named SQUARE that squares the contents of BL and places the result in BX ;Subroutine: SQUARE ;Description: (BX)=square of (BL) SQUARE PROC NEAR PUSH AX ; Save the register to be used MOV AX, BX ; Place the number in AL IMUL BL ; Multiply with itself MOV BX, AX ; Save the result POP AX ; Restore the register used RET SQUARE ENDP 611 37100 微處理機原理與應用 Lecture 06-43 65 The Loop and the Loop-Handling The LOOP s MOV CX, COUNT ; Load count for the number of repeats NEXT: ; Body of routine that is repeated LOOP NEXT ; Loop back to label NEXT if count not zero 611 37100 微處理機原理與應用 Lecture 06-46 Typical loop routine structure 64 Subroutines and Subroutine- Handling The PUSHF and POPF s 65 The Loop and the Loop-Handling Example The block-move program PUSHF POPF Push flag onto stack Pop word off stack ((SP)) () (SP) (SP)-2 () ((SP)) (SP) (SP)+2 OF,DF,IF,TF,SF,ZF, AF,PF,CF NXTPT: MOV AX, DATASEGADDR MOV SI, BLK1ADDR MOV DI, BLK2ADDR MOV CX, N MOV AH, [SI] MOV [DI], AH INC SI INC DI LOOP NXTPT HLT 611 37100 微處理機原理與應用 Lecture 06-44 611 37100 微處理機原理與應用 Lecture 06-47 65 The Loop and the Loop-Handling The LOOP s LOOP LOOPE LOOPZ LOOPNE LOOPNZ Loop Loop while equal Loop while zero Loop while not equal Loop while not zero LOOP Short-label LOOPE/LOOPZ Short-label LOOPNE/LOOPNZ Short-label (CX) (CX)-1 Jump is initiated to location defined by shortlabel if (CX) 0; otherwise, execute next sequential (CX) (CX)-1 Jump to location defined by short-label if (CX) 0 and (ZF)=1; otherwise, execute next sequential (CX) (CX)-1 Jump to location defined by short-label if (CX) 0 and (ZF)=0; otherwise, execute next sequential 65 The Loop and the Loop-Handling Given the following sequence of s, explain what happens as they are executed MOV DL, 05 MOV AX, 0A00H MOV SI, 0 MOV CX, 0FH AGAIN: INC SI CMP [SI], DL LOOPNE AGAIN 611 37100 微處理機原理與應用 Lecture 06-45 611 37100 微處理機原理與應用 Lecture 06-48

65 The Loop and the Loop-Handling 66 String and String-Handling Move string MOVSB, MOVSW Example The block-move program using the move-string NXTPT: MOV AX, DATASEGADDR MOV ES, AX MOV SI, BLK1ADDR MOV DI, BLK2ADDR MOV CX, N MOVSB LOOP NXTPT HLT 611 37100 微處理機原理與應用 Lecture 06-49 611 37100 微處理機原理與應用 Lecture 06-52 65 The Loop and the Loop-Handling 66 String and String-Handling Compare string and scan string CMPSB/CMPSW, SCASB/SCASW Example Block scan operation using the SCASB AGAIN: NEXT: MOV AX, DATASEGADDR MOV ES, AX MOV AL, 05 MOV DI, 0A000H MOV CX, 0FH SCASB LOOPNE AGAIN 611 37100 微處理機原理與應用 Lecture 06-50 611 37100 微處理機原理與應用 Lecture 06-53 66 String and String-Handling The basic string s MOVS CMPS SCAS LODS STOS Move string Compare string Scan string Load string Store string MOVSB MOVSW CMPSB CMPSW SCASB SCASW LODSB LODSW STOSB STOSW ((ES)0+(DI)) ((DS)0+(SI)) (SI) (SI)±1 or 2 (DI) (DI)±1 or 2 Set flags as per ((DS)0+(SI))-((ES)0+(DI)) (SI) (SI)±1 or 2 (DI) (DI)±1 or 2 Set flags as per (AL or AX)-((ES)0+(DI)) (DI) (DI)±1 or 2 (AL or AX)-((DS)0+(SI)) (SI) (SI)±1 or 2 ((ES)0+(DI)) (AL or AX) ±1 or 2 (DI) (DI)±1 or 2 CF,PF,AF, ZF,SF,OF CF,PF,AF, ZF,SF,OF 66 String and String-Handling Load and store string LODSB/LODSW, STOSB/STOSW Example Initializing a block of memory with a store string AGAIN: MOV AX, 0 MOV ES, AX MOV AL, 05 MOV DI, 0A000H MOV CX, 0FH STOSB LOOP AGAIN 611 37100 微處理機原理與應用 Lecture 06-51 611 37100 微處理機原理與應用 Lecture 06-54

66 String and String-Handling REP string REP (repeat prefixes) Prefix REP REPE/REPZ REPNE/REPNZ Used with: MOVS STOS CMPS SCAS CMPS SCAS Repeat while not end of string CX 0 Repeat while not end of string and strings are equal CX 0 and ZF=1 Repeat while not end of string and strings are not equal CX 0 and ZF=0 66 String and String-Handling Describe what happen as the following sequence of is executed MOV AX, DATA_SEGMENT MOV AX, EXTRA_SEGMENT MOV ES, AX MOV CX, 20H MOV SI, OFFSET MASTER MOV DI, OFFSET COPY REPZMOVSB 611 37100 微處理機原理與應用 Lecture 06-55 611 37100 微處理機原理與應用 Lecture 06-58 66 String and String-Handling REP string REP (repeat prefixes) 66 String and String-Handling Example Initializing a block of memory by repeating the STOSB MOV AX, 0 MOV ES, AX MOV AL, 05 MOV DI, 0A000H MOV CX, 0FH REPSTOSB 611 37100 微處理機原理與應用 Lecture 06-56 611 37100 微處理機原理與應用 Lecture 06-59 66 String and String-Handling Autoindexing for string and STD s 66 String and String-Handling STD Clear DF Set DF STD (DF) 0 (DF) 1 DF DF 611 37100 微處理機原理與應用 Lecture 06-57 611 37100 微處理機原理與應用 Lecture 06-60