BITS Pilani Pilani Campus Pawan Sharma Lecture 26-28 05-03-2012 EEE /INSTR/CS F241 ES C263 Microprocessor Programming and Interfacing.

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

Registers of the 8086/ /2002 JNM.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 2 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Introduction to 8086 Microprocessor
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#3) By Dr. Syed Noman.
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
Gursharan Singh Tatla 21-Nov-20101www.eazynotes.com.
8086 : INSTRUCTION SET By, Pramod Sunagar Assistant Professor
8-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
9-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
80x86 Processor Architecture
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
Assembly Language – Lab 5
An Introduction to 8086 Microprocessor.
Microprocessor Programming II
Types of Registers (8086 Microprocessor Based)
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Strings, Procedures and Macros
Arithmetic Flags and Instructions
Writing and using procedures
Click to add Title Comunicación y Gerencia Click To add Subtitle Click to add Text Fundamentals of Assembly Language.
Microprocessor Programming II To discuss more complicated programming techniques Flag control instructions Compare and jump Subroutines Loop and string.
Review of Assembly language. Recalling main concepts.
University of Sargodha, Lahore Campus Prepared by Ali Saeed.
MOV Instruction MOV destination,source  MOV AX,BX  MOV SUM,EAX  MOV EDX,ARRAY[EBX][ESI]  MOV CL,5  MOV DL,[BX]
Microprocessor & Assembly Language Arithmetic and logical Instructions.
MODULE 5 INTEL TODAY WE ARE GOING TO DISCUSS ABOUT, FEATURES OF 8086 LOGICAL PIN DIAGRAM INTERNAL ARCHITECTURE REGISTERS AND FLAGS OPERATING MODES.
Khaled A. Al-Utaibi  Introduction  The MOV Instruction  The LEA Instruction  The Stack Instructions  The String Data Transfer.
Internal Programming Architecture or Model
BITS Pilani Pilani Campus Pawan Sharma Lecture /12/ EEE /INSTR/CS F241 ES C263 Microprocessor Programming and Interfacing.
Computer Organization & Assembly Language University of Sargodha, Lahore Campus Prepared by Ali Saeed.
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.
I NTEL 8086 M icroprocessor بسم الله الرحمن الرحيم 1.
Assembly language programming
Format of Assembly language
Chapter Nov-2010
Introduction to 8086 Microprocessor
8086 Microprocessor.
Instruksi Set Prosesor 8088
Microprocessor and Assembly Language
Chapter 4 Data Movement Instructions
EE3541 Introduction to Microprocessors
INSTRUCTION SET.
Multiplication and Division Instructions
INSTRUCTION SET.
Assembly Language Programming Part 2
University of Gujrat Department of Computer Science
Intel 8088 (8086) Microprocessor Structure
INSTRUCTION SET OF 8086 PAWAN KUMAR SINGH.
Defining Types of data expression Dn [name] expression Dn [name]
Symbolic Instruction and Addressing
X86’s instruction sets.
Introduction to Assembly Language
Chapter 4: Instructions
Data Addressing Modes • MOV AX,BX; This instruction transfers the word contents of the source-register(BX) into the destination register(AX). • The source.
Morgan Kaufmann Publishers Computer Organization and Assembly Language
ارايه دهنده : حسن عسكرزاده
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
Symbolic Instruction and Addressing
Symbolic Instruction and Addressing
Computer Architecture CST 250
Unit-I 80386DX Architecture
Chapter 6 –Symbolic Instruction and Addressing
Multiplication and Division Instructions
Multiplication and Division Instructions
Chapter 8: Instruction Set 8086 CPU Architecture
Presentation transcript:

BITS Pilani Pilani Campus Pawan Sharma Lecture EEE /INSTR/CS F241 ES C263 Microprocessor Programming and Interfacing

BITS Pilani, Pilani Campus  String Instructions  Logical Instructions  IN/OUT instructions Last Lecture

BITS Pilani, Pilani Campus  Program Models  LOOP instructions  Signed multiplication and division  In/OUT instr  PUSH/POP Today’s Lecture

BITS Pilani, Pilani Campus Program Models MASM (Microsoft Assembler)

BITS Pilani, Pilani Campus MODELS  There are many models available to MASM Assembler ranging from Tiny to Huge  To designate a model use the.MODEL statement followed by the size of the memory system Ex:.MODEL TINY – enables the use of simplified segments TINY Model requires that all program and data fit into one 64K segment . DATA defines data segment .CODE defines code segment .STARTUP .EXIT

BITS Pilani, Deemed to be University under Section 3 of UGC Act, model tiny.data DATA1 DB 23 DATA2 DW 9999h DATA3 DW 9999 ARRAY DW 01,02,03,04,05,06,07,08.code.startup MOV BX,DATA2 MOV CX,DATA3 MOV DATA1,BL MOV DL,DATA1 MOVDI,0001 H MOV AX, ARRAY [DI].exit end

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956.model tiny.DATA DATA1 DB 23H ARRAY DW 01,02,03,04,05,06,07,08.CODE.startup MOV AX, ARRAY MOV CL, DATA1 MOV BX, OFFSET ARRAY MOV AL,[BX].exit end

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956 Model TypeDescription TinyAll the data and code fit in one segment. Tiny programs are written in.COM which means the program must be originated at location 100H SmallContains two segments - One DS of 64k bytes and one CS of 64k bytes MediumContains one DS of 64kbyte and any number of CS for large programs CompactOne CS contains the program and any number of DS contains the data Largeallows any number of CS & DS HugeSame as large - but the DSs may contain more than 64k bytes each * Flat Model –Special type of Tiny Model for 32-bit

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956.MODEL SMALL; This statement is required before you can use other ;simplified segment directives.STACK ; Use default 1-kilobyte stack.DATA ; Begin data segment ; Place data declarations here.CODE ; Begin code segment.STARTUP ; Generate start-up code  ; Place instructions here.EXIT ; Generate exit code END

BITS Pilani, Pilani Campus  Used to repeat a series of instructions some number of times and are basically conditional jump instructions.  The no. of times, sequence is to be repeated is loaded in CX  Combines two operations in each instruction.  First, each time Loop instruction executes, CX automatically decrements by 1  Secondly, jump to a specified label if CX  0, and sometimes checks zero flag, after auto- decrement of CX LOOP

BITS Pilani, Pilani Campus  IF CX  0 execution will jump to destination, specified by a label in the instruction  If CX = 0 after auto dec, execution will go on to the next instruction after LOOP  Destination address is of type SHORT  LOOP affects no FLAGs

BITS Pilani, Pilani Campus Add a data in one block of memory with data in another block of memory using LOOP Size of block -100 words Y 1 =X 1 + Y 1 Y 2 =X 2 + Y 2 ………… Y n= =X n + Y n

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956.Model Tiny.data BLOCK1 DW 100 DUP(01) BLOCK2 DW 100 DUP(02) COUNTDW100.code.startup CLD MOV CX, COUNT MOV SI, OFFSET BLOCK1 MOV DI, OFFSET BLOCK2 X1: LODSW ADD AX, ES:[DI] STOSW LOOP X1.EXIT END

BITS Pilani, Pilani Campus LOOPE/LOOPZ ( LOOP while equal)  LOOP while CX  0 and ZF = 1  Each time the LOOP instr executes - CX decremented  If CX  0 & ZF = 1 execution will jump to destination specified  If CX = 0 after auto decrement or ZF = 0 execution will go to the next instruction  Destination address must be within -128 bytes to +127 bytes (short jump) Conditional LOOPs

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956 MOV BX, OFFSET ARRAY DEC BX MOV CX, 100 NEXT: INC BX CMP [BX], 0FF H LOOPE NEXT On exit from loop: CX=0 and ZF=1  all elements are equal to FFH CX≠0  BX points to the first element that was not FFH CX=0 and ZF=0  last element was not FFH

BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956 LOOPNE/LOOPNZ Loop While CX  0 and ZF = 0 MOV BX, OFFSET ARRAY DEC BX MOV CX, 100 NEXT: INC BX CMP [BX], 0D H LOOPNE NEXT On exit from loop: CX=0 and ZF=0  0DH was not found in array CX≠0  BX points to the first element that contains 0DH CX=0 and ZF=1  the last array element was 0DH

BITS Pilani, Pilani Campus Multiply & Divide

BITS Pilani, Pilani Campus MUL SOURCE  Source times AL  Source times AX  Source can be a register or memory location  Result for Byte multiplication in AX  Result for Word multiplication in DX :AX  CF and OF zero if MSB/MSW zero  AF,PF,SF,ZF -undefined

BITS Pilani, Pilani Campus MUL BH MUL CX MUL BYTE PTR [BX] MOV AX, MULTIPLICAND _16 MOV CL, MULTIPLIER _8 MOV CH, 00 H MUL CX Multiplying byte with a word requires the byte’s MSB to be filled with 0’s

BITS Pilani, Pilani Campus.MODEL TINY.DATA MULTIPLICAND DW 2040 H MULTIPLIER DW 2000 H PRODUCT1 DW ? PRODUCT2 DW ?.CODE.STARTUP MOV AX, MULTIPLICAND MUL MULTIPLIER MOV PRODUCT1, AX MOV PRODUCT2, DX.EXIT END

BITS Pilani, Pilani Campus IMUL SOURCE  Signed Multiplication  Source times AL  Source times AX  Source can be a register or memory location  Result for Byte multiplication in AX  Result for Word multiplication in DX :AX  CF and OF zero if MSB/MSW zero ---- allows the user to detect and perhaps discard unnecessary leading zero’s in a result. If MSB and MSW contain part of the result, then both CF=OF=1  AF,PF,SF,ZF -undefined

BITS Pilani, Pilani Campus IMUL BH IMUL CX IMUL BYTE PTR [BX] MOV CX, MULTIPLICAND _16 MOV AL, MULTIPLIER _8 CBW IMUL CX

BITS Pilani, Pilani Campus DIV SOURCE Divides UNSIGNED WORD by a BYTE Divides UNSIGNED DWORD by a WORD  Word/Byte  Word in AX,  Byte in Register/Memory location  AL- quotient AH- reminder  DWORD/WORD  DWORD in DX : AX  Word in Register/Memory Location  AX- QuotientDX- Reminder All Flags undefined To divide a byte by a byte, put the dividend byte in AL and fill AH with 0’s

BITS Pilani, Pilani Campus IDIV SOURCE SIGNED WORD/BYTE SIGNED DWORD/WORD Word/Byte Dividend Word in AX, Divisor Byte in Register/Memory location AL- quotient AH- reminder DWORD/WORD Dividend DWORD in DX : AX Divisor Word in Register/Memory Location AX- QuotientDX- Reminder All Flags undefined- Sign of remainder same as dividend To divide a byte by a byte, put the dividend byte in AL and fill AH with copies of the sign bit from AL.

BITS Pilani, Pilani Campus IN Accumulator, PORT  Copy a data from a port to AL (if 8-bit port or I/O address is read) or AX (if 16-bit port or I/O address is addressed)  I/O ports are 8-bits in width so whenever a 16-bit port is accessed, two consecutive 8-bit ports are actually addressed.  Two formats possible  Fixed port (the 8-bit address of a port is directly specified in the instruction) and variable port ( the port address is loaded into the DX register used to address the I/O device, before the IN instruction) – IN AL, 00 H – IN AX, 20 H INPUT AND OUTPUT INSTRUCTIONS

BITS Pilani, Pilani Campus Port address appear on the address bus during I/O operation 8-bit address zero extended – IN AL, 06 H  Copies data from port and address appear as 0006 H on (A 0 to A 15 )  Other higher address undefined

BITS Pilani, Pilani Campus Variable Port Addressing allows transfer between AL, AX and a 16-bit port address available in DX DX can be changed by program control, giving a variable address. Does not affect flags. Advantage over fixed-port addressing. – MOV DX,0FF78H;initialize DX to point to port – IN AL, DX; input a byte from 8 bit port FF78H to AL – IN AX, DX; input a word from 16-bit port FF78H(LSB) ;and FF79H (MSB)

BITS Pilani, Pilani Campus OUT PORT, Accumulator  Copies a byte from AL or a word from AX to the specified port. Has two possible forms: fixed port and variable port.  OUT 05 H, AL  OUT 03 H, AX  MOV DX, 0FFF8H  OUT DX, AL  OUT DX, AX Fixed port variable port

BITS Pilani, Pilani Campus  Input a data from a port at address 05 H. Input data is a valid one digit BCD number. Use a lookup table to convert it into seven segment code. Output to port 50 H

BITS Pilani, Pilani Campus a b c d e f g h a b c d e f g h Seven segment display

BITS Pilani, Pilani Campus.Model Tiny.DATA TABLE DB 3F H, 06H, 5B H, 4F H, 66 H, 6D H DB 7D H, 07 H, 7F H, 67 H----common cathode configuration.CODE.STARTUP IN AL, 05 H LEASI, TABLE MOVBX,0 ADDBL,AL MOVAL,[SI+BX] OUT50 H,AL.EXIT END

BITS Pilani, Pilani Campus XLAT  Translate instruction used to translate a byte from one code to another code.  The instruction replaces a byte in the AL register with a byte pointed to by BX in a lookup table in memory.  Before using XLAT, the lookup table containing the values of new code is put in memory  Offset of the starting address of the table is loaded into BX  Byte to be translated is put in AL  To point to the byte in table, adds the contents of AL with BX to form a memory address in data segment  Copies the contents of this memory (BX + AL) into AL

BITS Pilani, Pilani Campus.Model Tiny.DATA TABLE DB 3F H, 06 H, 5B H, 4F H, 66 H, 6D H DB 7D H, 07 H, 7F H, 67 H.CODE.STARTUP IN AL, 05 H LEA BX, TABLE XLAT OUT50 H,AL.EXIT END

BITS Pilani, Pilani Campus PUSH and POP Instructions  Store and retrieve data from LIFO stack memory  Two bytes involved  Whenever data pushed into stack  MSB moves into memory [SP-1]  LSB moves into memory [SP-2]  Contents of SP register decremented by 2

BITS Pilani, Pilani Campus  Push source  Registers/Segment Register  Memory  Flag Register  PUSH AX;decrement SP by 2, copy AX to stack  PUSH BX  PUSH SI  PUSH WORD PTR[BX]; decrement SP by 2, copy word from ;memory in DS at [BX] to stack  PUSHF

BITS Pilani, Pilani Campus H 7004F H AH 7004E H AL 7004D H BH 7004C H BL 7004B H SIH 7004A H SIL H MEMH H MEML H FRH H FRL SP  SP-2[004E H ] 7004E H  AX SP  SP-2[004C H ] 7004C H  BX SP  SP-2[004A H ] 7004A H  SI SP  SP-2[0048 H ] H  MEM SP  SP-2[0046 H ] H  FLAGS SP:0050 H SS:7000 H

BITS Pilani, Pilani Campus POP  POP performs inverse of PUSH  Takes data from stack to general purpose register, memory or segment register  Data popped in 16 bits  First byte from stack to lower register  Second byte to higher address  SP = SP+2 – POP AX – POP CX – POP WORD PTR[BX] – POP CS is illegal

BITS Pilani, Pilani Campus Q: Set the TRAP flag without changing any of the other flags PUSHF MOV BP,SP INC BP OR [BP],01H POPF

BITS Pilani, Pilani Campus Subroutines

BITS Pilani, Pilani Campus CALL Instruction  CALL instruction in the main line program loads the Instruction pointer and in some cases also the Code Segment register with the starting address of the procedure  Next instruction fetched will be the first instruction of the procedure

BITS Pilani, Pilani Campus RET instruction at the procedure end, sends the execution back to the instruction after the CALL instruction in the main line program RET MAIN CALL Sub- Program

BITS Pilani, Pilani Campus CALL Stores the address of the instruction after CALL, into stack ( return address) near CALL or far CALL (IP saved) (CS and IP saved)  RET inst retrieves the next address after CALL  Back to IP or ( IP and CS)

BITS Pilani, Pilani Campus DIRECT WITHIN –SEGMENT- NEAR CALL  RELATIVE DISPLACEMENT  CALL LABEL  IP IP + d16 (signed displacement)‏ INDIRECT WITHIN SEGMENT- NEAR CALL  16-BIT IP REPLACED BY REGISTER / MEMORY LOCATION CONTENTS  CALL BP  CALL WORD PTR [BX]  IP reg16/mem16

BITS Pilani, Pilani Campus DIRECT INTERSEGMENT FAR CALL Both CS and IP needs to be changed CALL IPL IPH CSL CSH INDIRECT INTERSEGMENT FAR CALL Two words taken From Memory First word  IP, Second word  CS CALL DWORD PTR [BX]

BITS Pilani, Pilani Campus Instruction Timing and Delay Loops

BITS Pilani, Pilani Campus Subroutine commonly used is delay subroutine Software delays using LOOP Delay required = 1ms =1000µs 8086 running on 5MHz clock- Each cycle is 0.2µs  Total of 5000 clock cycles required=C T Introduce the instructions: MOV CX,N 4 Cycles X1: NOP 3 Cycles NOP 3 Cycles LOOP X1 17 or 5 Cycles

BITS Pilani, Pilani Campus Overhead = C O = 4 Number of cycles/loop = C L = = 23 Number of times the loop runs = N C T = C 0 + N*C L – = 4 + N*23 –12  N = 218

BITS Pilani, Pilani Campus Write an ALP that takes 100 data samples from input port, at intervals of 1ms and masks the upper four bits of each sample and puts each masked sample in successive memory locations in ARRAY –using subroutines

BITS Pilani, Pilani Campus In Assembly language programming, Procedures (subroutines) begin with PROC directive and ends with ENDP directive PROC directive is followed by the type of procedure: NEAR or FAR CALL instruction links to the procedure RET instruction returns from the procedure

BITS Pilani, Pilani Campus CALL SUMS _____ SUMS PROC NEAR ADD AX, BX ADD AX, CX ADD AX, DX RET SUMS ENDP

BITS Pilani, Pilani Campus.Model Tiny.data res db100 dup(0) stack dw100 dup(?) ; get aside 100 words for stack top_stack label word ; give name to next location after last word in stack.code.startup lea sp, top_stack ; initialize stack pointer leadi, res movcx,100 x1:inal, 05 h callmask call delay loopx1.exit

BITS Pilani, Pilani Campus call – 19 ret – 16 Overhead = CO = No. of cycles/loop CL = = 23 No. of times the loop runs = N CT = C0 + N*CL – = 39 + N*23 –12  N = 217 Maskprocnear andal,0f h stosb ret Maskendp Delayprocnear movcx,217 x2: nop nop loop x2 ret Delayendp end