BITS Pilani Pilani Campus Pawan Sharma Lecture 29-32 09/12/14-03-2012 EEE /INSTR/CS F241 ES C263 Microprocessor Programming and Interfacing.

Slides:



Advertisements
Similar presentations
Instruction Set of 8086 Engr. M.Zakir Shaikh
Advertisements

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.
There are two types of addressing schemes:
More about procedures and Video Processing. Lesson plan Review existing concepts More about procedures and boolean expression Video processing.
Video systems (continue). Practice Modify the program to get a string from a keyboard to display the input string on the middle of the screen with reverse.
Data Movement Instructions
8086 Assembly Language Programming I
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.
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 4 Data Movement Instructions by.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
Factorial of a number data segment x1 db 4 fact dw ? data ends
Micro-Computer Applications: Procedures & Interrupts Dr. Eng. Amr T. Abdel-Hamid ELECT 707 Fall 2011.
An Introduction to 8086 Microprocessor.
CDP ECE Spring 2000 ECE 291 Spring 2000 Lecture 7: More on Addressing Modes, Structures, and Stack Constantine D. Polychronopoulos Professor, ECE.
Stack Operations LIFO structure (last-in,first-out) –The last value put into the stack is the first value taken out Runtime stack –A memory array that.
Types of Registers (8086 Microprocessor Based)
Implementing function/ procedure calls (in Pascal and C)
Objective At the conclusion of this chapter you will be able to:
Strings, Procedures and Macros
Module R3 Process Scheduling. Module R3 involves the creation of a simple “Round Robin” dispatcher. The successful completion of this module will require.
Writing and using procedures
Click to add Title Comunicación y Gerencia Click To add Subtitle Click to add Text Fundamentals of Assembly Language.
Lecture 9 (The Stack and Procedures). 1 Lecture Outline Introduction The Stack The PUSH Instruction The POP Instruction Terminology of Procedures INDEC.
Review of Assembly language. Recalling main concepts.
Multi-module programming. Requirements of an assembly language module when it is linked with another module PUBLIC directive - it exports to other modules.
University of Sargodha, Lahore Campus Prepared by Ali Saeed.
Assembly Language Data Movement Instructions. MOV Instruction Move source operand to destination mov destination, source The source and destination are.
Internal Programming Architecture or Model
MICROPROCESSOR, PROGRAMMING & INTERFACING Tutorial 4 – Module 4.
BITS Pilani Pilani Campus Pawan Sharma Lecture 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.
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
I NTEL 8086 M icroprocessor بسم الله الرحمن الرحيم 1.
Assembly language programming
Instruction set Architecture
Format of Assembly language
Chapter Nov-2010
8086 Microprocessor.
COURSE OUTCOMES OF MICROPROCESSOR AND PROGRAMMING
Additional Assembly Programming Concepts
Instruksi Set Prosesor 8088
Microprocessor and Assembly Language
Microprocessor and Assembly Language
Chapter 4 Data Movement Instructions
EE3541 Introduction to Microprocessors
INSTRUCTION SET.
Machine control instruction
Assembly Language Programming Part 2
(The Stack and Procedures)
Defining Types of data expression Dn [name] expression Dn [name]
Symbolic Instruction and Addressing
Chapter 4 Data Movement Instructions
8086 Registers Module M14.2 Sections 9.2, 10.1.
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
UNIT-I An Over View Of 8085 Architecture Of 8086 Microprocessor
(The Stack and Procedures)
Symbolic Instruction and Addressing
Chapter 6 - Procedures and Macros
Lecture 06 Programming language.
Chapter 6 –Symbolic Instruction and Addressing
Process.
CNET 315 Microprocessor & Assembly Language
(The Stack and Procedures)
Intel 8086.
Procedures & Macros Introduction Syntax Difference.
Procedures and Macros.
Presentation transcript:

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

BITS Pilani, Pilani Campus  Program Models  LOOP instructions  Signed multiplication and division  In/OUT instr  PUSH/POP  CALL instruction Last Lecture

BITS Pilani, Pilani Campus  Instruction Timing and Delay Loops  Procedures  Passing parameters to procedures Today’s Lecture

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 array db100 dup(0) stack dw100 dup(?) ; get aside 100 words for stack.code.startup leadi, array 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

BITS Pilani, Pilani Campus Passing Parameters to Procedures  Parameters are data values or addresses passed back and forth between the mainline program and the procedure  Four ways to pass parameters  In Registers  In Dedicated memory locations accessed by name  With pointers passed in registers  With stack

BITS Pilani, Pilani Campus CALL SUMS _____ SUMS PROC NEAR PUSHBX PUSHCX PUSHDX ADD BX, AX ADD CX, BX ADDDX,CX ADD AX, DX POPDX POPCX POPBX RET SUMS ENDP Save the contents of the registers on the stack which are used by procedure and at the end, retrieve the saved values. -- good practice to push the flags and any registers used in a procedure, directly in the procedure

BITS Pilani, Pilani Campus ;Initialize segment registers DATASEGMENT BCD_INPUTDB 16h BIN_VALUEDB ? DATA ENDS STACK_SEG SEGMENT DW 100 DUP(0) STACK_SEG ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX MOV AX,STACK_SEG MOV SS,AX MOV AL,BCD_INPUT CALL BCD_BIN MOV BIN_VALUE, AL BCD to Binary conversion (using parameter (data) in register) The BCD number is copied from memory to the AL and then passed to the procedure in the AL register. Conversion example: Packed BCD – Decimal - 16 Bin/hex -10 h (01 * 0a h ) + 6

BITS Pilani, Pilani Campus EX: BCD to Binary Conversion BCD_BIN PROC NEAR PUSHF PUSH BX PUSH CX MOV BL, AL AND BL, 0F H AND AL, F0 H MOV CL, 04 ROR AL, CL MOV BH, 0A H MUL BH ADD AL, BL POP CX POP BX POPF RET BCD_BIN ENDP Parameter stored in register Not pushing the AX register on stack as we use it to pass a value to the procedure and expect the procedure to pass a different value back to the program Disadvantage: no of registers limit the no of parameters that can be passed to procedures.

BITS Pilani, Pilani Campus In the preceding example, why didn’t we simply access the BCD_INPUT and BIN_VALUE by name from the procedure? Passing parameters stored in general memory ;same data structure and initialization as in the previous example CALL BCD_BIN BCD_BIN PROC NEAR PUSHF PUSH AX PUSH BX PUSH CX MOV AL, BCD_INPUT MOV BL, AL AND BL, 0F H AND AL, 0F0 H MOV CL, 04 ROR AL, CL MOV BH, 0A H MUL BH ADD AL, BL MOVBIN_VALUE, AL POP CX POP BX POPAX POPF RET BCD_BIN ENDP

BITS Pilani, Pilani Campus  Can be done but with severe limitation!!  Procedure will always look for the named memory location BCD_INPUT to get its data and will always put the result in BIN_VALUE.  Or, we cant use this procedure to convert the BCD no stored somewhere else in memory.

BITS Pilani, Pilani Campus Passing parameters using pointers EX: BCD to Binary Conversion BCD_BIN PROC NEAR PUSHF PUSH AX PUSH BX PUSH CX MOV AL, [SI] MOV BL, AL AND BL, 0F H AND AL, 0F0 H MOV CL, 04 ROR AL, CL MOV BH, 0A H MUL BH ADD AL, BL MOV[DI], AL POP CX POP BX POPAX POPF RET BCD_BIN ENDP More versatile than using named memory location as the procedure pointers can point to data anywhere in memory. Set up SI and DI acting as pointers. MOV SI, OFFSET BCD_INPUT MOV DI, OFFSET BIN_VALUE CALL BCD_BIN

BITS Pilani, Pilani Campus  Push parameters on stack in mainline program before calling the procedure  Instructions in procedure read these parameters from stack as needed.  Parameters passed back from procedure are written on stack and read by the main-line program. Passing parameters using stack

BITS Pilani, Pilani Campus.model tiny.data bcd_input db 16h bin_value db (0).code.startup MOV AL,BCD_INPUT PUSH AX CALL BCD_BIN POP AX MOV BIN_VALUE, AL ;EX: BCD to Binary Conversion BCD_BIN PROC NEAR PUSHF PUSH AX PUSH BX PUSH CX PUSH BP MOV BP, SP MOV AX, [BP + 12] MOV BL, AL AND BL, 0F H AND AL, 0F0 H MOV CL, 04 ROR AL, CL MOV BH, 0A H MUL BH ADD AL, BL MOV[BP + 12], AX POP BP POP CX POP BX POPAX POPF RET BCD_BIN ENDP.exit end

BITS Pilani, Pilani Campus MOV AL, BCDINPUT CALL BCD_BIN Using reg BCD_BIN PROC NEAR MOV AL, BCDINPUT Using Mem MOV SI, OFFSET BCDINPUT CALL BCD_BIN BCD_BIN PROC NEAR MOV AL, [SI] Using Pointers

BITS Pilani, Pilani Campus Advantage: reduces the code length for repetitive usage of a group of instructions – Machine code generated only once Disadvantage: need stack and overhead time – NOT SUITABLE if repetitive instructions are short Solution: use MACROS Advantages & Disadvantages

BITS Pilani, Pilani Campus  A macro is a group of instructions that perform a task, just as procedure performs one task.  The difference is that the procedure is accessed via a CALL instruction, whereas a macro and all the instructions defined in the macro are inserted in the program at the point of usage.  Name of macro and any parameters associated with it are typed, and the assembler then inserts them into the program.  Macro is faster than procedure because there is no CALL and RET.  MACRO and ENDM are the keywords MACROS

BITS Pilani, Pilani Campus MOVE MACRO A, B PUSH AX MOV AX, B MOV A, AX POP AX ENDM MOVE VAR1, VAR2 ; use the MOVE macro PUSH AX MOV AX, VAR2 MOV VAR1, AX POP AX MOVE VAR3, VAR4 PUSH AX MOV AX, VAR4 MOV VAR3, AX POP AX

BITS Pilani, Pilani Campus Important to note that machine code is generated for every MACRO call Coding is easier but code length increases MACRO sequences must always be defined before they are used in the program, so they appear at the top of the segment.

BITS Pilani, Pilani Campus Ex: Block Move MOVE_ASCII MACRO NUMBER, SOURCE, DESTINATION MOV CX, NUMBER LEA SI, SOURCE LEA DI, DESTINATION CLD REP MOVSB ENDM

BITS Pilani, Pilani Campus MOVE_ASCII 003DH, BLOCK_START, BLOCK_DEST Results in: MOV CX, 003DH LEA SI, BLOCK_START LEA DI, BLOCK_DEST CLD REP MOVSB

BITS Pilani, Pilani Campus SAHF Store AH to Flag Register (Lower) LAHF Load Flag into AH Register (Lower) CMC Complement Carry Flag STI CLI

BITS Pilani, Pilani Campus LES REGISTER, MEMORY ADDRESS OF FIRST WORD  Put new values into the specified register and ES register from four successive memory locations.  LES BX, [7890H]  Loads BX with a word taken from DS at 7890H and 7891H  Loads ES register with a word taken from DS at 7892H and 7893H  LES DI, [BX]  Used to point DI and ES at start of string before a string inst is executed.

BITS Pilani, Pilani Campus LDS REGISTER, MEMORY ADDRESS OF FIRST WORD Same as LES but uses DS register in place of ES register LDS BX, [4325H] Loads BX with a word taken from DS at 4325H and 4326H Loads DS register with a word taken from DS at 4327H and 4328H

BITS Pilani, Pilani Campus XCHG Destination, Source  Exchange the contents of a reg with another reg  Exchange the contents of a reg with Memory location  Source & destination both must be of type word/bytes  Cannot directly exchange the contents of two memory locations.  Segment registers can not be used. XCHG AX, DX XCHG BL, CH XCHG AL, PRICES [BX]

BITS Pilani, Pilani Campus HLT  Stops execution of s/w  Stop fetching and executing instructions. Processor can come out of halt by  Interrupt  Reset  DMA request

BITS Pilani, Pilani Campus Interrupt Program Execution– INT type The term type refers to a number between 0 and 255 (00H to FFH), which identifies the interrupt. INT 21H - DOS INTERRUPT INT 10H – BIOS INTERRUPT INT nn instruction

BITS Pilani, Pilani Campus