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.

Slides:



Advertisements
Similar presentations
DOS and BIOS Interrupts DOS and BIOS interrupts are used to perform some very useful functions, such as displaying data to the monitor, reading data from.
Advertisements

ICS312 Set 6 Operands. Basic Operand Types (1) Register Operands. An operand that refers to a register. MOV AX, BX ; moves contents of register BX to.
More about procedures and Video Processing. Lesson plan Review existing concepts More about procedures and boolean expression Video processing.
8086 : INSTRUCTION SET By, Pramod Sunagar Assistant Professor
Direct video practice and Keyboard Operations
Assembly Language for Intel-Based Computers Chapter 15: BIOS-Level Programming (c) Pearson Education, All rights reserved. You may modify and.
Chapter 7 Programming with DOS and BIOS Function Calls Objectives: The use of DOS and BIOS function call How to read the PC’s keyboard How to send text.
8-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
Kip Irvine: Assembly Language for Intel-Based Computers
Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction Flag – LODS Instructions – STOS Instructions – MOVS Instructions.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#8) By Dr. Syed Noman.
Programming the Microprocessor A Course in Microprocessor Electrical Engineering Dept. University of Indonesia.
Assembly Programming Timothy C. Rice Jr., MIT. OUTLINE Basic Structure Exit to Dos Print Character Clear Screen Change BG & FG Color Set Curser Location.
ICS312 Set 4 Program Structure. Outline for a SMALL Model Program Note the quiz at the next lecture will be to reproduce this slide.MODEL SMALL.586 ;
ORG ; FOUR INT 21H and INT 10H Programming and Macros Dec Hex Bin
CDP ECE Spring 2000 ECE 291 Spring 2000 Lecture 7: More on Addressing Modes, Structures, and Stack Constantine D. Polychronopoulos Professor, ECE.
BIOS1 Basic Input Output System BIOS BIOS refers to a set of procedures or functions that enable the programmer have access to the hardware of the computer.
3.7 String Instructions Specifying the Operands’ Size and Address and the String Direction STRING = a data collection in memory. String ELEMENTS can be:
Text-mode Video Dr. Dimitrios S. Nikolopoulos CSL/UIUC
1/2002JNM1 Positional Notation (Hex Digits). 1/2002JNM2 Problem The 8086 has a 20-bit address bus. Therefore, it can access 1,048,576 bytes of memory.
11.1/36 Repeat: From Bits and Pieces Till Strings.
BIOS and DOS Programming in DOS INT 10 and 21H. Interrupts There are some extremely useful subroutines within BIOS or DOS that are available to the user.
1 Screen and Keyboard Operations Suthida Chaichomchuen
Text-Mode Programming Question #1 What are the three levels of access to the video display when writing characters on the screen in text mode?
Objective At the conclusion of this chapter you will be able to:
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)
Strings, Procedures and Macros
Video systems. Lesson plan Review the code for the previous exercise Video systems Review for midterm exam.
ICS312 Lecture13 String Instructions.
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.
10H Interrupt. Option 0H – Sets video mode. Registers used: – AH = 0H – AL = Video Mode. 3H - CGA Color text of 80X25 7H - Monochrome text of 80X25 Ex:
String Processing Chapter 10 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
4. Kernel and VGA ENGI 3655 Lab Sessions. Richard Khoury2 Textbook Readings  None.
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.
Microprocessors Monday, Apr. 16 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Multi-module programming. Requirements of an assembly language module when it is linked with another module PUBLIC directive - it exports to other modules.
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.
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.
Lecture 11 Text mode video
Lecture 6 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
File Operations. FILE PROCESSING For the purposes of the following discussion, reading means copying all or part of an existing file into memory Writing.
Chapter 8 String Operations. 8.1 Using String Instructions.
1 Computer Architecture & Assembly Language Spring 2001 Dr. Richard Spillman Lecture 10 –Assembly V.
Format of Assembly language
Chapter Nov-2010
Assembly 07 String Processing.
BYTE AND STRING MANIPULATON
Chapter 4 Data Movement Instructions
EE3541 Introduction to Microprocessors
INSTRUCTION SET.
Intel 8088 (8086) Microprocessor Structure
Microprocessor and Assembly Language
Defining Types of data expression Dn [name] expression Dn [name]
Symbolic Instruction and Addressing
Chapter 4 Data Movement Instructions
Intel 8088 (8086) Microprocessor Structure
8086 Registers Module M14.2 Sections 9.2, 10.1.
Morgan Kaufmann Publishers Computer Organization and Assembly Language
32-bit instruction mode(80386-Pentium 4 only)
Symbolic Instruction and Addressing
Symbolic Instruction and Addressing
Assembly Language for Intel-Based Computers, 5th Edition
T opic: S TRING I NSTRUCTION P RESENTED B Y: N OOR FATIMA M AHA AKRAM ASIF.
Unit:08 Software Interrupts
Data Movement Instructions
UNIT-II Assembly Language Programs Involving Logical
Chapter 6 –Symbolic Instruction and Addressing
Presentation transcript:

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 being accessed or manipulated. The operation of the dedicated registers stated above are used to simplify code and minimize its size.

String Instructions The registers(DI,SI) are automatically incremented or decremented depending on the value of the direction flag:  DF=0, increment SI, DI.  DF=1, decrement SI, DI. To set or clear the direction flag one should use the following instructions:  CLD to clear the DF.  STD to set the DF.

String Instructions The REP/REPZ/REPNZ prefixes are used to repeat the operation it precedes. String instructions we will discuss:  LODS  STOS  MOVS  CMPS  SCAS  INS  OUTS

LODS/LODSB/LODSW/LODSD Loads the AL, AX or EAX registers with the content of the memory byte, word or double word pointed to by SI relative to DS. After the transfer is made, the SI register is automatically updated as follows:  SI is incremented if DF=0.  SI is decremented if DF=1.

LODS/LODSB/LODSW/LODSD Examples:  LODSB AL=DS:[SI]; SI=SI  1  LODSW AX=DS:[SI]; SI=SI  2  LODSD EAX=DS:[SI]; SI=SI  4  LODS MEAN AL=DS:[SI]; SI=SI  1 (if MEAN is a byte)  LODS LIST AX=DS:[SI]; SI=SI  2 (if LIST is a word)  LODS MAX EAX=DS:[SI]; SI=SI  4 (if MAX is a double word)

LODS/LODSB/LODSW/LODSD

STOS/STOSB/STOSW/STOSD Transfers the contents of the AL, AX or EAX registers to the memory byte, word or double word pointed to by DI relative to ES. After the transfer is made, the DI register is automatically updated as follows:  DI is incremented if DF=0.  DI is decremented if DF=1.

STOS/STOSB/STOSW/STOSD Examples:  STOSB ES:[DI]=AL; DI=DI  1  STOSW ES:[DI]=AX; DI=DI  2  STOSD ES:[DI]=EAX; DI=DI  4  STOS MEAN ES:[DI]=AL; DI=DI  1 (if MEAN is a byte)  STOS LIST ES:[DI]=AX; DI=DI  2 (if LIST is a word)  STOS MAX ES:[DI]=EAX; DI=DI  4 (if MAX is a double word)

STOS/STOSB/STOSW/STOSD

MOVS/MOVSB/MOVSW/MOVSD Transfers the contents of the the memory byte, word or double word pointed to by SI relative to DS to the memory byte, word or double word pointed to by DI relative to ES. After the transfer is made, the DI register is automatically updated as follows:  DI is incremented if DF=0.  DI is decremented if DF=1.

MOVS/MOVSB/MOVSW/MOVSD Examples:  MOVSB ES:[DI]=DS:[SI]; DI=DI  1;SI=SI  1  MOVSW ES:[DI]= DS:[SI]; DI=DI  2; SI=SI  2  MOVSD ES:[DI]=DS:[SI]; DI=DI  4; SI=SI  4  MOVS MEAN1,MEAN2 ES:[DI]=DS:[SI]; DI=DI  1; SI=SI  1 (if MEAN1 and MEAN2 are byte sized)  MOVS LIST1,LIST2 ES:[DI]=DS:[SI]; DI=DI  2; SI=SI  2 (if LIST1 and LIST2 are word sized)  MOVS MAX1,MAX2 ES:[DI]=DS:[SI]; DI=DI  4; SI=SI  4 (if MAX1 and MAX2 are double word sized)

MOVS/MOVSB/MOVSW/MOVSD

INS/INSB/INSW/INSD Transfer the contents of the port addressed by DX to the memory byte, word or double word pointed to by DI relative to ES. After the transfer is made, the DI register is automatically updated as follows:  DI is incremented if DF=0.  DI is decremented if DF=1.

INS/INSB/INSW/INSD Examples:  INSB ES:[DI]=[DX]; DI=DI  1  INSW ES:[DI]= [DX]; DI=DI  2  INSD ES:[DI]=[DX]; DI=DI  4  INS MEAN ES:[DI]=[DX]; DI=DI  1 (if MEAN is a byte)  INS LIST ES:[DI]=[DX]; DI=DI  2 (if LIST is a word)  INS MAX ES:[DI]=[DX]; DI=DI  4 (if MAX is a double word)

OUTS/OUTSB/OUTSW/OUTSD Transfer the contents of the memory byte, word or double word pointed to by SI relative to DS to the port addressed by DX. After the transfer is made, the SI register is automatically updated as follows:  SI is incremented if DF=0.  SI is decremented if DF=1

OUTS/OUTSB/OUTSW/OUTSD Examples:  OUTSB [DX]=DS:[SI]; SI=SI  1  OUTSW [DX]= DS:[SI]; SI=SI  2  OUTSD [DX]=DS:[SI]; SI=SI  4  OUTS MEAN [DX]=DS:[SI]; SI=SI  1 (if MEAN is a byte)  OUTS LIST [DX]=DS:[SI]; SI=SI  2 (if LIST is a word)  OUTS MAX [DX]=DS:[SI]; SI=SI  4 (if MAX is a double word)

CMPS/CMPSB/CMPSW/CMPSD Compares the contents of the the memory byte, word or double word pointed to by SI relative to DS to the memory byte, word or double word pointed to by DI relative to ES and changes the flags accordingly. After the comparison is made, the DI and SI registers are automatically updated as follows:  DI and SI are incremented if DF=0.  DI and SI are decremented if DF=1.

SCAS/SCASB/SCASW/SCASD Compares the contents of the AL, AX or EAX register with the memory byte, word or double word pointed to by DI relative to ES and changes the flags accordingly. After the comparison is made, the DI register is automatically updated as follows:  DI is incremented if DF=0.  DI is decremented if DF=1.

REP/REPZ/REPNZ These prefixes cause the string instruction that follows them to be repeated the number of times in the count register ECX or until:  ZF=0 in the case of REPZ (repeat while equal).  ZF=1 in the case of REPNZ (repeat while not equal).

REP/REPZ/REPNZ Use REPNE and SCASB to search for the character ‘f’ in the buffer given below. BUFFER DB ‘EE3751’ MOV AL,’f’ LEA DI,BUFFER MOV ECX,6 CLD REPNE SCASB JE FOUND

REP/REPZ/REPNZ Use REPNE and SCASB to search for the character ‘3’ in the buffer given below. BUFFER DB ‘EE3751’ MOV AL,’f’ LEA DI,BUFFER MOV ECX,6 CLD REPNE SCASB JE FOUND

Modular Programming Many programs are too large to be developed by a single individual. A team of programmers develops different parts of the system and their program modules are linked together, thus becoming a large program which includes all modules programmed separately.

The Assembler and Linker The Assembler converts an ASCII source file created by the programmer into hexadecimal object file.  TASM PROG1.ASM The Linker reads the object file and creates the executable file.  TLINK PROG1.OBJ

PUBLIC and EXTERN These two directives allow the programmer to define labels, data, and entire segments as follows:  PUBLIC defines that labels, data, and entire segments are available for other program modules to use..DATA PUBLIC LIST LIST DB 50 DUP(?) .

PUBLIC and EXTERN  EXTERN declares that labels are external to a module. If data is defined as external, their sizes must be defined..DATA  Extrn LIST:byte.CODE  Extrn POWER:far

Libraries Collections of procedures that may be used by many different programs.

DOS and BIOS Interrupts DOS and BIOS interrupts are used to perform some very useful functions, such as displaying data to the monitor, reading data from keyboard, etc. They are used by identifying the interrupt option type, which is the value stored in register AH and providing, whatever extra information that the specific option requires.

BIOS Interrupt 10H Option 0H – Sets video mode. Registers used:  AH = 0H  AL = Video Mode. 3H - CGA Color text of 80X25 7H - Monochrome text of 80X25 Ex:  MOV AH,0  MOV AL,7  INT 10H

BIOS Interrupt 10H Option 2H – Sets the cursor to a specific location.  Registers used:  AH = 2H  BH = 0H selects Page 0.  DH = Row position.  DL = Column position.  Ex:  MOV AH,2  MOV BH,0  MOV DH,12  MOV DL,39  INT 10H

BIOS Interrupt 10H Option 6H – Scroll window up. This interrupt is also used to clear the screen when you set AL = 0. Registers used: AH = 6H AL = number of lines to scroll. BH = display attribute. CH = y coordinate of top left. CL = x coordinate of top left. DH = y coordinate of lower right. DL = x coordinate of lower right.

BIOS Interrupt 10H Clear Screen Example: MOV AH,6 MOV AL,0 MOV BH,7 MOV CH,0 MOV CL,0 MOV DH,24 MOV DL,79 INT 10H The code above may be shortened by using AX, BX and DX registers to move word size data instead of byte size data.

BIOS Interrupt 10H Option 7H – Scroll window down. This interrupt is also used to clear the screen when you set AL = 0. Registers used:  AH = 7H  AL = number of lines to scroll.  BH = display attribute.  CH = y coordinate of top left.  CL = x coordinate of top left.  DH = y coordinate of lower right.  DL = x coordinate of lower right.

BIOS Interrupt 10H Option 8H – Read a character and its attribute at the cursor position. Registers used:  AH = 8H and returned attribute value.  AL = Returned ASCII value.  BH = display page.

BIOS Interrupt 10H Option 9H – Write a character and its attribute at the cursor position. Registers used:  AH = 9H.  AL = ASCII value.  BH = display page.  BL = attribute.  CX = number of characters to write.

Attribute Definition Monochrome display attributes  Blinking D7 = 0 - Non-blinking D7 = 1 - Blinking  Intensity D3=0 - Normal intensity D3=1 - Highlighted intensity  Background and foreground D6 D5 D4 and D2 D1 D0  White =  Black = 1 1 1

Attribute Definition Color display attributes  Blinking D7 = 0 - Non-blinking D7 = 1 - Blinking  Intensity D3=0 - Normal intensity D3=1 - Highlighted intensity  Background and foreground D6 D5 D4 and D2 D1 D0  RGB values defined by the table to the right.

DOS Interrupt 21H Option 1 – Inputs a single character from keyboard and echoes it to the monitor. Registers used:  AH = 1  AL = the character inputted from keyboard. Ex:  MOV AH,1  INT 21H

DOS Interrupt 21H Option 2 – Outputs a single character to the monitor. Registers used:  AH = 2  DL = the character to be displayed. Ex:  MOV AH,2  MOV DL,’A’  INT 21H

DOS Interrupt 21H Option 6 – Inputs a single character from keyboard without an echo to the monitor. Registers used:  AH = 6  AL = the character inputted from keyboard.  DL = 0FFH or -1 Ex:  MOV AH,6  MOV DL,-1  INT 21H

DOS Interrupt 21H Option 9 – Outputs a string of data, terminated by a $ to the monitor. Registers used:  AH = 9  DX = the offset address of the data to be displayed. Ex:  MOV AH,09  MOV DX,OFFSET MESS1  INT 21H

DOS Interrupt 21H Option 0AH – Inputs a string of data from the keyboard. Registers used:  AH = 9  DX = the offset address of the location where string will be stored. DOS requires that a buffer be defined in the data segment. It should be defined as follows:  1 st byte contains the size of the buffer.  2 nd byte is used by DOS to store the number of bytes stored.

DOS Interrupt 21H Ex: .DATA  BUFFER1DB0FH,?,0FH DUP (0FFH) .  MOV AH,0AH  MOV DX,OFFSET BUFFER1  INT 21H Assume “Go Tigers!” was entered on the keyboard.  BUFFER1 = 0FH,0BH,’Go Tigers!’,CR,0FFH, 0FFH, 0FFH, 0FFH

DOS Interrupt 21H Option 4CH – Terminates a process, by returning control to a parent process or to DOS. Registers used:  AH = 4CH  AL = binary return code. Ex:  MOV AH,4CH  INT 21H

Macros Format  Name MACRO Argument,Argument Macro code  ENDM Example  Power MACRO X,N

Macros SWAP MACRO X,Y PUSH AX PUSH DX MOV AX,X MOV DX,Y MOV Y,AX MOV X,DX POP DX POP AX ENDM SWAP VAR1,VAR2 PUSH AX PUSH DX MOV AX,VAR1 MOV DX,VAR2 MOV VAR2,AX MOV VAR1,DX MOP DX POP AX

Macros A local variable is a variable that appears only in the macro. Local variables need to be defined with the local directive. Example:  DELAY MACRO COUNT  LOCAL AGAIN  PUSH CX  MOV CX,COUNT  AGAIN:LOOP AGAIN  POP CX