Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 1 Chapter Four.

Slides:



Advertisements
Similar presentations
Princess Sumaya Univ. Computer Engineering Dept. Chapter 9:
Advertisements

Registers of the 8086/ /2002 JNM.
There are two types of addressing schemes:
指令与寻址方式. 一、 instruction Sentence ( 指令语句 ) 按指令的用途划分有: 1. Data Transfer ( 数据传送 ) —— MOV 、 PUSH 、 POP … 2. Arithmetic Operations ( 算术运算 ) —— ADD 、 SUB 、
Gursharan Singh Tatla 21-Nov-20101www.eazynotes.com.
8086 : INSTRUCTION SET By, Pramod Sunagar Assistant Professor
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Introduction to Computer Engineering by Richard E. Haskell Register Indirect Addressing Module M18.2 Section 12.3.
8-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
Assembly Language for Intel-Based Computers
Flow Control Instructions
Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction Flag – LODS Instructions – STOS Instructions – MOVS Instructions.
Microprocessor Programming II
3.7 String Instructions Specifying the Operands’ Size and Address and the String Direction STRING = a data collection in memory. String ELEMENTS can be:
11.1/36 Repeat: From Bits and Pieces Till Strings.
Low Level Programming Lecturer: Duncan Smeed Low Level Program Control Structures.
Chapter 4 - Implementing Standard Program Structures in 8086 Assembly Language from Microprocessors and Interfacing by Douglas Hall.
Chapter four – The 80x86 Instruction Set Principles of Microcomputers 2015年10月19日 2015年10月19日 2015年10月19日 2015年10月19日 2015年10月19日 2015年10月19日 1 Chapter.
Chapter Two– Data Numbering & Character Encoding System in Microcomputer Principles of Microcomputers 2015年10月22日 2015年10月22日 2015年10月22日 2015年10月22日 2015年10月22日.
Dr. José M. Reyes Álamo 1.  Review: ◦ Statement Labels ◦ Unconditional Jumps ◦ Conditional Jumps.
CE302 MICROPROCESSORS Levent EREN Izmir University of Economics.
String-Introduction String is a series of bytes or a series of words in sequential memory locations. Index registers - SI (Data segment) - DI (Extra segment)
Dr. José M. Reyes Álamo 1.  Review: ◦ of Comparisons ◦ of Set on Condition  Statement Labels  Unconditional Jumps  Conditional Jumps.
Strings, Procedures and Macros
ICS312 Lecture13 String Instructions.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
Processing String Data and Binary Data (continue)
Click to add Title Comunicación y Gerencia Click To add Subtitle Click to add Text Fundamentals of Assembly Language.
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
String Instructions String instructions were designed to operate on large data structures. The SI and DI registers are used as pointers to the data structures.
String Processing Chapter 10 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Chapter Four–80x86 Instruction Set Principles of Microcomputers 2016年1月12日 2016年1月12日 2016年1月12日 2016年1月12日 2016年1月12日 2016年1月12日 1 Chapter four 80x86.
Microprocessor Programming II To discuss more complicated programming techniques Flag control instructions Compare and jump Subroutines Loop and string.
Khaled A. Al-Utaibi  I/O Ports  I/O Space VS Memory Space  80x86 I/O Instructions − Direct I/O Instructions − Indirect I/O Instructions.
LEA instruction The LEA instruction can be used to get the offset address of a variable Example ORG 100h MOV AL, VAR1 ; check value of VAR1 by moving it.
Review of Assembly language. Recalling main concepts.
Assembling and Linking An assembly language program is turned into an executable file in two steps Assembling turns the source code into object code (.obj.
String Instructions String instructions were designed to operate on large data structures. The SI and DI registers are used as pointers to the data structures.
2/20/2016CAP 2211 Flow Control Instructions. 2/20/2016CAP 2212 Transfer of Control Flow control instructions are used to control the flow of a program.
Arrays. Outline 1.(Introduction) Arrays An array is a contiguous block of list of data in memory. Each element of the list must be the same type and use.
Khaled A. Al-Utaibi  Introduction  The MOV Instruction  The LEA Instruction  The Stack Instructions  The String Data Transfer.
Jumps, Loops and Branching. Unconditional Jumps Transfer the control flow of the program to a specified instruction, other than the next instruction in.
Internal Programming Architecture or Model
Lecture 11 Text mode video
Lecture 6 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
Chapter 8 String Operations. 8.1 Using String Instructions.
Format of Assembly language
Chapter Nov-2010
Data Transfers, Addressing, and Arithmetic
Assembly 07 String Processing.
BYTE AND STRING MANIPULATON
Today we are going to discuss about,
Chapter 9.
Chapter six of V4: The String Instructions
Microprocessor and Assembly Language
Chapter 4 Data Movement Instructions
EE3541 Introduction to Microprocessors
Morgan Kaufmann Publishers Computer Organization and Assembly Language
INSTRUCTION SET.
INSTRUCTION SET.
Assembly Language Programming Part 2
Microcomputer Programming
Chapter 4 Data Movement Instructions
Lecture 1 Instruction set of 8086 Лектор: Люличева И.А. 1.
Assembly Language for Intel-Based Computers, 5th Edition
Flow Control Instructions
T opic: S TRING I NSTRUCTION P RESENTED B Y: N OOR FATIMA M AHA AKRAM ASIF.
Chapter 5 Arithmetic and Logic Instructions
Data Movement Instructions
CNET 315 Microprocessor & Assembly Language
Presentation transcript:

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 1 Chapter Four 80x86 Instruction Set ( 6 )

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2 String Instructions The 80x86 supports twelve string instructions: movs (move string) lods (load string element into the accumulator) stos (store accumulator into string element) scas (Scan string and check for match against the value in the accumulator) cmps (compare two strings) ins (input a string from an I/O port) outs (output a string to an I/O port rep (repeat a string operation) repz (repeat while zero) repe (repeat while equal) repnz (repeat while not zero) repne (repeat while not equal)

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 3 String Instructions These instructions can operate on strings of bytes, words, or double words. To specify the object size, simply append a b, w, or d to the end of the instruction’s mnemonic, i.e., lodsb, movsw, cmpsd, etc. Of course, the double word forms are only available on and later processors.

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 4 String Instructions movscmpsThe movs and cmps instructions assume that ds:si contains the segmented address of a source string and that es:di contains the segmented address of a destination string. lodsThe lods instruction assumes that ds:si points at a source string, the accumulator (al/ax/eax) is the destination location. scasstosThe scas and stos instructions assume that es:di points at a destination string and the accumulator contains the source value.

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 5 String Instruction Basics Source DS:SI, Destination ES:DI –You must ensure DS and ES are correct –You must ensure SI and DI are offsets into DS and ES respectively Direction Flag (0 = Up, 1 = Down) –CLD - Increment addresses (left to right) –STD - Decrement addresses (right to left)

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 6 Moving (Copying) MOVSB, MOVSW –Memory to memory copy of a byte or word –Each execution of this instruction causes Copy byte/word at DS:SI to ES:DI Inc/Dec SI and DI by 1 or 2 –If CX contains a repetition factor REP MOVSB or REP MOVSW will automatically execute the move [CX] times, and CX becomes 0

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 7 Example: Copy a String ;Copy array a to b, assume ES=DS, and 10 bytes are to be copied mov cx, 10 ;10 bytes to copy mov di, offset b;destination mov si, offset a;source cld;left to right rep movsb

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 8 Example: Memory Shift ;shift bytes of a 3 bytes to right movcx, 7 ;bytes to copy mov di, offset a+9;dest mov si, offset a+9-3 ;source std;copy from right to left rep movsb DI a SI

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 9 Example: Replication db(100-4) dup (?);space movcx,100-4;96 bytes to copy movsi, offset pattern movdi, offset pattern+4 cld;destructive overlap repmovsb DI a SI

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 10 Store String STOSB, STOSW Copy AL or AX into an array of bytes or words –destination ES:DI Each repetition Increments or Decrements DI –depends on DF Commonly used with REP prefix and number of repetitions in CX The Word version byte reverses AX as usual

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 11 Example: Initilializing Storage arrdw200 dup (?);empty words ;to be initialized to A050A movax,50A0h movdi,offset arr movcx,200;array size cld stosw A050A050 arr 50A0 AX DI

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 12 Load String LODSB, LODSW –Byte or word at DS:SI is copied into AL or AX –SI is increased or decreased by 1 or 2 This is commonly paired with STOSx in a loop to process each component of an array There is no reason to use REP with this instruction

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 13 Example: Process Array ;array b = toUpper(array a) movdi, offset b;dest movsi, offset a;source movcx,30;array size cld;left to right processing lp: lodsb;get next byte andal,0DFh;to upper case stosb;store at next location looplp

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 14 Scan String SCASB, SCASW Compares AL or AX with ES:DI and auto increments or decrements DI This instruction sets the flags register –Flags set according to result of compare –Used in a loop, or with conditional REPs REPZ, REPE, REPNZ, REPNE

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 15 Conditional Repeats for SCASx and CMPSx while (CX != 0 ) { do string primitive --CX if (REPNE and ZF == 1) exit loop if (REPE and ZF == 0) exit loop } The test for CX is at the top of the loop Test of zero flag is at the end of the loop. Only CMPS and SCAS instructions can affect the ZF value

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 16 Example: String Search arrdb 'abcdefghijklmnopqrstuvwxyz' movdi, offset arr movcx,26; 26 bytes cld;left to right processing moval,target;ch to find repne scasb;search for match ;make at most cx comparisons jnenomatch;ZF never set ;match occurred at ES:[di-1] ;di is incremented even if match

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 17 Compare String CMPSB, CMPSW Compares DS:SI to ES:DI, setting flags and auto-increments/decrements SI and DI Used to compare arrays of words or arrays of bytes Typically used with conditional REP instruction

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 18 Example: String Compare movsi, offset str1 movdi, offset str2 cld;left to right processing movcx, 12;shorter string repe cmpsb ;cmp til <> or cx=0 jlstr1smaller jgstr2smaller ;the strings are equal - so far ;if sizes different, shorter string is less

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 19 String Instructions 例 410 :将数据段首地址为 string1 的 10 个 字符传送到附加数据段内,并将其从附 加数据段内读出显示。

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 20 String Instructions 例 411 :内存中以 BUFFER 为首地址的内 存单元中有 10 个非压缩 BCD 码形式存放 的十进制数,将这些数顺序在屏幕上显 示。

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 21 String Instructions 例 413 :从键盘输入一个字符串 string1 ( 使用 0A 号 DOS 功能调用实现),将该数 据块传送到 string2 ,并将小写变成大写, 遇到回车符结束。

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 22 Program Flow Control Instructions The instructions discussed thus far execute sequentially; that is, the CPU executes each instruction in the sequence it appears in your program. To write real programs requires several control structures, not just the sequence. Examples include the if statement, loops, and subroutine invocation (a call). Since compilers reduce all other languages to assembly language, it should come as no surprise that assembly language supports the instructions necessary to implement these control structures. unconditional transfersconditional transfers subroutinecallandreturn instructions80x86 program control instructions belong to three groups: unconditional transfers, conditional transfers, and subroutine call and return instructions. The following sections describe these instructions:

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 23 Unconditional Jumps The jmp (jump) instruction unconditionally transfers control to another point in the program. There are six forms of this instruction: an intersegment/direct jump, two intrasegment/direct jumps, an intersegment/indirect jump, and two intrasegment/indirect jumps. Intrasegment jumps are always between statements in the same code segment. Intersegment jumps can transfer control to a statement in a different code segment. These instructions generally use the same syntax, it is jmp target

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 24 The CALL and RET Instructions The call and ret instructions handle subroutine calls and returns. There are five different call instructions and six different forms of the return instruction:

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 25 The Conditional Jump Instructions Although the jmp, call, and ret instructions provide transfer of control, they do not allow you to make any serious decisions. The 80x86’s conditional jump instructions handle this task. The conditional jump instructions are the basic tool for creating loops and other conditionally executable statements like the if..then statement.

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 26 The Conditional Jump Instructions The conditional jumps test one or more flags in the flags register to see if they match some particular pattern. If the pattern matches, control transfers to the target location. If the match fails, the CPU ignores the conditional jump and execution continues with the next instruction. Some instructions, for example, test the conditions of the sign, carry, overflow, and zero flags. For example, after the execution of a shift left instruction, you could test the carry flag to determine if it shifted a one out of the H.O. bit of its operand. Likewise, you could test the condition of the zero flag after a test instruction to see if any specified bits were one. Most of the time, however, you will probably execute a conditional jump after a cmp instruction. The cmp instruction sets the flags so that you can test for less than, greater than, equality, etc.

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 27 The Conditional Jump Instructions

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 28 The Conditional Jump Instructions

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 29 The Conditional Jump Instructions

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 30 The Conditional Jump Instructions 例 417 : 在以 DATA1 为首地址的内存数据段中, 存放了 10 个 8 位的无符号数,是将其中的 最大数和最小数找出来,并存入 max 和 min 单元中。

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 31 本章中文作业 中文教材 第 1 题 第 2 题 第 3 题 第 6 题 第 9 题 第 11 题 第 12 题

Chapter Four-- The 80x86 Instruction Set Principles of Microcomputers 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 2015年10月6日 32 本章英文作业 1. Which flag(s) does the 80x86 use to check for unsigned arithmetic overflow? 2. Which flag(s) let you check for signed overflow?. 3. Which flag(s) does the 80x86 use to test the following unsigned conditions? How must the flags be set for the condition to be true? a) equal b) not equal c) less than d) less than or equal e) greater than f) greater than or equal 4. Repeat the above question for a signed comparison. 5. What instruction is CMP most similar to? 6. What instruction is TEST most similar to?