Assembler Programming. Lecture 2

Similar documents
EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM

The Microprocessor and its Architecture

Basic Execution Environment

Introduction to IA-32. Jo, Heeseung

INTRODUCTION TO IA-32. Jo, Heeseung

Lecture 15 Intel Manual, Vol. 1, Chapter 3. Fri, Mar 6, Hampden-Sydney College. The x86 Architecture. Robb T. Koether. Overview of the x86

Code segment Stack segment

Complex Instruction Set Computer (CISC)

Lecture (02) The Microprocessor and Its Architecture By: Dr. Ahmed ElShafee

The x86 Architecture

Addressing Modes on the x86

EEM336 Microprocessors I. The Microprocessor and Its Architecture

Assembly Language Each statement in an assembly language program consists of four parts or fields.

6/17/2011. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to:

Hardware and Software Architecture. Chapter 2

Chapter 2: The Microprocessor and its Architecture

MODE (mod) FIELD CODES. mod MEMORY MODE: 8-BIT DISPLACEMENT MEMORY MODE: 16- OR 32- BIT DISPLACEMENT REGISTER MODE

The Instruction Set. Chapter 5

Moodle WILLINGDON COLLEGE SANGLI (B. SC.-II) Digital Electronics

Module 3 Instruction Set Architecture (ISA)

We can study computer architectures by starting with the basic building blocks. Adders, decoders, multiplexors, flip-flops, registers,...

UMBC. A register, an immediate or a memory address holding the values on. Stores a symbolic name for the memory location that it represents.

MICROPROCESSOR MICROPROCESSOR ARCHITECTURE. Prof. P. C. Patil UOP S.E.COMP (SEM-II)

SYSC3601 Microprocessor Systems. Unit 2: The Intel 8086 Architecture and Programming Model

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

6/20/2011. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to:

Dr. Ramesh K. Karne Department of Computer and Information Sciences, Towson University, Towson, MD /12/2014 Slide 1

EC-333 Microprocessor and Interfacing Techniques

Intel 8086 MICROPROCESSOR ARCHITECTURE

CMSC Lecture 03. UMBC, CMSC313, Richard Chang

IA32 Intel 32-bit Architecture

UNIT 2 PROCESSORS ORGANIZATION CONT.

Chapter 11. Addressing Modes

Intel 8086 MICROPROCESSOR. By Y V S Murthy

x86 Assembly Tutorial COS 318: Fall 2017

Chapter 3: Addressing Modes

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 2: IA-32 Processor Architecture Included elements of the IA-64 bit

EEM336 Microprocessors I. Addressing Modes

Scott M. Lewandowski CS295-2: Advanced Topics in Debugging September 21, 1998

Lecture 5:8086 Outline: 1. introduction 2. execution unit 3. bus interface unit

Computer Processors. Part 2. Components of a Processor. Execution Unit The ALU. Execution Unit. The Brains of the Box. Processors. Execution Unit (EU)

CHAPTER 3 BASIC EXECUTION ENVIRONMENT

CS 16: Assembly Language Programming for the IBM PC and Compatibles

MICROPROCESSOR MICROPROCESSOR ARCHITECTURE. Prof. P. C. Patil UOP S.E.COMP (SEM-II)

iapx Systems Electronic Computers M

icroprocessor istory of Microprocessor ntel 8086:

MICROPROCESSOR PROGRAMMING AND SYSTEM DESIGN

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 03, SPRING 2013

Machine-level Representation of Programs. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

CC411: Introduction To Microprocessors

BAHAR DÖNEMİ MİKROİŞLEMCİLER LAB3 FÖYÜ

Buffer Overflow Attack

Marking Scheme. Examination Paper Department of CE. Module: Microprocessors (630313)

Faculty of Engineering Computer Engineering Department Islamic University of Gaza Assembly Language Lab # 2 Assembly Language Fundamentals

X86 Addressing Modes Chapter 3" Review: Instructions to Recognize"

IA32/Linux Virtual Memory Architecture

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-11: 80x86 Architecture

The x86 Architecture. ICS312 - Spring 2018 Machine-Level and Systems Programming. Henri Casanova

Advanced Microprocessors

8086 INTERNAL ARCHITECTURE

Unit 08 Advanced Microprocessor

Project 1: Bootloader. COS 318 Fall 2015

9/25/ Software & Hardware Architecture

Assembly Language Lab # 9

EC-333 Microprocessor and Interfacing Techniques

Processor Structure and Function

The Pentium Processor

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017

William Stallings Computer Organization and Architecture 10 th Edition Pearson Education, Inc., Hoboken, NJ. All rights reserved.

SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF ECE EC6504 MICROPROCESSOR AND MICROCONTROLLER (REGULATION 2013)

Microprocessor (COM 9323)

UMBC. contain new IP while 4th and 5th bytes contain CS. CALL BX and CALL [BX] versions also exist. contain displacement added to IP.

Lecture 5: Computer Organization Instruction Execution. Computer Organization Block Diagram. Components. General Purpose Registers.

EEM336 Microprocessors I. Data Movement Instructions

Introduction to Microprocessor

Program controlled semiconductor device (IC) which fetches (from memory), decodes and executes instructions.

Registers. Ray Seyfarth. September 8, Bit Intel Assembly Language c 2011 Ray Seyfarth

Reverse Engineering II: The Basics

Reverse Engineering II: Basics. Gergely Erdélyi Senior Antivirus Researcher

Lab 2: Introduction to Assembly Language Programming

INTRODUCTION TO MICROPROCESSORS

Assembly Language. Dr. Esam Al_Qaralleh CE Department Princess Sumaya University for Technology. Overview of Assembly Language

ADDRESSING MODES. Operands specify the data to be used by an instruction

16.317: Microprocessor Systems Design I Fall 2013

Low Level Programming Lecture 2. International Faculty of Engineerig, Technical University of Łódź

Microprocessor. By Mrs. R.P.Chaudhari Mrs.P.S.Patil

Assembly Language. Lecture 2 - x86 Processor Architecture. Ahmed Sallam

ADVANCE MICROPROCESSOR & INTERFACING

Q1: Multiple choice / 20 Q2: Memory addressing / 40 Q3: Assembly language / 40 TOTAL SCORE / 100

Chapter Three Addressing Mode MOV AX, BX

Assembling, Linking and Executing 1) Assembling: .obj obj .obj.lst .crf Assembler Types: a) One pass assembler:

Microprocessor and Assembly Language Week-5. System Programming, BCS 6th, IBMS (2017)

Instruction Set Architectures

Memory Models. Registers

Chapter 2 COMPUTER SYSTEM HARDWARE

MICROPROCESSOR ALL IN ONE. Prof. P. C. Patil UOP S.E.COMP (SEM-II)

Chapter 4: Data Movement Instructions. 4 1 MOV Revisited

T Reverse Engineering Malware: Static Analysis I

Access. Young W. Lim Fri. Young W. Lim Access Fri 1 / 18

Computer Organization (II) IA-32 Processor Architecture. Pu-Jen Cheng

Transcription:

Assembler Programming Lecture 2

Lecture 2 8086 family architecture. From 8086 to Pentium4. Registers, flags, memory organization. Logical, physical, effective address. Addressing modes.

Processor Processor is the device that manages all actions and services in the system. Processor handles synchronous and asynchronous events. All those actions processor handles executing the programs or the procedures.

8086 family processors evolution 8086 real mode only, 16-bit, 1MB addressing. 80186 real mode only, 16-bit, 1MB. 80286 real and protected mode, 16-bit, 16MB. 80386 real and protected mode, 32-bit, 4GB. i486 real and protected mode, 32-bit, 4GB. Pentium real and protected, 32-bit, 4GB. Pentium Pro real and protected, 32-bit, 64GB. Pentium II real and protected, 32-bit, 64GB. Pentium III real and protected, 32-bit, 64GB. Pentium 4 real and protected, 32-bit, 64GB.

8086 architecture general purpose registers AH AX AL SI BH BX BL DI CH CX CL BP DX DH DL

8086 architecture special purpose registers SP IP Carry Parity Auxiliary Carry Zero Sign Trace Interrupt Direction Overflow Flags OF DF IF TF SF ZF AF PF CF

8086 architecture segment registers CS DS ES SS

Real mode 80386 registers EAX AH AX AL ESI SI EBX BH BX BL EDI DI ECX CH CX CL EBP BP EDX DH DX DL ESP SP

EIP and extended flag register EIP IP I/O Privilege Level Nested Task Resume Flag Virtual Mode Alignment Check Virt. Interrupt Flag Virt. Interrupt Pending Identification EFlags ID VIP VIF AC VM RF NT PL PL OFDF IF TF SF ZF AF PF CF

80386 segment registers CS DS ES FS GS SS

Other registers 80386 has registers for protected mode operation. i486 and above has math coprocessor s registers. Pentium and above has multimedia extension registers for MMX. Pentium4 has another multimedia registers for SSE.

Memory addressing in real mode Memory is organized in segments for 16-bit real mode segments size is 64kB, for 32-bit mode segments size is 4GB. Logical address consists of two values segment address, offset within segment. Logical address is recalculated into linear address which in real mode corresponds to the physical address of the memory.

Real address calculating Segment (16 bit) Shift left 4 bits Segment 0 0 0 0 Fill with four zeros + Offset (16 bit) Add Offset value Linear address (20 bit)

Segmented addressing CS DS SS Code Segment Data Segment Stack Segment ES FS GS Data Segment Data Segment Data Segment

Addressing modes Instructions usually have the operands. the right operand is the source, the left operand is the destination. Operands can be of one of the types: register, immediate, direct memory, indirect memory. In the examples we will use mov instruction.

8086 register addressing mov ax, bx mov dl, al mov si, dx mov sp, bp mov dh, cl mov ax, ax mov ax, cs mov ds, ax

8086 immediate values Immediate value is a constant or result of constant expression. It is calculated during assembling. It is placed in the code as part of the instruction. mov ax, A mov ax, 0 mov bx, 12*7

8086 memory addressing Direct memory addressing (displacement only). Indirect memory addressing. Base addressing. Index addressing. Base addressing with indexing. Base addressing with indexing and displacement.

8086 direct memory addressing Specifies the data at given address mov ax, variable mov ax, [variable] mov si, ES:[variable] mov di, ES:[100]

8086 direct memory addressing BL mov ds:[0800h], bl one byte 0800h mov ax, ds:[0600h] high byte 0601h low byte 0600h AX

Indirect memory addressing Address of the data is held in the base or index register. While BX, SI or DI is used the processor as a default takes DS segment register. While BP is used the processor takes SS segment register. mov ax, [bx] mov ax, [bp] mov al, [di] mov ah, [si]

Indirect memory addressing mov al, [bx] data AL BX + DS

Base memory addressing Address of the beggining of the data table is held in the base register. Displacement inside the table is a constant. All of the following variations are legal: mov ax, element[bx] mov ax, [bx+element] mov ax, [bx]+element

Base memory addressing mov al, [bx]+element data AL element + BX + table beginning DS

Index memory addressing Address of the data table is a constant. Number of the element (byte) is held in the index register. All of the following variations are legal: mov ax, table[si] mov ax, [si+table] mov ax, [si]+table

Index memory addressing mov al, table[di] data AL DI + table + table beginning DS

Base memory addressing with indexing Address of the data table is held in the base register. Number of the element (byte) is held in the index register. All of the following variations are legal: mov ax, [bx][si] mov ax, [bx+si] mov ax, [si][bx]

Base memory addressing with indexing mov al, [bp][di] data AL DI BP + + base address SS

Base memory addressing with indexing It s illegal to use two registers of the same type. Only the following register variations are possible: mov ax, [bx][si] mov ax, [bx][di] mov ax, [bp][si] mov ax, [bp][di]

Base memory addressing with indexing and displacement Address of the data table is an constant. Displacment of the structure is held in the base register. Number of element in the structure (byte) is held in the index register. All of the following variations are legal: mov ax, table[bx][di] mov ax, table[di][bx] mov ax, table[bx+di] mov ax, [table+bx+di] mov ax, [bx][di]+table

Base memory addressing with indexing and displacement mov al, table[bx][si] SI BX + + data AL structure address table + table address DS

Additional notes Calculated offset is called effective address. Different addressing modes have different timings. More complicated modes take much time. If effective address is greater than 0FFFFh the carry bit is ignored. Constant displacement is a 8-bit or 16-bit signed value. Using 8-bit value is faster.

80386 register addressing The same as in 8086 with additional 32-bit registers. Only lower 16-bit half of 32-bit registers is accessible directly. mov eax, ebx mov esi, edx

Indirect memory addressing Address of the data is held in the base and/or index register. It is possible to add the constant displacement too. Almost any of the 32-bit registers can be base or index register. ESP can be the base register only. In 16-bit addressing mode the displacement must not exceed 0FFFFh. In this mode maximum segment size is 64kB.

Indirect memory addressing with scaling It is very useful mode for tables containing values greater than 1 byte. Index registers can be scaled by a factor of 1, 2, 4 or 8. If the scaling factor is 1 the base register is the first used in the instruction. If EBP is scaled it s treated as index register and DS segment is used instead of SS.

Indirect memory addressing with scaling mov ax, [ebx][ebp] ;DS bx-base mov ax, [ebp][ebx] ;SS bp-base mov ax, [ebp][ebx*2] ;SS bp-base mov ax, [ebp*2][ebx] ;DS bx-base mov ax, [ebp*2] ;DS no base mov ax, [ebp] ;SS no index mov ax, es:[ebp][ebx*2] ;ES