Dr. José M. Reyes Álamo 1.  The 80x86 memory addressing modes provide flexible access to memory, allowing you to easily access ◦ Variables ◦ Arrays ◦

Slides:



Advertisements
Similar presentations
INSTRUCTION SET ARCHITECTURES
Advertisements

There are two types of addressing schemes:
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
The University of Adelaide, School of Computer Science
Computer Organization and Architecture
Chapter 11 Instruction Sets
Lecture 6 Machine Code: How the CPU is programmed.
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
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.
Accessing parameters from the stack and calling functions.
Assembly תרגול 8 פונקציות והתקפת buffer.. Procedures (Functions) A procedure call involves passing both data and control from one part of the code to.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Stack Operations Runtime Stack PUSH Operation POP.
Addressing Modes Chapter 11 S. Dandamudi To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S.
Chapter 7: Runtime Environment –Run time memory organization. We need to use memory to store: –code –static data (global variables) –dynamic data objects.
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
Runtime Environments Compiler Construction Chapter 7.
Today’s topics Parameter passing on the system stack Parameter passing on the system stack Register indirect and base-indexed addressing modes Register.
CSC 221 Computer Organization and Assembly Language
1 C - Memory Simple Types Arrays Pointers Pointer to Pointer Multi-dimensional Arrays Dynamic Memory Allocation.
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 8: Advanced Procedures (c) Pearson Education, All rights reserved. You may.
INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
December 8, 2003Other ISA's1 Other ISAs Next, we discuss some alternative instruction set designs. – Different ways of specifying memory addresses – Different.
Faculty of Engineering, Electrical Department,
Dr. José M. Reyes Álamo 1.  Review: ◦ Statement Labels ◦ Unconditional Jumps ◦ Conditional Jumps.
The x86 Architecture Lecture 15 Fri, Mar 4, 2005.
Execution of an instruction
CET 3510 Microcomputer Systems Tech. Lecture 2 Professor: Dr. José M. Reyes Álamo.
Sahar Mosleh California State University San MarcosPage 1 Stack operations, Applications and defining procedures.
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-2.ppt Modification date: March 23, Procedures Essential ingredient of high level.
Addressing Modes Chapter 6 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Chapter 11 Instruction Sets: Addressing Modes and Formats Gabriel Baron Sydney Chow.
ΠΟΛΥΤΕΧΝΙΚΗ ΣΧΟΛΗ Τμήμα Ηλεκτρολογών Μηχανικών και Τεχνολογίας Υπολογιστών Μικρουπολογιστές & Μικροσυστήματα ΙΙ Καθηγητής Σταύρος Α. Κουμπιάς Πανεπιστημίου.
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.
The x86 Instruction Set Lecture 16 Mon, Mar 14, 2005.
Chapter 10 Instruction Sets: Characteristics and Functions Felipe Navarro Luis Gomez Collin Brown.
Instruction Sets: Addressing modes and Formats Group #4  Eloy Reyes  Rafael Arevalo  Julio Hernandez  Humood Aljassar Computer Design EEL 4709c Prof:
COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE Lecture 21 & 22 Processor Organization Register Organization Course Instructor: Engr. Aisha Danish.
Compiler Construction Code Generation Activation Records
1 The Stack and Procedures Chapter 5. 2 A Process in Virtual Memory  This is how a process is placed into its virtual addressable space  The code is.
Chapter 2 The Microprocessor Architecture Microprocessors prepared by Dr. Mohamed A. Shohla.
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.
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.
Internal Programming Architecture or Model
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.
Addressing Modes Dr. Hadi Hassan.  Two Basic Questions  Where are the operands?  How memory addresses are computed?  Intel IA-32 supports 3 fundamental.
Chapter 12 Processor Structure and Function. Central Processing Unit CPU architecture, Register organization, Instruction formats and addressing modes(Intel.
Stack Operations Dr. Hadi AL Saadi.
Assembly language.
Instruction set Architecture
William Stallings Computer Organization and Architecture 8th Edition
Chapter 4 Data Movement Instructions
Introduction to Compilers Tim Teitelbaum
Microcomputer Programming
Assembly Lang. – Intel 8086 Addressing modes – 1
BIC 10503: COMPUTER ARCHITECTURE
Stack Frames and Advanced Procedures
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures
Processor Organization and Architecture
MIPS Procedure Calls CSE 378 – Section 3.
Computer Organization and Assembly Language
Computer Operation 6/22/2019.
Computer Architecture and System Programming Laboratory
Presentation transcript:

Dr. José M. Reyes Álamo 1

 The 80x86 memory addressing modes provide flexible access to memory, allowing you to easily access ◦ Variables ◦ Arrays ◦ Records ◦ Pointers ◦ Other complex data types 2

 Most 80x86 instructions can operate on the 80x86’s general purpose register set  Registers are the best place to keep often used variables ◦ Instructions using the registers are shorter and faster than those that access memory  The general addressing modes provided by the 80x86 family are: ◦ displacement-only ◦ base ◦ displacement plus base ◦ base plus indexed ◦ displacement plus base plus indexed 3

 Also known as direct addressing mode  Consists of a 32 bit constant that specifies the address of the target location  On the 80x86 processors, this displacement is an offset from the beginning of memory (address zero)  Examples are in bytes 4

5

6

 The operand is not the actual address, but rather, the operand’s value specifies the memory address to use  The register’s value is the memory location to access  Eight forms of indirect addressing mode: ◦ mov( [eax], al ); ◦ mov( [ebx], al ); ◦ mov( [ecx], al ); ◦ mov( [edx], al ); ◦ mov( [edi], al ); ◦ mov( [esi], al ); ◦ mov( [ebp], al ); ◦ mov( [esp], al ); 7

 Requires a 32-bit register  Have to use the [ ] ◦ Alternatively can use the load effective address (lea) command  In HLA can also use the & operator ◦ mov( &J, ebx );// Load address of J into EBX. ◦ mov( eax, [ebx] );// Store EAX into J.  Uses: ◦ Access data referenced by a pointer, ◦ Step through array data ◦ To modify the address of a variable while your program is running. ◦ To provide anonymous variables (you can read/write to/from it but do not know its name, only the address) 8

 Computes an effective address by adding the address of the specified variable to the value of the 32-bit register appearing inside the square brackets.  This sum is the actual address in memory that the instruction will access.  Syntax: ◦ mov( VarName[ eax ], al ); ◦ mov( VarName[ ebx ], al ); ◦ mov( VarName[ ecx ], al ); ◦ mov( VarName[ edx ], al ); ◦ mov( VarName[ edi ], al ); ◦ mov( VarName[ esi ], al ); ◦ mov( VarName[ ebp ], al ); ◦ mov( VarName[ esp ], al ); 9

10

 Two syntactical variations of the indexed addressing mode  The first variant uses the following syntax: ◦ mov( [ 32BitReg+ constant ], al ); ◦ mov( [32BitReg - constant ], al );  The second variant syntax: ◦ mov( VarName[32BitReg + constant ], al ); ◦ mov( VarName[32BitReg - constant ], al ); 11

12

 Uses: ◦ If a 32-bit register contains the base address of a multi-byte object and you wish to access a memory location some number of bytes before or after that location ◦ Accessing fields of a record (or structure) when you have a pointer to the record data 13

 Similar to the indexed addressing modes with two differences: 1.Allow you to combine two registers plus a displacement 2.Let you multiply the index register by a (scaling) factor of 1, 2, 4, or 8. 14

 Syntax ◦ VarName[ IndexReg32*scale ] ◦ VarName[ IndexReg32*scale + displacement ] ◦ VarName[ IndexReg32*scale - displacement ] ◦ [ BaseReg32 + IndexReg32*scale ] ◦ [ BaseReg32 + IndexReg32*scale + displacement ] ◦ [ BaseReg32 + IndexReg32*scale - displacement ] ◦ VarName[ BaseReg32 + IndexReg32*scale ] ◦ VarName[ BaseReg32 + IndexReg32*scale + displacement ] ◦ VarName[ BaseReg32 + IndexReg32*scale - displacement ] 15

16

 Uses: ◦ To access elements of arrays whose elements are two, four, or eight bytes each. ◦ Useful for accessing elements of an array when you have a pointer to the beginning of the array. 17

 The lowest memory addresses are reserved by the operating system.  Generally, applications are not allowed to access data or execute instructions at the lowest addresses in memory. ◦ “general protection fault” error 18

19

 The code section contains the machine instructions that appear in an HLA program.  HLA translates each machine instruction you write into a sequence of one or more byte values.  The CPU interprets these byte values as machine instructions during program execution.  In theory, you could write a program that stores data values into memory and then transfers control to the data it just wrote, producing a program that writes itself as it executes.  This produces romantic visions of Artificially Intelligent programs that modify themselves  In real life, the effect is usually a disaster and that’s why today’s operating systems operate in protected mode. 20

 Is where you will typically declare your variables.  You can also embed lists of data into the static memory segment. 21

 Holds constants, tables, and other data that your program  All readonly objects declarations must be initialized  Data here can be thought as constants 22

 The storage is used to declare variables that are always uninitialized when the program begins running, as opposed to the readonly section where you initialize all objects you declare, and the static section that lets you optionally initialize objects.  Usually the operating system will initialize all storage objects to zero 23

 Used to create automatic variables  Your program will allocate memory when a unit starts executing (usually a procedure), and will deallocate memory when the unit finishes execution.  These variables are usually located in the stack segment 24

 The stack is a dynamic data structure that grows and shrinks according to certain memory needs of the program.  The stack also stores important information about program including local variables, subroutine information, and temporary data.  The 80x86 controls its stack via the ESP (stack pointer) register.  Data is written to the stack segment by “pushing” data onto the stack and removed by “popping” or “pulling” data off of the stack. 25

 Syntax: ◦ push( reg 16 ); ◦ push( reg 32 ); ◦ push( memory 16 ); ◦ push( memory 32 ); ◦ pushw( constant ); ◦ pushd( constant );  Whenever you push data onto the stack, the 80x86 decrements the stack pointer by the size of the data you are pushing and then it copies the data to memory where ESP is then pointing  The stack pointer should always be an even multiple of four 26

27

 Syntax ◦ pop( reg 16 ); ◦ pop( reg 32 ); ◦ pop( memory 16 ); ◦ pop( memory 32 );  The POP instruction only supports 16-bit and 32- bit operands; you cannot pop an eight-bit value from the stack  You cannot POP a constant value  Popping a value does not erase the value in memory, it just adjusts the stack pointer so that it points at the next value above the popped value 28

29

 Although static and automatic variables are all simple programs may need, more sophisticated programs need the ability to allocate and deallocate storage dynamically (at run-time) under program control  These memory allocation routines let the programmer request how many bytes of storage to allocate, they return a pointer to the newly allocated storage, and they provide a facility for returning the storage to the system so the system can reuse it in a future allocation call  The heap segment of memory is used for those allocations 30

31

 To declare a string the syntax is static stringName:string;  Strings are pointers  First need to go to the address indicated by the pointer and then access the individual characters 32

33

Get the n th character of string s in HLA, where n is an uns32  mov( s, ebx );// Get address of string data into EBX.  mov( n, ecx );// Get desired offset into string.  mov( [ebx+ecx], al );// Get the desired character into AL. Caution: Need to check the index exist, otherwise might get an error Other code samples in the book 34