Microprocessor and Assembly Language

Slides:



Advertisements
Similar presentations
Lecture By SHERY KHAN Assembly Language Lecture By SHERY KHAN
Advertisements

There are two types of addressing schemes:
Microprocessor Fundamentals Week 5 Mount Druitt College of TAFE Dept. Electrical Engineering 2008.
Addressing modes The way in which an operand is specified is called the Address Mode.
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.
Department of Computer Science and Software Engineering
Irvine, Kip R. Assembly Language For Intel-Based Computers TYPE and SIZE Operators TYPE –returns the size, in bytes of a single element of a data label.
Addressing modes – 1 The way in which an operand is specified is called the Address Mode.
The 8086 Assembly Programming Data Allocation & Addressing Modes
Microcomputer & Interfacing Lecture 3
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
Addressing Modes Chapter 11 S. Dandamudi To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S.
CDP ECE Spring 2000 ECE 291 Spring 2000 Lecture 7: More on Addressing Modes, Structures, and Stack Constantine D. Polychronopoulos Professor, ECE.
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.
MOHD. YAMANI IDRIS/ NOORZAILY MOHAMED NOOR1 Addressing Mode.
INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 4 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
4-Oct Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  direct mode: OK for static addresses  indirect register mode:
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.
Review of Assembly language. Recalling main concepts.
Addressing Modes. Addressing Mode The data is referred as operand. The operands may be contained in registers, memory or I/O ports, within the instruction.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
Addressing Modes Dr. Hadi Hassan.  Two Basic Questions  Where are the operands?  How memory addresses are computed?  Intel IA-32 supports 3 fundamental.
I NTEL 8086 M icroprocessor بسم الله الرحمن الرحيم 1.
Addressing Modes Instruction – Op-code – Operand Addressing mode indicates a way of locating data or operands. – Any instruction may belong to one or more.
Assembly language programming
Instruction set Architecture
Format of Assembly language
Presentation on Real Mode Memory Addressing
Data Transfers, Addressing, and Arithmetic
Microprocessor Systems Design I
COURSE OUTCOMES OF MICROPROCESSOR AND PROGRAMMING
16.317: Microprocessor System Design I
Additional Assembly Programming Concepts
ADDRESSING MODES.
16.317: Microprocessor System Design I
Microprocessor and Assembly Language
Microprocessor and Assembly Language
Microprocessor and Assembly Language
ADDRESSING MODES.
University of Gujrat Department of Computer Science
Microprocessor and Assembly Language
Computer Organization & Assembly Language
(The Stack and Procedures)
Assembly Lang. – Intel 8086 Addressing modes – 1
Chapter 3 Addressing Modes
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Arithmetic Instructions
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.
8086 Registers Module M14.2 Sections 9.2, 10.1.
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
(Array and Addressing Modes)
(The Stack and Procedures)
Chapter 4 –Requirements for coding in Assembly Language
Symbolic Instruction and Addressing
(Array and Addressing Modes)
CNET 315 Microprocessor & Assembly Language
Lecture 06 Programming language.
University of Gujrat Department of Computer Science
Microprocessor and Assembly Language
Chapter 6 –Symbolic Instruction and Addressing
(The Stack and Procedures)
Chapter 8: Instruction Set 8086 CPU Architecture
Introduction to 8086 Assembly Language
Part I Data Representation and 8086 Microprocessors
(Array and Addressing Modes)
Presentation transcript:

Microprocessor and Assembly Language Lecture-5-Addressing Modes Muhammad Hafeez Department of Computer Science GC University Lahore

Today’s Agenda Arrays Addressing Modes

Declare An Array DUP Operator Possible to define data, who elements share a common initial value DATA1 DB 100 DUP(0) DATA2 DB 50 DUP(?) DATA3 DB 5,4,3 DUP(2,2 DUP(1),1)

Declare A Byte Array myArray DB 10H,20H,30H,40H Assembly Address can also be written as myArray[0], myArray[1],… Offset Assembly Address Value 0200 myArray 10h 0201 myArray+1 20h 0202 myArray+2 30h 0203 myArray+3 40H

Declare A Word Array myWordArray DW 10H,20H,30H,40H Assembly Address can also be written as myWordArray[0], myWordArray[2],… Offset Assembly Address Value 0200 myWordArray 10h 0202 myWordArray+2 20h 0204 myWordArray+4 30h 0206 myWordArray+6 40H

Location of Array Element A is location of element S is size of a particular element, for Byte S=1 for Word S=2 Position Location 1 A 2 A = 1 x S 3 A = 2 X S 4 A = 3 X S N A = (N-1) X S

Addressing Modes We know nearly every instruction involves one or two operands. We know the operands may be registers, immediate data, or memory operand. Addressing modes describes the various ways through which programmer can access operands. Addressing Mode particularly help in addressing memory location used in Array

Addressing Modes Number of addressing modes is determined when the microprocessor is designed and cannot be changed. Much of CPU power lies on its ability to handle large types of operands. Effective Address of an operand refers to the distance of the data from the beginning of a segment. Addressing modes are associated with types of operands

Addressing Modes The Way an Operand’s Effective Address is specified is called Addressing Modes The Operands can be specified using: Register Addressing Mode Immediate Addressing Mode Direct Addressing Mode Register Indirect Addressing Mode Based Addressing Mode Indexed Addressing Mode Based Indexed Addressing Mode

Register Addressing Mode Transfers a copy of a byte or word from the Source Register to the Destination Register. Example: MOV AX,BX

Direct Addressing Mode Moves a byte or word between a Memory Location and a Register. Instruction set does not support a memory to memory transfer. Example: MOV CX,List Effective Address is generated as: DS * 10H + DISP(LIST) MOV BX, myArray[0] + myArray + Disp

Register In-Direct Addressing Mode The OFFSET of an operand is contained in a register The Register could be BX, SI, DI and BP What is the default segment registers of these offset registers? Format is [register] Suppose BX has value 0100H and this value is the address of a memory location that has content 1234H, then MOV AX, [BX] Will place 1234H in AX

Register In-Direct Addressing Mode Some implementation of Register Indirect Addressing Mode MOV AX,[BX] MOV CX,[SI] MOV [DI],[SI] ADD DX,[DI] Which instruction is illegal?

Example: Add into AX, 10 elements of an array using Register Indirect Addressing Mode MOV AX,0 LEA BX, LIST MOV CX,10 ADDS: ADD AX,[SI] ADD SI,2 LOOP ADDS

Example: Add into AX, 10 elements of an array using Register Indirect Addressing Mode MOV AX,0 LEA BX, LIST MOV CX,10 ADDS: ADD AX,[SI] ADD SI,2 LOOP ADDS

Based Addressing Mode/ Indexed Addressing Mode Operand’s Offset address is obtained by adding a number called displacement into the content of a register Displacement can be: A constant (negative or positive) Offset address of a variable Offset address of a variable plus or minus a constant

Based Addressing Mode/ Indexed Addressing Mode The Syntax can be: [Register + Displacement] [Displacement + Register] Displacement + [Register] [Register] + Displacement Displacement [Register] IF BP, BX is used Addressing Mode is called Based If SI, DI is used Addressing Mode is called Indexed

Example: MOV CX,17 MOV SI,0 TOP: NEXT: INC SI LOOP TOP Replace Lower Case String with upper case letter by letter. MSG DB ‘lower case string’ MOV CX,17 MOV SI,0 TOP: CMP MSG[SI],20H JE NEXT SUB MSG[SI],20H NEXT: INC SI LOOP TOP

PTR Pseudo-Op Operands of the instructions must be of the same size What about a constant moving into Register or Memory ? When you want to store some constant into a memory location pointed by a register such as MOV [SI], 5 It will not be assembled REASON ??

PTR Pseudo-Op The assembler will not know whether to move 5 into Byte of Memory of Word of Memory If you want to move 5 into Byte of Memory then write MOV Byte Ptr [SI],5 If you want to move 5 into Word of memory then write MOV Word Ptr [SI],5

Two Dimensional Array An Array whose elements are one dimensional arrays itself Memory is sequential Two Dimensional arrays are stored sequentially Two Methods: Row Major Order Row0 is stored first, then row1 and so on Column Major Order Column0 is stored first then, then column1 and so on

Row Major Order / Column Major Order Row Major Order: B[0,0],B[0,1],B[0,2],B[1,0],B[1,1],B[1,2],…. Column Major Order: B[0,0],B[1,0],B[2,0],B[0,1],B[1,1],B[2,1],…. Most High Level Languages store data in Row Major Order

Declare Two Dimensional Array in Assembly Row Major Order Array DB 10,20,30 DB 40,50,60 DB 70,80,90 Column Major Order Array DB 10,40,70 DB 20,50,80 DB 30,60,90

Locate an Element in Two Dimensional Array A [i,j] is MxN a 2D array, stored in Row Major Order M is Total Number of rows N is Total Number of columns Where i is row number and j is column Locate, where i begins Find jth Column in that ith row

Locate an Element in Two Dimensional Array Suppose S is the size of element, s=1 for byte array and s=2 for word array Row0 begins at A Row i begins at A+i*N*S where i is the row to find, N is total number of column in 2D array and S is the size of each element jth element is stored at j*S bytes from start from row So, A[i,j] location is A+(i*N+j)*S

Based Indexed Addressing Mode The Effective Address of operand is found at the sum of Contents of Based Register [BX OR BP] Contents of Indexed Register [SI OR DI] Optionally, a variable’s offset address Optionally, a constant (positive or negative)

Based Indexed Addressing Mode There are many valid ways to write Based Indexed Addressing Mode, some of them are [base + index + variable + constant]<-- preferred variable[base + index + constant] constant[base + index + variable]

Example: Based Indexed Addressing Mode Suppose A is a 5x7 word array stored in row-major order. Write code to clear row 2.     MOV   BX,28       ; BX indexes row 2      MOV SI,0       ; SI will index columns      MOV   CX,7   ; # elements in a row clear:    MOV   [BX + SI + A],0  ; clear A[2,j]      ADD   SI,2             ; go to next column      LOOP  clear            ; loop until done

Example: Based Indexed Addressing Mode Another Example: Write code to clear column 3 -- Since A is a 7 column word array we need to add 2*7 = 14 to get to the next row         mov   si,6       ; si indexes column 3          xor   bx,bx      ; bx will index rows          mov   cx,5      ; #elements in a column  clear:          mov   [bx + si + A],0   ; clear A[i,3]          add   bx,14             ; go to next row          loop  clear             ; loop until done

Questions ??????????????????????????