Assembly Language for Intel-Based Computers, 4 th Edition. Kip R. Irvine. Chapter 2: IA-32 Processor Architecture

Similar documents
Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 2: IA-32 Processor Architecture. Chapter Overview.

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

Assembly Language for x86 Processors 7 th Edition. Chapter 2: x86 Processor Architecture

IA-32 Architecture. Computer Organization and Assembly Languages Yung-Yu Chuang 2005/10/6. with slides by Kip Irvine and Keith Van Rhein

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

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

Assembly Language. Lecture 2 x86 Processor Architecture

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

IA-32 Architecture COE 205. Computer Organization and Assembly Language. Computer Engineering Department

Hardware and Software Architecture. Chapter 2

Computers and Microprocessors. Lecture 34 PHYS3360/AEP3630

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

The Instruction Set. Chapter 5

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

MICROPROCESSOR TECHNOLOGY

Introduction to IA-32. Jo, Heeseung

INTRODUCTION TO IA-32. Jo, Heeseung

Complex Instruction Set Computer (CISC)

IA32 Intel 32-bit Architecture

Memory Models. Registers

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

History of the Intel 80x86

For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to

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

16-Bit Intel Processor Architecture

EEM336 Microprocessors I. The Microprocessor and Its Architecture

Computer System Architecture

CREATED BY M BILAL & Arslan Ahmad Shaad Visit:

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

Embedded Systems Programming

Computers Are Your Future

lesson 3 Transforming Data into Information

Processes and Tasks What comprises the state of a running program (a process or task)?

Processing Unit CS206T

3 Computer Architecture and Assembly Language

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

CS 101, Mock Computer Architecture

UNIT 2 PROCESSORS ORGANIZATION CONT.

Computers and Microprocessors. Lecture 35 PHYS3360/AEP3630

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

Week 1. Introduction to Microcomputers and Microprocessors, Computer Codes, Programming, and Operating Systems

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

x86 architecture et similia

Addressing Modes on the x86

Chapter 2: The Microprocessor and its Architecture

Basic Execution Environment

COS 318: Operating Systems. Overview. Prof. Margaret Martonosi Computer Science Department Princeton University

Datapoint 2200 IA-32. main memory. components. implemented by Intel in the Nicholas FitzRoy-Dale

The Microprocessor and its Architecture

EECE416 :Microcomputer Fundamentals and Design. X86 Assembly Programming Part 1. Dr. Charles Kim

INTEL Architectures GOPALAKRISHNAN IYER FALL 2009 ELEC : Computer Architecture and Design

Chapter 2 COMPUTER SYSTEM HARDWARE

CS3210: Booting and x86

machine cycle, the CPU: (a) Fetches an instruction, (b) Decodes the instruction, (c) Executes the instruction, and (d) Stores the result.

Q1. Describe C.P.U and its subunits with the help of diagram?

SAE5C Computer Organization and Architecture. Unit : I - V

Assembler Programming. Lecture 2

Instruction Set Architectures

The Pentium Processor

Chapter 9: A Closer Look at System Hardware

Chapter 9: A Closer Look at System Hardware 4

CMSC Lecture 03. UMBC, CMSC313, Richard Chang

DIGITA L LOGIC AND COMPUTER ORGA NIZATION

CS3210: Booting and x86. Taesoo Kim

eaymanelshenawy.wordpress.com

Introduction to Microprocessor

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

Assembly Language Programming Introduction

5 Computer Organization

Real instruction set architectures. Part 2: a representative sample

5 Computer Organization

Chapter 4 The Components of the System Unit

Chapter 4. MARIE: An Introduction to a Simple Computer 4.8 MARIE 4.8 MARIE A Discussion on Decoding

CHETTINAD COLLEGE OF ENGINEERING AND TECHNOLOGY COMPUTER ARCHITECURE- III YEAR EEE-6 TH SEMESTER 16 MARKS QUESTION BANK UNIT-1

Computers Are Your Future

Intel 8086 MICROPROCESSOR. By Y V S Murthy

Lab 2: Introduction to Assembly Language Programming

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

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

EC-333 Microprocessor and Interfacing Techniques

Practical Malware Analysis

Components of a personal computer

MICROPROCESSOR MCQs. 1) What does the microprocessor comprise of? a. Register section b. One or more ALU c. Control unit d.

IA32/Linux Virtual Memory Architecture

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

Computer System Overview

Computer System Overview OPERATING SYSTEM TOP-LEVEL COMPONENTS. Simplified view: Operating Systems. Slide 1. Slide /S2. Slide 2.

Architecture of 8086 Microprocessor

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

W4118: PC Hardware and x86. Junfeng Yang

DHANALAKSHMI SRINIVASAN INSTITUTE OF RESEARCH AND TECHNOLOGY. Department of Computer science and engineering

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

ASSEMBLY LANGUAGE MACHINE ORGANIZATION

Advanced Microprocessors

Chapter 2. lw $s1,100($s2) $s1 = Memory[$s2+100] sw $s1,100($s2) Memory[$s2+100] = $s1

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

CHAPTER 4 MARIE: An Introduction to a Simple Computer

Chapter 4 The Components of the System Unit

Computer Organization & Assembly Language Programming

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

Transcription:

Assembly Language for Intel-Based Computers, 4 th Edition Kip R. Irvine Chapter 2: IA-32 Processor Architecture

Chapter Overview General Concepts IA-32 Processor Architecture IA-32 Memory Management Components of an IA-32 Microcomputer Input-Output System Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 2

General Concepts Basic microcomputer design Instruction execution cycle Reading from memory How programs run Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 3

Basic Microcomputer Design [1/2] The central processor unit (CPU) is where all the calculations and logic operations take place. Clock synchronizes CPU operations Control unit (CU) coordinates sequence of execution steps Arithmetic logic unit (ALU) performs arithmetic and bitwise processing data bus registers Central Processor Unit (CPU) Memory Storage Unit I/O Device #1 I/O Device #2 ALU CU clock control bus address bus Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 4

Basic Microcomputer Design [2/2] The memory storage unit is where instructions and data are held while a computer program is running. A bus is a group of parallel wires that transfer data from one part of the computer to another. Data bus, address bus and control bus data bus registers Central Processor Unit (CPU) Memory Storage Unit I/O Device #1 I/O Device #2 ALU CU clock control bus address bus Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 5

Clock Synchronizes all CPU and BUS operations Machine (clock) cycle measures time of a single operation A machine instruction requires at least one clock cycle to execute. A few instructions (e.g., the multiply instruction) requre in excess of 50 clocks. The duration of a clock cycle is the reciprocal of the clock s speed Clock is used to trigger events 1 one cycle 0 Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 6

Instruction Execution Cycle The execution of a single machine instruction can be divided into a sequence of individual operations. Three primary operations: fetch, decode and execute. Two more steps are required when the instruction uses a memory operand: fetch operand and store output operand. Fetch Decode Fetch operands Execute Store output memory op1 op2 PC program I-1 I-2 I-3 I-4 read registers fetch registers I-1 instruction register write write flags ALU decode (output) execute Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 7

Multi-Stage Pipeline Pipelining makes it possible for a processor to execute instructions in parallel Instruction execution divided into discrete stages Stages S1 S2 S3 S4 S5 S6 1 I-1 2 I-1 Example of a nonpipelined processor. Many wasted cycles. Cycles 3 4 5 6 7 I-2 I-1 I-1 I-1 I-1 8 I-2 9 I-2 10 I-2 11 I-2 12 I-2 Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 8

Pipelined Execution More efficient use of cycles, greater throughput of instructions: Stages Cycles 1 2 3 4 5 6 S1 S2 S3 S4 S5 S6 I-1 I-2 I-1 I-2 I-1 I-2 I-1 I-2 I-1 I-2 I-1 For k states and n instructions, the number of required cycles is: k + (n 1) 7 I-2 Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 9

Wasted Cycles (pipelined) When one of the stages requires two or more clock cycles, clock cycles are again wasted. Cycles 1 2 3 4 5 6 7 8 9 10 11 Stages exe S1 S2 S3 S4 S5 I-1 I-2 I-3 I-1 I-2 I-1 I-3 I-2 I-3 I-1 I-1 I-2 I-1 I-2 I-3 I-2 I-3 I-3 S6 I-1 I-2 I-3 For k states and n instructions, the number of required cycles is: k + (2n 1) Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 10

Superscalar A superscalar processor has multiple execution pipelines. In the following, note that Stage S4 has left and right pipelines (u and v). Stages S4 Cycles S1 S2 S3 u v S5 S6 1 I-1 2 I-2 I-1 3 I-3 I-2 I-1 4 I-4 I-3 I-2 I-1 5 I-4 I-3 I-1 I-2 6 I-4 I-3 I-2 I-1 7 I-3 I-4 I-2 I-1 8 I-4 I-3 I-2 9 I-4 I-3 10 I-4 For k states and n instructions, the number of required cycles is: k + n Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 11

Reading from Memory Multiple machine cycles are required when reading from memory, because it responds much more slowly than the CPU. The steps are: address placed on address bus Read Line (RD) set low to notify memory that a value is to be read CPU waits one cycle for memory to respond. During this cycle, the memory controller places the operand on the data bus (DATA) Read Line (RD) goes to 1, indicating that the data is on the data bus Cycle 1 Cycle 2 Cycle 3 Cycle 4 CLK ADDR Address RD DATA Data Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 12

Cache Memory High-speed expensive static RAM both inside and outside the CPU. Level-1 cache: inside the CPU Level-2 cache: outside the CPU Cache hit: when data to be read is already in cache memory Cache miss: when data to be read is not in cache memory. Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 13

How a Program Runs [1/2] User sends program name to Operating system searches for program in Current directory gets starting cluster from Directory entry loads and starts returns to Program System path Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 14

How a Program Runs [2/2] The user issues a command to run a certain program. The OS searches for the program s filename (in the current directory or predetermined list of directories) The OS retrieves basic information about the program s file from the disk directory. The OS loads the program file into memory. The CPU begins to execute the program (process). Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 15

Multitasking OS can run multiple tasks at the same time. Scheduler utility assigns a given amount of CPU time to each running program. Rapid switching of tasks Gives illusion that all programs are running at once Round-robin scheduling The processor must support task switching. The processor saves the state (e.g., registers, variables, program counter) of each task before switching to a new one. OS can assign varying priorities to tasks. Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 16

IA-32 Processor Architecture Modes of operation Basic execution environment Floating-point unit Intel Microprocessor history Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 17

Modes of Operation Protected mode Programs are given separate memory areas (called segments) Windows, Linux Real-address mode Implements the programming environment of the Intel 8086 processor Native MS-DOS All Intel processors boot in Real-address mode System management mode Provides an operating system with a mechanism for implementing Power management, system security, diagnostics Implemented by computer manufactures Virtual-8086 mode hybrid of Protected and Real-address modes While in Protected mode, the processor can directly execute Real-address mode program in a safe multitasking environment. each program has its own 8086 computer Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 18

Basic Execution Environment Addressable memory General-purpose registers Index and base registers Specialized register uses Status flags Floating-point, MMX, XMM registers Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 19

Addressable Memory Protected mode 4 GB 32-bit address Real-address and Virtual-8086 modes 1 MB space 20-bit address Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 20

Registers Registers are high-speed storage locations directly inside the CPU Optimized for speed (e.g., loop processing) 32-bit General-Purpose Registers EAX EBX ECX EDX EBP ESP ESI EDI 16-bit Segment Registers EFLAGS EIP CS SS DS ES FS GS Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 21

Accessing Parts of Registers Used for arithmetic and data movement Use 8-bit name, 16-bit name, or 32-bit name Applies to EAX, EBX, ECX, and EDX 8 AH 8 AL 8 bits + 8 bits AX 16 bits EAX 32 bits Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 22

Index and Base Registers Some registers have only a 16-bit name for their lower half: Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 23

Some Specialized Register Uses [1/2] General-Purpose EAX accumulator (used by multiplication and division instructions) ECX loop counter ESP stack pointer addresses data on the stack ESI, EDI source/destination index registers (for highspeed memory transfer) EBP extended frame pointer (used by high-level languages to reference function parameters and local variables) Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 24

Some Specialized Register [2/2] Segment (as base locations for pre-assigned memory areas) CS code segment DS data segment SS stack segment ES, FS, GS - additional segments EIP instruction pointer Containing the address of the next instruction to be executed EFLAGS Status and control flags Control the operation of the CPU or reflect the outcome of some CPU operation each flag is a single binary bit Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 25

Flags Control Flags Direction Interrupt Status Flags Carry unsigned arithmetic out of range Overflow signed arithmetic out of range Sign result is negative Zero result is zero Auxiliary Carry carry from bit 3 to bit 4 in an 8-bit operand Parity sum of 1 bits is an even number Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 26

Floating-Point, MMX, XMM Registers Eight 80-bit floating-point data registers ST(0), ST(1),..., ST(7) used for high-speed floating-point arithmetic Eight 64-bit MMX registers Eight 128-bit XMM registers for single-instruction multiple-data (SIMD) operations ST(0) ST(1) ST(2) ST(3) ST(4) ST(5) ST(6) ST(7) Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 27

Intel Microprocessor History Intel 8086 Intel 80286 IA-32 processor family P6 processor family CISC and RISC Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 28

Early Intel Microprocessors Intel 8086/8088 Mark the beginning of the modern Intel Architecture family IBM-PC used 8088 1 MB addressable RAM 16-bit registers 16-bit data bus (8-bit for 8088 low-cost microcontroller) separate floating-point unit (8087) Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 29

The IBM-PC/AT Computer Intel 80286 16 MB addressable RAM Protected memory several times faster than 8086 80287 floating point unit Downward Compatibility Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 30

Intel IA-32 Family Intel386 4 GB addressable RAM, 32-bit registers, paging (virtual memory) Intel486 instruction pipelining Pentium superscalar, 32-bit address bus, 64-bit internal data path Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 31

Intel P6 Family Based on a new micro-architecture design that improves execution speed (extension of the basic IA- 32 architecture) Pentium Pro Advanced optimization techniques in microcode Pentium II MMX (multimedia) instruction set Pentium III SIMD (streaming extensions) instructions with special 128-bit registers designed to move large amounts of data quickly Pentium 4 NetBurst micro-architecture, tuned for multimedia applications Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 32

CISC and RISC CISC complex instruction set large instruction set high-level operations High-level language compilers would have less work requires microcode interpreter Complex instructions require a long time for the processor to decode and execute examples: Intel 80x86 family RISC reduced instruction set simple, atomic instructions (for pipelining) small instruction set directly executed by hardware High-speed engineering and graphics workstation use RISC processors examples: ARM (Advanced RISC Machines) DEC Alpha (now Compaq) Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 33

IA-32 Memory Management Real-address mode Calculating linear addresses Protected mode Multi-segment model Paging Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 34

Real-Address mode 1 MB RAM maximum addressable (00000~FFFFFh) Application programs can access any area of memory Single tasking Supported by MS-DOS operating system Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 35

Segmented Memory The original 8086 processor had only 16-bit registers, which can not directly represent a 20-bit address Segmented memory addressing: absolute (linear) address is a combination of a 16-bit segment value added to a 16-bit offset F0000 E0000 D0000 8000:FFFF C0000 linear addresses B0000 A0000 90000 80000 70000 60000 50000 8000:0250 one segment 40000 0250 30000 8000:0000 20000 10000 00000 seg ofs Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 36

Calculating Linear Addresses Given a segment address, multiply it by 16 (add a hexadecimal zero), and add it to the offset Example: convert 08F1:0100 to a linear address Adjusted Segment value: 0 8 F 1 0 Add the offset: 0 1 0 0 Linear address: 0 9 0 1 0 Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 37

Your turn... What linear address corresponds to the segment/offset address 028F:0030? 028F0 + 0030 = 02920 Always use hexadecimal notation for addresses. Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 38

Your turn... What segment addresses correspond to the linear address 28F30h? Many different segment-offset addresses can produce the linear address 28F30h. For example: 28F0:0030, 28F3:0000, 28B0:0430,... Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 39

Protected Mode 4 GB addressable RAM (00000000 to FFFFFFFFh) Each program assigned a memory partition which is protected from other programs Designed for multitasking Supported by Linux & MS-Windows Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 40

Flat Segmentation Model All segments are mapped to the entire 32-bit physical address space of the computer. At least two segments: one for program code and one for data Each segment is defined by a segment descriptor, a 64-bit value stored in a table known as the global descriptor table (GDT) Segment descriptor in the Global Descriptor Table base address limit access 00000000 0040 ---- not used Physical RAM FFFFFFFF (4GB) 00040000 00000000 Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 41

Multi-Segment Model Each program has a local descriptor table (LDT) holds descriptor for each segment used by the program RAM Local Descriptor Table base limit access 00026000 0010 00008000 000A 00003000 0002 26000 8000 3000 Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 42

Paging Supported directly by the CPU Divides each segment into 4096-byte blocks called pages Sum of all programs can be larger than physical memory Part of running program is in memory, part is on disk Virtual memory manager (VMM) OS utility that manages the loading and unloading of pages Page fault issued by CPU when a page must be loaded from disk Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 43

Components of an IA-32 Microcomputer Motherboard Video output Memory Input-output ports Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 44

Motherboard The heart of a microcomputer CPU socket External cache memory slots Main memory slots BIOS (a collection of functions that communicate directly with hardware devices) chips Sound synthesizer chip (optional) Video controller chip (optional) IDE (hard and CD-ROM drives), parallel, serial, USB PCI bus connectors (expansion cards) Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 45

Video chip Audio chip Intel D850MD Motherboard mouse, keyboard, parallel, serial, and USB connectors PCI slots memory controller hub Intel 486 socket Firmware hub dynamic RAM I/O Controller Speaker Battery Source: Intel Desktop Board D850MD/D850MV Technical Product Specification IDE drive connectors Power connector Diskette connector Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 46

Video Output Video controller on motherboard, or on expansion card A special-purpose microcomputer, relieving the primary CPU of the job of controlling video hardware Video memory (VRAM) Video CRT Display uses raster scanning horizontal retrace vertical retrace Direct digital LCD monitors no raster scanning required Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 47

Memory ROM read-only memory (permanently burned into a chip) EPROM erasable programmable read-only memory (be erased slowly with ultraviolet light) Dynamic RAM (DRAM) inexpensive; must be refreshed constantly Static RAM (SRAM) expensive; used for cache memory; no refresh required Video RAM (VRAM) dual ported (refreshing+writing); optimized for constant video refresh Allocated on a video controller CMOS RAM system setup information On the system motherboard Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 48

Input-Output Ports [1/2] USB (universal serial bus) intelligent high-speed connection to devices up to 12 megabits/second USB hub connects multiple devices enumeration: computer queries devices Parallel short cable (less than 10 feet), high speed common for printers bidirectional, parallel data transfer (8 or 16 bits simultaneously) Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 49

Input-Output Ports [2/2] Serial RS-232 serial port one bit at a time uses long cables and modems 16550 UART (Universal Asynchronous Receiver Transmitter) controls the serial ports. Located either on the motherboard or on an adapter card Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 50

Levels of Input-Output Level 3: Call a library function (C++, Java) easy to do; abstracted from hardware; details hidden slowest performance Level 2: Call an operating system function specific to one OS; device-independent E.g., writing entire strings to files, reading string from the keyboard, allocating blocks of memory for application programs medium performance Level 1: Call a BIOS (basic input-output system) function may produce different results on different systems knowledge of hardware required usually good performance Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 51

Displaying a String of Characters When a HLL program displays a string of characters, the following steps take place: 1. Application program writes the string to standard output. 2. The library function calls OS, passing a string pointer. 3. OS passes the ASCII code and color of each character to BIOS. OS also calls BIOS function to control the cursor. 4. BIOS maps each character to a particular system font and sends it to a hardware port attached to the video controller card. 5. The video controller card generates hardware signals to the video display. Application Program Level 3 OS Function Level 2 BIOS Function Level 1 Hardware Level 0 Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 52

ASM Programming levels ASM programs can perform input-output at each of the following levels: OS Function Level 2 ASM Program BIOS Function Level 1 Hardware Level 0 Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 53

Playing a WAV file At the OS level, you do not have to know what type of device was installed and the card s features. At the BIOS level, you would query the sound card and find out whether it belongs to a certain class of sound cards. At the hardware level, you would fine-tune the program for certain brands of audio cards, to take advantage of each card s special features. Not all operating system permit user programs to directly access system hardware. Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 54