X86 Assembly Language We will be using the nasm assembler (other assemblers: MASM, as, gas)

Slides:



Advertisements
Similar presentations
Register In computer architecture, a processor register is a small amount of storage available on the CPU whose contents can be accessed more quickly than.
Advertisements

There are two types of addressing schemes:
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 2 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#3) By Dr. Syed Noman.
Intel MP.
Azir ALIU 1 What is an assembly language?. Azir ALIU 2 Inside the CPU.
Lecture 6 Machine Code: How the CPU is programmed.
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 2 The Microprocessor and its Architecture.
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
3-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL Intel 8088 (8086) Microprocessor.
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 Instructor: Dr. Michael Geiger Spring 2012 Lecture 2: 80386DX Internal Architecture & Data Organization.
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Spring 2013 Lecture 4: 80386DX memory, addressing.
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Spring 2014 Lecture 4: x86 memory.
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 2 The Microprocessor and its Architecture.
Gursharan Singh Tatla Block Diagram of Intel 8086 Gursharan Singh Tatla 19-Apr-17.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
An Introduction to 8086 Microprocessor.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 2: IA-32 Processor Architecture (c) Pearson Education, All rights reserved. You.
1 Fundamental of Computer Suthida Chaichomchuen : SCC
MOHD. YAMANI IDRIS/ NOORZAILY MOHAMED NOOR1 Addressing Mode.
Fall 2012 Chapter 2: x86 Processor Architecture. Irvine, Kip R. Assembly Language for x86 Processors 6/e, Chapter Overview General Concepts IA-32.
INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
The x86 Architecture Lecture 15 Fri, Mar 4, 2005.
ECE291 Lecture 1 All about computers. ECE 291 Lecture 1Slide 2 of 45 Lecture outline Errata from yesterday Class and Lab Schedules Top-down view of computers.
1 ICS 51 Introductory Computer Organization Fall 2009.
UHD:CS2401: A. Berrached1 The Intel x86 Hardware Organization.
ECE291 Lecture 1 All about computers. ECE 291 Lecture 1Page 2 of 41 Lecture outline Top-down view of computers Processor architecture RegistersMemoryPeripherals.
(-133)*33+44* *33+44*14 Input device memory calculator Output device controller Control bus data bus memory.
Chapter 2 Parts of a Computer System. 2.1 PC Hardware: Memory.
Computers organization & Assembly Language Chapter 1 THE 80x86 MICROPROCESSOR.
ECE291 Computer Engineering II Lecture 3 Dr. Zbigniew Kalbarczyk University of Illinois at Urbana- Champaign.
Intel 8086 (8088) Microprocessor Structure
University of Sargodha, Lahore Campus Prepared by Ali Saeed.
MODULE 5 INTEL TODAY WE ARE GOING TO DISCUSS ABOUT, FEATURES OF 8086 LOGICAL PIN DIAGRAM INTERNAL ARCHITECTURE REGISTERS AND FLAGS OPERATING MODES.
Lecture 2 About Computers Dr. Dimitrios S. Nikolopoulos CSL/UIUC.
1 x86 Programming Model Microprocessor Computer Architectures Lab Components of any Computer System Control – logic that controls fetching/execution of.
Week 6 Dr. Muhammad Ayaz Intro. to Assembly Language.
Intel 8086 MICROPROCESSOR ARCHITECTURE
Computer Organization & Assembly Language University of Sargodha, Lahore Campus Prepared by Ali Saeed.
BITS Pilani Pilani Campus Pawan Sharma Lecture / ES C263 INSTR/CS/EEE F241 Microprocessor Programming and Interfacing.
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.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
Chapter 12 Processor Structure and Function. Central Processing Unit CPU architecture, Register organization, Instruction formats and addressing modes(Intel.
Chapter Overview General Concepts IA-32 Processor Architecture
Assembly language.
Format of Assembly language
Introduction to 8086 Microprocessor
Computer skills CPU Jakub Yaghob.
Basic Microprocessor Architecture
Assembly IA-32.
ADDRESSING MODES.
University of Gujrat Department of Computer Science
Basic of Computer Organization
Microcomputer & Interfacing Lecture 1
Introduction to Assembly Language
BIC 10503: COMPUTER ARCHITECTURE
8086 Registers Module M14.2 Sections 9.2, 10.1.
CS-401 Computer Architecture & Assembly Language Programming
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures
CS 301 Fall 2002 Computer Organization
The Microprocessor & Its Architecture
Assembly Language (CSW 353)
Computer Architecture CST 250
Computer Architecture and System Programming Laboratory
Part I Data Representation and 8086 Microprocessors
Presentation transcript:

X86 Assembly Language We will be using the nasm assembler (other assemblers: MASM, as, gas)

Outline x86 registers x86 memory basics Introduction to x86 assembly

Why Assembly ? Assembly lets you write fast programs –You can write programs that execute calculations at the maximum hardware speed… –…assuming that you know what you’re doing… Why not always use assembly ? Assembly is necessary for writing certain portions of system software –Compilers –Operating systems Assembly is used to program embedded devices and DSPs

x86 Intel/Microsoft’s monopoly: cost-effective microprocessors for the mass market x86 refers to an instruction set rather than a specific processor architecture, also known as ia32 The processor core that implements the x86 instruction set has gone through substantial modifications and additions over the last 20 years x86 is a Complex Instruction Set Computer –20,000+ instructions –This course course will take you through some of them! amd64 instruction set has replaced x86 for new code

Registers Registers are storage locations The first-level of a computer’s memory hierarchy The fastest to access storage in your system Purposes –Data used in arithmetic/logical operations –Pointers to memory locations containing data or instructions –Control information (e.g. outcome of arithmetic instructions, outcome of instructions that change the control flow of a program)

x86 Registers at a Glance Accumulator EAX AHAL AX Base EBX BHBL BX Count ECX CHCL CX Data EDX DHDL DX General Purpose (sort of) Instr Pointer EIP IP Flags EFLAG FLAG Special Registers Stack Segment Code Segment CS Data Segment DS Extra Segment ES SS FS GS Segment Registers Stack Pointer ESP SP Base Pointer EBP BP Dest Index EDI DI Source Index ESI SI Index Registers

General Purpose Registers Accumulator (AH,AL,AX,EAX) –Accumulates results from mathematical calculations Base (BH,BL,BX,EBX) –Points to memory locations Count (CL,CH,CX,ECX) –Counter used typically for loops –Can be automatically incremented/decremented Data (DL,DH,DX,EDX) –Data used in calculations –Most significant bits of a 32-bit mul/div operation

A note on GP registers In and newer processors GP registers can be used with a great deal of flexibility… But you should remember that each GP register is meant to be used for specific purposes… Memorizing the names of the registers will help you understand how to use them Learning how to manage your registers will help you develop good programming practices You will find that you are generally short of registers

Index Registers SP, ESP –Stack pointer (more on that in upcoming lectures…) BP, EBP –Address stack memory, used to access subroutine arguments as a stack frame mechanism SI, ESI, DI, EDI –Source/Destination registers –Point to the starting address of a string/array –Used to manipulate strings and similar data types

Segment Registers CS –Points to the memory area where your program’s instructions are stored DS –Points to the memory area where your program’s data is stored SS –Points to the memory area where your stack is stored ES,FS,GS –They can be used to point to additional data segments, if necessary

Special Registers IP, EIP –Instruction pointer, points always to the next instruction that the processor is going to execute –Only changed indirectly by branching instructions FLAG, EFLAG –Flags register, contains individual bits set by different operations (e.g. carry, overflow, zero) –Used massively with branch instructions

x86 memory addressing modes Width of the address bus determines the amount of addressable memory The amount of addressable memory is NOT the amount of physical memory available in your system Real mode addressing –A throwback to the age of 8086, 20-bit address bus, 16-bit data bus –In real mode we can only address memory locations 0 through 0FFFFF h. Used only with 16-bit registers –We will not be using real mode! Protected mode addressing –32-bit address bus, 32-bit data bus, 32-bit registers –Up to 4 Gigabytes of addressable memory –80386 and higher operate in either real or protected mode

Real-mode addressing on the x86 Memory address format Segment:Offset Linear address obtained by: –Shifting segment left by 4 bits –Adding offset Example: 2222:3333 Linear address: Example: 2000:5553 Linear address: THIS WILL NOT APPLY TO US IN 32-bit PROTECTED MODE!

Assembly files Five simple things: Labels –Variables are declared as labels pointing to specific memory locations –Labels mark the start of subroutines or locations to jump to in your code Instructions – cause machine code to be generated Directives – affect the operation of the assembler Comments Data

Comments, comments, comments! ; Comments are denoted by semi-colons. ; Please comment your code thoroughly. ; It helps me figure out what you were doing ; It also helps you figure out what you were ; doing when you look back at code you ; wrote more than two minutes ago. ; everything from the semi-colon to the end ; of the line is ignored.

Labels ; Labels are local to your file/module ; unless you direct otherwise, the colon ; identifies a label (an address!) MyLabel: ; to make it global we say globalMyLabel ; And now the linker will see it

Example with simple instructions var1:dd0FFh str1:db“my dog has fleas”,10 var2:dd0 ; Here are some simple instructions mov eax, [var1] ; notice the brackets mov edx, str1 ; notice lack of brackets call dspmsg jmp done mov ebx, [var2] ; this will never happen done:nop