For the example slides do not click the mouse to see the full animation Microprocessor 1 Dr.Raed Al-qadi 2009 for the example slides do not click the mouse.

Slides:



Advertisements
Similar presentations
Register In computer architecture, a processor register is a small amount of storage available on the CPU whose contents can be accessed more quickly than.
Advertisements

There are two types of addressing schemes:
Data Movement Instructions
Gursharan Singh Tatla 21-Nov-20101www.eazynotes.com.
8086 : INSTRUCTION SET By, Pramod Sunagar Assistant Professor
Direct video practice and Keyboard Operations
8-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
Microcomputer & Interfacing Lecture 3
80x86 Processor Architecture
Topic – string – Ch. 11 [Marut] Ch. 4 [Brey] String Data Transfer Instructions – The Direction Flag – LODS Instructions – STOS Instructions – MOVS Instructions.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
An Introduction to 8086 Microprocessor.
3.7 String Instructions Specifying the Operands’ Size and Address and the String Direction STRING = a data collection in memory. String ELEMENTS can be:
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.
Types of Registers (8086 Microprocessor Based)
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
ICS312 Lecture13 String Instructions.
Addressing Modes of 8086 Processor Ammar Anwar Khan Electrical Engineer King Saud University Riyadh Saudi Arabia.
Click to add Title Comunicación y Gerencia Click To add Subtitle Click to add Text Fundamentals of Assembly Language.
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,
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.
Microprocessors used in Personal Computers. The Memory Map of a Personal Computers Transient Program Area (TPA): Holds the operating system (interrupt.
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.
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.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
Khaled A. Al-Utaibi  Introduction  The MOV Instruction  The LEA Instruction  The Stack Instructions  The String Data Transfer.
Internal Programming Architecture or Model
Lecture 11 Text mode video
Lecture 6 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
Intel MP Organization. Registers - storage locations found inside the processor for temporary storage of data 1- Data Registers (16-bit) AX, BX, CX, DX.
Chapter 8 String Operations. 8.1 Using String Instructions.
I NTEL 8086 M icroprocessor بسم الله الرحمن الرحيم 1.
Instruction set Architecture
Lecture 2 Programming of 8086 Лектор: Люличева И.А. 1.
Chapter Nov-2010
Presentation on Real Mode Memory Addressing
Assembly 07 String Processing.
Introduction to 8086 Microprocessor
BYTE AND STRING MANIPULATON
COURSE OUTCOMES OF MICROPROCESSOR AND PROGRAMMING
ADDRESSING MODES.
Microprocessor and Assembly Language
Chapter 4 Data Movement Instructions
EE3541 Introduction to Microprocessors
INSTRUCTION SET.
Assembly Language Programming Part 2
ADDRESSING MODES.
Intel 8088 (8086) Microprocessor Structure
Defining Types of data expression Dn [name] expression Dn [name]
Symbolic Instruction and Addressing
Data Addressing Modes • MOV AX,BX; This instruction transfers the word contents of the source-register(BX) into the destination register(AX). • The source.
3.6 Data transfer Instructions
Programming 8086 – Part IV Stacks, Macros
Chapter 4 Data Movement Instructions
Intel 8088 (8086) Microprocessor Structure
8086 Registers Module M14.2 Sections 9.2, 10.1.
CS-401 Computer Architecture & Assembly Language Programming
Lecture 1 Instruction set of 8086 Лектор: Люличева И.А. 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
T opic: S TRING I NSTRUCTION P RESENTED B Y: N OOR FATIMA M AHA AKRAM ASIF.
Lecture 06 Programming language.
Data Movement Instructions
Chapter 6 –Symbolic Instruction and Addressing
Presentation transcript:

for the example slides do not click the mouse to see the full animation Microprocessor 1 Dr.Raed Al-qadi 2009 for the example slides do not click the mouse to see the full animation

Instruction set for 8088/8086 microprocessors 1- Data transfer instructions. 2-ALU instructions. 3-Shift and rotate instructions. 4-Program control and subroutines instructions. 5-Miscallenous instructions. for the example slides do not click the mouse to see the full animation

Data transfer instructions. In 8088/8086 the data transfer or data movement instructions are : 1)MOV 2)IN/OUT 3)LEA 4)MOV OFFSET 5)XLAT 6)PUSH and POP 7)String instructions We are going to investigate these instructions in details. for the example slides do not click the mouse to see the full animation

MOV MOV instrucion has the following syntax: MOV dst,src ; just clone the src into the dst The following criteria's should be applied whereever MOV is used : 1- dst and src must be the same size. 2- dst must NOT be immediate value. 3- dst and src cant be segment registers at the same time. 4- dst and src cant be memory at the same time except with MOVS instruction ( discussed later).

for the example slides do not click the mouse to see the full animation Example 1 : *Knowing that, DS=2042H. SI=500H, AX=214E, MOV [SI],AX ; DS=2042H DS=20420H SI= H 20921H 214E AHAL 4E 21

for the example slides do not click the mouse to see the full animation Do’s and Don'ts Some special cases : Case 1 : MOV CS,anything; DONT ( if you transfer to CS problems occur since CS contains the program code) Case 2 : MOV Segment, anything ; DO if anything does not equal segment register Case 3 : MOV segment,segemnt; DO NOT Case 4: MOV mem,mem; DON'T, memory to memory is not allowed except with MOVS

for the example slides do not click the mouse to see the full animation IN/OUT These two instructions are used to read from and to a device. IN instruction syntax: IN AL,port address; (port <=255) AL or AX can be used only. Or IN AL,DX; only DX can be used here

for the example slides do not click the mouse to see the full animation IN is used to read from input device in separate I/O mode. Example 2: IN AL,KEYBOARD; true But, ADD AL,KEYBOARD; false IN AL,60H; true, means read from Device at address 60H I/O addresses 64Kbyte 0000 FFFF KEYBOARD

for the example slides do not click the mouse to see the full animation Example 3 : The serial port is at 03F8H(>255), read a byte from the serial port. Since 03F8H>255 MOV DX,03F8H IN AL,DX I/O addresses 64Kbyte 0000 FFFF data 03F8H DX=03F8H AL=data

for the example slides do not click the mouse to see the full animation Example 4 : Define the DISPLAY device at 2430H and read a byte from it. DISPLAY EQU 2430H MOV DX,DISPLAY IN AL,DX I/O addresses 64Kbyte 0000 FFFF DISPLAY 2430 DX=03F8H AL=data

for the example slides do not click the mouse to see the full animation OUT instruction Syntax: OUT port address, AL; can be AX or AL OUT DX,AL ; Just holds for DX Example 5: Send char ‘A’ to the printer at 03A0H. MOV DX,03A0H MOV AL,’A’ OUT DX,AL

for the example slides do not click the mouse to see the full animation LEA LEA stands for load effective address, it loads a 16 bit register with the offset address of the data specified by the operand. Syntax : LEA dst,src; dst stores the address of src

for the example slides do not click the mouse to see the full animation Example 6: Fill the array AR1 with ‘*’.org 300.data AR1 DB 20 DUP(?) LEA SI,AR1 MOV CX,20; LP : MOV [SI],’*’ INC SI LOOP LP SI=add(AR1) AR1 Cx= * * * * * * * * * * * * * * * * * * * *

for the example slides do not click the mouse to see the full animation MOV OFFSET The same as LEA, Syntax : MOV dst,OFFSET src; store the address of src into dst.

for the example slides do not click the mouse to see the full animation XLAT XLAT called translate instruction, the operation of XLAT is changing the value of AL with the memory pointed to by (AL+BX) Mem[AL+BX]AL AL=data AL=dddd BX=mmmm datadddd+mmmm

for the example slides do not click the mouse to see the full animation More clearly the XLAT instruction converts the content of register AL, using a table. Its beginning address is contained in register BX. The content of register AL is interpreted as a relative address in the table. XLAT is the only instruction that adds 8 bit number to 16 bit number! XLAT never Affects the flags..

for the example slides do not click the mouse to see the full animation Example 7: Suppose that a seven segment LED display lookup table is stored in memory at address TABLE, now XLAT can use this table to translate the BCD number in AL to a seven segment code also in AL. Let TABLE =1000H,DS=1000H,

for the example slides do not click the mouse to see the full animation First, obtain the look up table. gfedcbax0x0 x1x1 x2x2 x3x FH0 06H1 5BH2 4FH3 66H4 6DH5 7DH6 27H7 7FH8 6FH9 Next see the code

for the example slides do not click the mouse to see the full animation The code for the operation of converting is very simple using XLAT TABLE DB 3FH,06H,5BH,4FH,66H,6DH,7DH,27H,7FH,6FH MOV AL,SOME_BCD_VALUE MOV BX,OFFSET TABLE XLAT For example take 06H(6 BCD) for the initial value of AL,after translation AL contains 7DH, see the figures in the next slide.

for the example slides do not click the mouse to see the full animation AL=4FH TABLE DB 3FH,06H,5BH DB4FH,66H,6DH DB 7DH,27H,7FH,6FH MOV AL,06H MOV BX,OFFSET TABLE XLAT 3FH 06H 5BH 4FH 66H 6DH 7DH 27H 7FH 6FH DSTABLE BX=address (TABLE)=1000H 1000H AL=06H Temp=AL+BX=1006H AL=memory [temp] AL=4FH, which is the seven segment code of 06H

for the example slides do not click the mouse to see the full animation Example 8: Write code to read the input key from port (60H) and output the value to a 7-segemnt display at 80H. KEYS EQU 60H; DISPLAY EQU 80H; TABLE DB3FH,06H,5BH,4FH,66H,6DH,7DH,27H,7FH,6FH LEA BX,TABLE; IN AL,KEYS; XLAT OUT DISPLAY,AL

for the example slides do not click the mouse to see the full animation Stack instructions PUSH and POP Both are important to store and retrieve data from the LIFO structure (stack), PUSH instruction : In 8088 and 8086 PUSH always transfer 2 bytes of data to the stack. It has the following syntax : PUSH src; src could be any 2 byte register or memory location or immediate value

for the example slides do not click the mouse to see the full animation How does PUSH executes? Simply when we push 2 bytes of data to the stack, the most significant byte is stored in stack segment pointed to by SP-1, and the least significant to location pointed by SP-2,see the following example, Example 9 : let AX=31F2H,SP=100H,SS=2000H; CX=FFFFH,BX=413AH

for the example slides do not click the mouse to see the full animation SP=FE PUSH AX SS=2000H SP=100 31F2 AX 31 F2

for the example slides do not click the mouse to see the full animation Example 10: Assume SP=100H,SS=2000H AX=31F2H,BX=413AH,CX=FFFFH. We will see the changes in the stack after executing the following sentences : PUSH AX PUSH BX POP CX POP AX

for the example slides do not click the mouse to see the full animation SP=FCH SP=FEH SS=2000H SP=100H PUSH AX PUSH BX POP CX 31F2 AHAL 413A BHBL 31 F2 41 3A CHCL 3A41FF

for the example slides do not click the mouse to see the full animation Example 11: Write code to reverse string using stack operations. STR DB ‘HELLO’,00H ; REVSTR DB 256 DUP(?) MOV CX,0; count number of bytes LEA SI,STR; LEA DI,REVSTR

for the example slides do not click the mouse to see the full animation NEXT-CHAR : MOV AL,[SI] CMP AL,00 JE NEXT PUSH AX ;only care about AL INC CX; JMP NEXT-CHAR

for the example slides do not click the mouse to see the full animation NEXT: CMP CX,00; check if cx =0 or the string is null JE DONE-REV POP AX MOV [DI],AL INC DI DEC CX; JMP NEXT DONE-REV: MOV [DI],00; to terminate with null

for the example slides do not click the mouse to see the full animation String Instructions String instructions MOVS MOVSBMOVSW LODS LODSBLODSW STOS STOSBSTOSW B stands for byte, and W stands for word

for the example slides do not click the mouse to see the full animation MOVS *MOVSB : how does it execute? Copy byte at DS:[SI] to ES:[DI]. Update SI and DI. Note that MOVS instruction deals with SI in the data segment and DI in the extra segment. The extra segment can’t be overridden here). DS:[SI] - ES:[DI] if DF = 0 then (DF is D flag) SI = SI + 1 DI = DI + 1 else SI = SI - 1 DI = DI - 1

for the example slides do not click the mouse to see the full animation Using REP instruction with string instructions MOV CX,100 REP MOVSB How does the above code executes? IF (Dflag==0) { Memory[DI]  ----memory[SI] SI++;DI++; } else(If D flag==1) { SI--; DI –-;CX-- } IF(CX=!=0) repeat the instruction, other wise then next one CLD clears the D flag (D=0) STD sets the Dflag to 1(D=1) D=1 we decrement SI,DI D=0 we increment DI,SI

for the example slides do not click the mouse to see the full animation CLD MOV CX,100 REP MOVSB ; is same as: MOV CX,100; LP:MOV AL,[SI] MOV ES:[DI],AL INC SI INC DI LOOP LP

for the example slides do not click the mouse to see the full animation MOVSW *MOVSW : how does it execute? Copy word at DS:[SI] to ES:[DI]. Update SI and DI. The same as MOVSB except we move a word not abyte, see what happens to SI and DI. DS:[SI] - ES:[DI] if DF = 0 then SI = SI + 2 DI = DI + 2 else SI = SI - 2 DI = DI - 2

for the example slides do not click the mouse to see the full animation ES Example 12: Copy 1000 bytes from location STR1 to STR2,Both are in data segment. LEA SI,STR1 LEA DI, STR2 MOV AX,DS MOV ES,AX MOV CX,1000; CLD REP MOVSB 1000 bytes 1000 bytes STR1 STR2 DS SI=add(str1) DI=add(str2 AX=DS ES=AX=DS Load CX with 1000 Dflag=0

for the example slides do not click the mouse to see the full animation Example 13: Copy 500 words from physical address 0800:200 to physical address 4000:0300,use string instructions is the segment address and the 200 is the offset by contrast 4000 is the segment address and 0300 is its offset So, we begin by assigning the segments addresses to DS and ES and the offsets to SI and DI

for the example slides do not click the mouse to see the full animation MOV DS,0800H MOV ES,4000H MOV SI,0200H MOV DI,0300H CLD MOV CX,500 REP MOVSW 1000 bytes 1000 bytes DS=0800H ES=4000H SI=200 DI=300 D=0 DATADATA

for the example slides do not click the mouse to see the full animation STOSB and STOSW For STOSB Store byte in AL into ES:[DI]. Update DI. For STOSW Store word in AX into ES:[DI]. Update DI. How STOSB executes? ES:[DI] = AL if DF = 0 then DI = DI + 1 else DI = DI - 1 And STOSW executes the same as STOSB but DI is incremented or decremented by 2

for the example slides do not click the mouse to see the full animation LODSB and LODSW For LODSB this is how it is done AL = DS:[SI] if D = 0 then SI = SI + 1 else SI = SI – 1 And LODSW is the same except that SI is changed by 2

for the example slides do not click the mouse to see the full animation Example 14: Write program to clear DOS-screen. MOV ES,E000; E000:800 is not the real address of video memory but here is just to illustrate the idea MOV DI,800 CLD MOV CX,25*80; since the screen is 25*80 characters and it is done by assembler MOV AX,0020H; 00 for color and 20H for space REP STOSW

for the example slides do not click the mouse to see the full animation The old screen is character screen,and the characters that appear on it are stored in the video memory location,for each character 2 bytes are used one for the ASCCI and the other for the color HELLO HELLOHELLO 00 20H COLOR CHAR Black space

for the example slides do not click the mouse to see the full animation Review of data movement instructions MOV operand1,operand2 Copy operand2 to operand1 The MOV instruction cannot: set the value of the CS and IP registers. copy value of one segment register to another segment register (should copy to general register first). copy immediate value to segment register (should copy to general register first). Transfer instructions never affect the flags

for the example slides do not click the mouse to see the full animation LEA and MOV OFFSET do the same operation, they load the address of one memory location to a register. XLAT copies the memory location addressed by [AL+BX] to AL. PUSH and POP are used to store and to read from the stack, both cant deal with 8 bits register, just use 16 bits.

for the example slides do not click the mouse to see the full animation String instructions are : MOVSB,MOVSW,STOSB,STOSW,LODS B,LODSW. The are used for moving or stroing or loading a whole byte or a whole word at a time, they shrink the code to minimal size at most problems Only MOVS can move data from memory to memory locations