CSC 221 Computer Organization and Assembly Language Lecture 12: Addressing Modes in Assembly.

Slides:



Advertisements
Similar presentations
Introduction to Assembly Language
Advertisements

CSC 221 Computer Organization and Assembly Language Lecture 21: Conditional and Block Structures: Assembly Programs.
Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
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.
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.
Assembly Language for Intel-Based Computers, 5th Edition
1 Lecture 4: Data Transfer, Addressing, and Arithmetic Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 4: Data Transfers, Addressing, and Arithmetic (c) Pearson Education, All rights.
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Intrinsic Data Types (1 of 2) BYTE, SBYTE 8-bit unsigned.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 4: Data Transfers, Addressing, and Arithmetic (c) Pearson Education, All rights.
CS2422 Assembly Language & System Programming October 3, 2006.
Assembly Language for Intel-Based Computers Chapter 3: Assembly Language Fundamentals Kip Irvine.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 4: Data Transfers, Addressing, and Arithmetic (c) Pearson Education, All rights.
Outline Data Transfer Instructions Arithmetic Instructions Data-Related Operations and Directives Indirect Addressing JMP and LOOP Instructions.
Data Transfers, Addressing, and Arithmetic
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 4: Data Transfers, Addressing, and Arithmetic (c) Pearson Education, All rights.
Chapter 4: Data Transfers, Addressing, and Arithmetic.
CSC 221 Computer Organization and Assembly Language
Sahar Mosleh California State University San MarcosPage 1 JMP and Loops Memory Operand Move Instruction Array Data Related Operation and Directives.
Intel x86 Assembly Fundamentals Computer Organization and Assembly Languages Yung-Yu Chuang with slides by Kip Irvine.
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.
Today’s topics Parameter passing on the system stack Parameter passing on the system stack Register indirect and base-indexed addressing modes Register.
Assembly Language for x86 Processors 6th Edition Chapter 4: Data-Related Operators and Directives, Addressing Modes (c) Pearson Education, All rights.
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 8: Advanced Procedures (c) Pearson Education, All rights reserved. You may.
Assembly Language for Intel-Based Computers Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify and copy.
Assembly Language for x86 Processors 7th Edition Chapter 13: High-Level Language Interface (c) Pearson Education, All rights reserved. You may modify.
CSC 221 Computer Organization and Assembly Language
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 4: Data Transfers, Addressing, and Arithmetic Lecture 15: ADD, SUB, NEG and how they.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 4: Data Transfers, Addressing, and Arithmetic (c) Pearson Education, All rights.
Addressing Modes Chapter 6 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
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.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 10: Structures and Macros (c) Pearson Education, All rights reserved. You.
Overview of Assembly Language Chapter 4 S. Dandamudi.
Assembly Language for x86 Processors 6th Edition
Assembly Language for Intel-Based Computers Chapter 4: Data Transfers, Addressing, and Arithmetic Kip Irvine.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures Lecture 19: Procedures Procedure’s parameters (c) Pearson Education, 2002.
Fall 2012 Chapter 4: Data Transfers, Addressing, and Arithmetic.
Assembly Language for x86 Processors 7th Edition
CSC 221 Computer Organization and Assembly Language Lecture 16: Procedures.
CSC 221 Computer Organization and Assembly Language Lecture 11: Addressing Modes in Assembly.
CSC 221 Computer Organization and Assembly Language Lecture 15: STACK Related Instructions.
CSC 221 Computer Organization and Assembly Language Lecture 20: Conditional and Block Structures.
Assembly Language for Intel-Based Computers, 4 th Edition Lecture 22: Conditional Loops (c) Pearson Education, All rights reserved. You may modify.
Addressing Modes Dr. Hadi Hassan.  Two Basic Questions  Where are the operands?  How memory addresses are computed?  Intel IA-32 supports 3 fundamental.
1 Using the Assembler Chapter – 4(A). 2 Exchanging Two Variables title Exchange Two Variables (Exchange.asm).model small.stack 100h.data value1 db 0Ah.
CSC 221 Computer Organization and Assembly Language
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers, 5th Edition
Assembly Lab 3.
Assembly Language for Intel-Based Computers, 5th Edition
Assembly Language for x86 Processors 7th Edition
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for x86 Processors 6th Edition
Assembly Language for x86 Processors 6th Edition
Assembly Language for Intel-Based Computers, 5th Edition
Data-Related Operators and Directives
Data Transfer, Addressing and Arithmetic
Stack Frames and Advanced Procedures
(Array and Addressing Modes)
(Array and Addressing Modes)
Basic Instructions.
Assembly Language for Intel-Based Computers, 5th Edition
Data Transfers, Addressing, and Arithmetic
Intel x86 Assembly Fundamentals
Data Transfer, Addressing and Arithmetic
Assembly Language for Intel-Based Computers, 5th Edition
(Array and Addressing Modes)
Presentation transcript:

CSC 221 Computer Organization and Assembly Language Lecture 12: Addressing Modes in Assembly

Lecture 11: Review OFFSET Operator –OFFSET returns the distance in bytes, of a label from the beginning of its enclosing segment PTR Operator –Overrides the default type of a label (variable). Provides the flexibility to access part of a variable. mov esi,OFFSET bVal ;ESI = data array BYTE 100 DUP(?).code mov esi,OFFSET array ; ESI is p Data-Related Operators and Directives.data myBytes BYTE 12h,34h,56h,78h.code mov ax,WORD PTR [myBytes] mov ax,WORD PTR [myBytes+2] mov eax,DWORD PTR myBytes

Lecture 11: Review TYPE Operator –The TYPE operator returns the size, in bytes, of a single element of a data declaration. LENGTHOF Operator –The LENGTHOF operator counts the number of elements in a single data declaration. Data-Related Operators and Directives.data var1 BYTE ? var4 QWORD ?.code mov eax,TYPE var1 ; 1 mov eax,TYPE var4 ; 8.data array1 WORD 30 DUP(?),0,0.code mov ecx,LENGTHOF array1 ;32 (cont.)

Lecture 11: Review SIZEOF Operator –The SIZEOF operator returns a value that is equivalent to multiplying LENGTHOF by TYPE. LABEL Directive –Assigns an alternate label name and type to an existing storage location –LABEL does not allocate any storage of its own –Removes the need for the PTR operator Data-Related Operators and Directives.data array1 WORD 30 DUP(?),0,0.code mov ecx,SIZEOF array1 ;64.data dwList LABEL DWORD wordList LABEL WORD intList BYTE 00h,10h,00h,20h.code mov eax,dwList ; h mov cx,wordList ; 1000h mov dl,intList ; 00h (cont.)

Lecture 11: Review Indirect Operands Indirect Addressing in Assembly.data val1 BYTE 10h,20h,30h.code mov esi,OFFSET val1 mov al,[esi]; deref. ESI inc esi mov al,[esi]; AL = 20h inc esi mov al,[esi]; AL = 30h.data myCount WORD 0.code mov esi,OFFSET myCount inc [esi]; error: ambiguous inc WORD PTR [esi]; ok (cont.)

Lecture 11: Review Index Operands –An indexed operand adds a constant to a register to generate an effective address. There are two notational forms: [label + reg]label[reg] Indirect Addressing in Assembly.data arrayW WORD 1000h,2000h,3000h.code mov esi,0 mov ax,[arrayW + esi] ; AX = 1000h mov ax,arrayW[esi]; alternate format add esi,2 add ax,[arrayW + esi] ……… (cont.)

Lecture 11: Review Index Scaling –You can scale an indirect or indexed operand to the offset of an array element. This is done by multiplying the index by the array's TYPE: Indirect Addressing in Assembly (cont.).data arrayB BYTE 0,1,2,3,4,5 arrayW WORD 0,1,2,3,4,5.code mov esi,4 mov al,arrayB[esi*TYPE arrayB]; 04 mov bx,arrayW[esi*TYPE arrayW]; 0004 ………

Lecture 11: Review Indirect Addressing in Assembly –Indirect Operands –Array Sum Example –Indexed Operands –Pointers Index Scaling (cont.)

Assembly Examples Let’s Enjoy Assembly

Programming Examples: Data-Related Operators and Directives OFFSET Operator PTR Operator TYPE Operator LENGTHOF Operator SIZEOF Operator LABEL Directive Summary

Programming Examples: Indirect Addressing Indirect Operands Array Sum Example Indexed Operands Pointers (cont.) Summary

Reference Most of the Slides are taken from Presentation: Chapter 4 Assembly Language for Intel-Based Computers, 4 th Edition Kip R. Irvine (c) Pearson Education, All rights reserved. You may modify and copy this slide show for your personal use, or for use in the classroom, as long as this copyright statement, the author's name, and the title are not changed.