Assembly Language Addressing Modes. Introduction CISC processors usually supports more addressing modes than RISC processors. –RISC processors use the.

Slides:



Advertisements
Similar presentations
Chapter 2 (cont.) An Introduction to the 80x86 Microprocessor Family Objectives: The different addressing modes and instruction types available The usefulness.
Advertisements

There are two types of addressing schemes:
Lect 3: Instruction Set and Addressing Modes. 386 Instruction Set (3.4) –Basic Instruction Set : 8086/8088 instruction set –Extended Instruction Set :
Lecture 6 Machine Code: How the CPU is programmed.
Chapter 1 Background System Software Chih-Shun Hsu
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
PC hardware and x86 3/3/08 Frans Kaashoek MIT
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
1 Lecture 5: Procedures Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
CS2422 Assembly Language & System Programming November 28, 2006.
Accessing parameters from the stack and calling functions.
Assembly Language for Intel-Based Computers Chapter 2: IA-32 Processor Architecture Kip Irvine.
ICS312 Set 3 Pentium Registers. Intel 8086 Family of Microprocessors All of the Intel chips from the 8086 to the latest pentium, have similar architectures.
Microprocessor Systems Design I
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Spring 2014 Lecture 4: x86 memory.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Stack Operations Runtime Stack PUSH Operation POP.
Assembly Language Procedures and the Stack. Stack A stack is a last-in–first-out (LIFO) data structure. Insert and delete operations are referred to as.
Lect 4: Instruction Set and Addressing Modes. 386 Instruction Set (3.4)  Basic Instruction Set : 8086/8088 instruction set  Extended Instruction Set.
Addressing Modes Chapter 11 S. Dandamudi To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S.
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
Procedures and the Stack Chapter 5 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
6.828: PC hardware and x86 Frans Kaashoek
CDP ECE Spring 2000 ECE 291 Spring 2000 Lecture 7: More on Addressing Modes, Structures, and Stack Constantine D. Polychronopoulos Professor, ECE.
Dr. José M. Reyes Álamo 1.  The 80x86 memory addressing modes provide flexible access to memory, allowing you to easily access ◦ Variables ◦ Arrays ◦
1 IA-32
CSC 221 Computer Organization and Assembly Language
Low Level Programming Lecturer: Duncan Smeed Overview of IA-32 Part 1.
INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Today’s topics Procedures Procedures Passing values to/from procedures Passing values to/from procedures Saving registers Saving registers Documenting.
1 ICS 51 Introductory Computer Organization Fall 2009.
Sahar Mosleh California State University San MarcosPage 1 Stack operations, Applications and defining procedures.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
26-Nov-15 (1) CSC Computer Organization Lecture 6: Pentium IA-32.
Addressing Modes Chapter 6 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
In1211/04-PDS 1 TU-Delft IA-32. In1211/04-PDS 2 TU-Delft IA family l IA (Intel Architecture) is a family of processors (1985), (1989), -Pentium-line.
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.
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2013/2014.
Compiler Construction Code Generation Activation Records
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
Chapter 2 The Microprocessor Architecture Microprocessors prepared by Dr. Mohamed A. Shohla.
Assembly 08 Interrupts. Introduction Interrupts are similar to procedures –They are used to alter a program’s control flow –The interrupt service is also.
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2014/2015.
MOV Instruction MOV destination,source  MOV AX,BX  MOV SUM,EAX  MOV EDX,ARRAY[EBX][ESI]  MOV CL,5  MOV DL,[BX]
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.
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures.
CSC 221 Computer Organization and Assembly Language Lecture 16: Procedures.
Calling Procedures C calling conventions. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Assembly Language Data Movement Instructions. MOV Instruction Move source operand to destination mov destination, source The source and destination are.
CSC 221 Computer Organization and Assembly Language Lecture 15: STACK Related Instructions.
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.
The Microprocessor & Its Architecture A Course in Microprocessor Electrical Engineering Department Universitas 17 Agustus 1945 Jakarta.
Addressing Modes Dr. Hadi Hassan.  Two Basic Questions  Where are the operands?  How memory addresses are computed?  Intel IA-32 supports 3 fundamental.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
Stack Operations Dr. Hadi AL Saadi.
Assembly language.
Segment Definition The CPU has several segment registers:
Aaron Miller David Cohen Spring 2011
Chapter 4 Data Movement Instructions
Basic Microprocessor Architecture
Assembly IA-32.
Computer Architecture adapted by Jason Fritts then by David Ferry
Data Addressing Modes • MOV AX,BX; This instruction transfers the word contents of the source-register(BX) into the destination register(AX). • The source.
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures
CS 301 Fall 2002 Computer Organization
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
Computer Architecture CST 250
Other Processors Having learnt MIPS, we can learn other major processors. Not going to be able to cover everything; will pick on the interesting aspects.
Computer Architecture and System Programming Laboratory
Presentation transcript:

Assembly Language Addressing Modes

Introduction CISC processors usually supports more addressing modes than RISC processors. –RISC processors use the load/store architecture. –Operands are usually stored the processor’s registers. The Pentium processors support the following addressing modes –Register Addressing Mode The input operands and results are stored back in registers. Since –Immediate Addressing Mode: The operand value is encoded as part of the instruction. The operand is available as soon as the instruction is read. –Memory Addressing Modes: The operand is in memory and access via several modes. The logical address is specified to determine the location of a memory operand. Memory addressing modes differ in how they specify the effective address.

Addressing Modes 16 bit addressing modes

Addressing Modes 32 bit addressing modes

Memory Addressing Modes Different addressing modes can efficiently support high-level language constructs and data structures. The memory addressing modes depend on the address size Segment + Base + (Index * Scale) + displacement CS EAX EAX 1 No displacement SS EBX EBX 2 8-bit displacement DS ECX ECX 4 32-bit displacement ES EDX EDX 8 FS ESI ESI GS EDI EDI EBP ESP

16 and 32 bit Addressing Modes In a code segment, the D bit and specifies the default size for operands and offsets. –D = 0 the operands and offsets are 16 bits; otherwise they are 32-bit. D bit in the CS segment descriptor to determine if the address is 16 or 32 bits long It is also possible to override these defaults.

Based Addressing One of the registers is used as the base register in computing the effective address of an operand. The effective address is computed by –Adding the contents of the base register with –A signed displacement value given as part of the instruction. For 16-bit addresses –The signed displacement is either an 8- or a 16-bit number. For 32-bit addresses, –The signed displacement is either an 8- or a 32-bit number. Based addressing –Is convenient to access individual elements of a structure. –It useful for accessing arrays whose element size is not 2, 4, or 8 bytes.

Example

Indexed Addressing The effective address is computed as (Index * scale factor) + signed displacement. Scaling factor –no scaling factor is allowed for 16-bit addresses –2, 4, or 8 can be specified for 32-bit adrresses. Example: add EAX,[EDI+20] mov EAX,[marks_table+ESI*4] add EAX,[table1+ESI]

Based-Indexed Addressing Based-Indexed with No Scale Factor Base + Index + signed displacement. The displacement can be –A signed 8- or 16-bit number for 16-bit addresses –An 8- or 32-bit number for 32-bit addresses. Ex. EBX points to table1, which consists of four-byte elements mov EAX,[EBX+ESI] cmp EAX,[EBX+ESI+4] Based-Indexed with Scale Factor Base + (Index * scale factor) + signed displacement. Provides an efficient indexing mechanism into a 2D array –When the element size is 2, 4, or 8 bytes.

Code Example Sorting an integer array using the insertion sort. %include "io.mac".DATA MAX_SIZE EQU 100 input_prompt db "Please enter input array: " db "(negative number terminates input)",0 out_msg db "The sorted array is:",0.UDATA array resd MAX_SIZE.CODE.STARTUP PutStr input_prompt ; request input array mov EBX, array mov ECX, MAX_SIZE array_loop: GetLInt EAX ; read an array number cmp EAX, 0 ; negative number? jl exit_loop ; if so, stop reading numbers mov [EBX], EAX ; otherwise, copy into array add EBX,4 ; increment array address loop array_loop ; iterates a maximum of MAX_SIZE exit_loop:

Code Example Sorting an integer array using the insertion sort. mov EDX, EBX ; EDX keeps the actual array size sub EDX, array ; EDX = array size in bytes shr EDX, 2 ; divide by 4 to get array size push EDX ; push array size & array pointer push array call insertion_sort PutStr out_msg ; display sorted array newline mov ECX, EDX mov EBX, array display_loop: PutLInt [EBX] newline add EBX,4 loop display_loop done:.EXIT

Code Example Sorting an integer array using the insertion sort. ; This procedure receives a pointer to an array of integers and the array size ; via the stack. The array is sorted by using insertion sort. %define SORT_ARRAY EBX insertion_sort: pushad ; save registers mov EBP, ESP mov EBX, [EBP+36] ; copy array pointer mov ECX,[EBP+40] ; copy array size mov ESI, 4 ; array left of ESI is sorted for_loop: mov EDX,[SORT_ARRAY+ESI] ; temp = array[i] mov EDI, ESI ; j = i-1 sub EDI, 4 while_loop: cmp EDX, [SORT_ARRAY+EDI] ; temp < array[j] jge exit_while_loop ; array[j+1] = array[j] mov EAX,[SORT_ARRAY+EDI] mov [SORT_ARRAY+EDI+4],EAX sub EDI,4 ; j = j-1 cmp EDI,0 ; j >= 0 jge while_loop

Code Example Sorting an integer array using the insertion sort. exit_while_loop: ; array[j+1] = temp mov [SORT_ARRAY+EDI+4],EDX add ESI,4 ; i = i+1 dec ECX cmp ECX,1 ; if ECX = 1, we are done jne for_loop sort_done: popad ; restore registers ret 8

Arrays One dimensional arrays –displacement = subscript * element size in bytes. Example: test_marks[5] uses displacement 5 * 4 = 20

Arrays Multidimensional arrays –Row-major ordering row-by-row, starts with the first row –Column major ordering column-by-column, starts with the first column. Displacement displacement = (i * COLS + j) * ELEM_SIZE array[3,1] is at displacement (3*3+1)*4=40. array