Assembly Language for Intel-Based Computers, 5th Edition

Slides:



Advertisements
Similar presentations
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and.
Advertisements

ICS312 Set 2 Representation of Numbers and Characters.
1 Lecture-2 CSIT-120 Spring 2001 Revision of Lecture-1 Introducing Computer Architecture The FOUR Main Elements Fetch-Execute Cycle A Look Under the Hood.
COMP3221 lec05-numbers-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 5: Number Systems – I
Basic Concepts COE 205 Computer Organization and Assembly Language
Data Representation Computer Organization &
Data Representation COE 205
Introduction to Computers and Programming. Some definitions Algorithm: –A procedure for solving a problem –A sequence of discrete steps that defines such.
Introduction to Programming with Java, for Beginners
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
1 Lecture-2 CS-120 Fall 2000 Revision of Lecture-1 Introducing Computer Architecture The FOUR Main Elements Fetch-Execute Cycle A Look Under the Hood.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
COMP3221 lec07-numbers-III.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 7: Number Systems - III
1 Introduction Chapter 1 n What is Assembly Language? n Data Representation.
Introduction to Computers and Programming. Some definitions Algorithm: Algorithm: A procedure for solving a problem A procedure for solving a problem.
Basic Concepts Computer Organization and Assembly Language.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#1) By Dr. Syed Noman.
Codes and number systems Introduction to Computer Yung-Yu Chuang with slides by Nisan & Schocken ( ) and Harris & Harris (DDCA)
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and copy this slide show for your personal use, or for.
Programmable Logic Controllers
Computers Organization & Assembly Language
Some material taken from Assembly Language for x86 Processors by Kip Irvine © Pearson Education, 2010 Slides revised 2/2/2014 by Patrick Kelley.
CPS120: Introduction to Computer Science
CSU0014 Assembly Languages Homepage: Textbook: Kip R. Irvine, Assembly Language for Intel-Based Computers,
Summer 2014 Chapter 1: Basic Concepts. Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Chapter Overview Welcome to Assembly Language.
Assembly Language for x86 Processors 7th Edition
ACOE2511 ACOE251/AEEC335 -Assembly Language for the 80X86/Pentium Intel Microprocessors Lecturer: Dr. Konstantinos Tatas.
Chapter 1: Basic Concepts
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
1 Introduction Chapter 1 n What is Assembly Language? n Data Representation.
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
Computer Systems Organization CS 1428 Foundations of Computer Science.
ICS312 Set 1 Representation of Numbers and Characters.
CS2422 Basic Concepts Department of Computer Science National Tsing Hua University.
Assembly Language for x86 Processors 7 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and copy this.
COMP3221 lec04--prog-model.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 4: Programmer’s Model of Microprocessors
CPU Internal memory I/O interface circuit System bus
Chapter 19 Number Systems. Irvine, Kip R. Assembly Language for Intel-Based Computers, Translating Languages English: Display the sum of A times.
CSNB374: Microprocessor Systems Chapter 1: Introduction to Microprocessor.
Introduction to Programming Instructor: Yong Tang Brookhaven National Laboratory Working on accelerator control (BNL Phone #)
EEL 3801C EEL 3801 Part I Computing Basics. EEL 3801C Data Representation Digital computers are binary in nature. They operate only on 0’s and 1’s. Everything.
1 Text Reference: Warford. 2 Computer Architecture: The design of those aspects of a computer which are visible to the programmer. Architecture Organization.
ACOE2511 Assembly Language for the 80X86/Pentium Intel Microprocessors Lecturer: Dr. Konstantinos Tatas.
Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Signed Integers The highest bit indicates the sign. 1 = negative, 0 = positive.
Computer Organization and Assembly Languages 2007/11/10
1 Basic Processor Architecture. 2 Building Blocks of Processor Systems CPU.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
1 TM 1 Embedded Systems Lab./Honam University ARM Microprocessor Programming Model.
Suffolk County Community College Mathematics and Computer Science Ammerman Campus CST 121Spring 2013 Section 151CRN: Computer Organization And System.
1 Chapter 1: Introduction Appendix A: Binary and Hexadecimal Tutorial Assembly Language for Intel-Based Computers, 3rd edition Kip R. Irvine.
1 Chapter 1: Basic Concepts Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine 9/6/2003.
CSC235 Computer Organization & Assembly Language
Lec 3: Data Representation
Assembly Language for x86 Processors 6th Edition
Assembly Language (CSW 353)
Data Representation Binary Numbers Binary Addition
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
Microprocessor Systems Design I
Microprocessor Systems Design I
March 2006 Saeid Nooshabadi
Assembly Language for x86 Processors 6th Edition
Introduction to Assembly Language
Chapter One: Introduction
Computer Organization and Assembly Language
University of Gujrat Department of Computer Science
Part I Data Representation and 8086 Microprocessors
Dr. Clincy Professor of CS
Presentation transcript:

Department of Computer Science Faculty of Science RU. COS2014 Basic Concepts Department of Computer Science Faculty of Science RU.

Assembly Language for Intel-Based Computers, 5th Edition Kip Irvine

Why study assembly language? Learn about computers Computer architecture Operating systems Data representation Hardware devices Learn about assembly languages Learn about compiling Learn how to write embedded programs Learn the assemble language for Intel 80x86

Welcome to Assembly Language: Definitions Assembly language: machine-specific language with a one-to-one correspondence with the machine language for that computer Machine language: The language a particular processor understands Assembler: converts programs from assembly language to machine language

Welcome to Assembly Language: Example High-Level Language: x = a + b; Assembly Language: MOV AX, a ADD AX, b MOV x, AX Machine language: A1 0002 06 0004 A3 0000

Welcome to Assembly Language: Problems with assembly language Provides no structure Is not portable Applications can be very long “Hard” to read and understand Lots of detail required

Assembly Language Machine language: Assembly language: Machine instructions: direct instructions to the processor, e.g. to be encoded to control the datapath A numeric language understood by the processor Assembly language: Statements (instructions) in short mnemonics and symbolic reference, e.g. ADD, MOV, CALL, var1, i, j, that have a 1-to-1 relationship with machine instructions Understood by human

CPU, memory, I/O, Operations on variables, … When you are writing a C program, how does a computer look like? CPU, memory, I/O, Operations on variables, …

A Model of Computer for C i = i + j; xfloat = 1.0; if (A[0]==0) … Program Counter Memory i, j, k; xfloat, yfloat; && +  CPU A[0], A[1], … if for Typed storage

Why a C program code can run on your computer? This model is quite different from what the hardware in a computer does when you run your program! Why a C program code can run on your computer? Obviously, someone does some translation for you!

We have known … C program Assembly program C compiler x = (a+b) * b MOV AX, a ADD AX, b MUL c MOV x, AX C compiler Input and output of a compiler

We can see that Assembly Lang. is closer to real computer hardware! From the angle of Assembly Lang., how does a computer look like?

A Model of Computer for ASM MOV AX, a ADD AX, b MOV x, AX … Memory a 010100110010101 CPU AX b 110010110001010 BX PC ... JX x 000000000010010 + -

We need one more level of translation! Assembly program/machine code still have some distance to the real computer hardware. e.g. Multi-core CPU、hyperthreading We need one more level of translation!

Computer Model of a Lower Layer (from Computer Architecture textbook)

A Layered View of Computer +  if for && CPU Memory i, j, k; xfloat, yfloat; A[0], A[1], … i = i + j; if (A[0]==0) … Program Counter i = i + j; xfloat = 1.0; if (A[0]==0) … CPU Memory ADD AX, b MOV x, AX … 010100110010101 a 110010110001010 b 000000000010010 x AX BX JX ... + - PC MOV AX, a ADD AX, b MOV x, AX … xxxxxx xxxxx

From Assembly to Binary MOV AX, a ADD AX, b MUL c MOV x, AX Assembler 00000000101000010000000000011000 00000000100011100001100000100001 10001100011000100000000000000000 10001100111100100000000000000100 10101100111100100000000000000000 10101100011000100000000000000100 00000011111000000000000000001000 Input and output of an assembler Machine code

Different Levels of Abstractions temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; High Level Language Program Compiler MOV AX, a ADD AX, b MOV x, AX Assembly Language Program more elaborated later in Sec. 1-2: Virtual Machine Concept Assembler Machine Language Program 0000 1001 1100 0110 1010 1111 0101 1000 1010 1111 0101 1000 0000 1001 1100 0110 1100 0110 1010 1111 0101 1000 0000 1001 0101 1000 0000 1001 1100 0110 1010 1111 Machine Interpretation Control Signal ALUOP[0:3] <= InstReg[9:11] & MASK °

What’s Next? Virtual machine concept (Sec. 1-2) Data representation (Sec. 1-3)

Virtual Machine Concept Purpose of this section: Understand the role of assembly language in a computer system Side product: The principle of layered abstraction for combating complexities, e.g. OSI 7-layer protocol

Virtual Machine Concept A layered abstraction of computers proposed by A. Tanenbaum Each layer provides an abstract computer, or virtual machine, to its upper layer Virtual machine: A hypothetical computer that can be constructed of either HW or SW What is a computer?

Simplest Model of Computers Program Instructions Input data Compute engine Memory Output data c.f., y = f(x) Layered abstraction: A computer consists of layers of such virtual machine abstractions

Why Layered Abstraction? Big idea: layered abstraction to combat complexities A strategy of divide-and-conquer Decompose a complex system into layers with well-defined interfaces Each layer is easier to manage and handle Only need to focus on a particular layer, e.g. to make it the best Also, it makes interaction clear Particularly if one layer is realized in hardware and the other in software

Layered Abstraction of Computer Each layer as a hypothetical computer, or virtual machine, that runs a programming language Can be programmed with the programming language to process inputs and outputs Program written in Li can be mapped to that Li-1 by: Interpretation: Li-1 program interprets and executes Li instructions one by one Translation: Li program is completely translated into Li-1 program, and runs on Li-1 machine Compute engine Memory Input data Output data Program Instructions

Layered Abstraction of Computer Virtual Machine +  if for && CPU Memory i, j, k; xfloat, yfloat; A[0], A[1], … i = i + j; if (A[0]==0) … Program Counter i = i + j; xfloat = 1.0; if (A[0]==0) … Li CPU Memory ADD AX, b MOV x, AX … 010100110010101 a 110010110001010 b 000000000010010 x AX BX JX ... + - PC MOV AX, a ADD AX, b MOV x, AX … Li-1 xxxxxx xxxxx

Languages of Different Layers English: Display the sum of A times B plus C. C++: cout << (A * B + C); Assembly Language: mov eax,A mul B add eax,C call WriteInt Intel Machine Language: A1 00000000 F7 25 00000004 03 05 00000008 E8 00500000

High-Level Language Level 5 Application-oriented languages, e.g., C, C++, Java, Perl Written with certain programming model in mind Variables in storage Operators for operations Programs compiled into assembly language (Level 4) or interpreted by interpreters What kind of computer does C see?

Assembly Language Level 4 Instruction mnemonics that have a one-to-one correspondence to machine language Based on a view of machine: register organization, addressing, operand types and locations, functional units, … Calls functions written at the OS level (Level 3) Programs are translated into machine language (Level 2) What kind of computer does it see?

Operating System Level 3 Provides services to Level 4 programs as if it were a computer Programs translated and run at the instruction set architecture level (Level 2)

Instruction Set Architecture Level 2 Known as conventional machine language Attributes of a computer as seen by assembly programmer, i.e. conceptual structure and functional behavior Organization of programmable storage Data types and data structures Instruction set and formats Addressing modes and data accessing Executed by Level 1 program (microarchitecture)

Microarchitecture Level 1 Can be described by register transfer language (RTL) Interprets conventional machine instructions (Level 2) Executed by digital hardware (Level 0) Register Memory Control Signals Controller ALU N Z clock IR PC

Digital Logic Level 0 CPU, constructed from digital logic gates System bus Memory

What’s Next? Virtual machine concept (Sec. 1-2) Data representation (Sec. 1-3)

Data Representation Purpose of this section Assembly program often needs to process data, and manage data storage and memory locations  need to know data representation and storage Binary numbers: translating between binary and decimal Binary addition Integer storage sizes Hexadecimal integers: translating between decimal and hex.; hex. subtraction Signed integers: binary subtraction Character storage

Binary Numbers Digits are 1 and 0 MSB – most significant bit 1 = true 0 = false MSB – most significant bit LSB – least significant bit Bit numbering:

Binary Numbers Each digit (bit) is either 1 or 0 Each bit represents a power of 2: Every binary number is a sum of powers of 2

Integer Storage Sizes Standard sizes: Why unsigned numbers? What is the largest unsigned integer that may be stored in 20 bits?

Signed Integers The highest bit indicates the sign 1 = negative, 0 = positive If the highest digit of a hexadecimal integer is > 7, the value is negative. Examples: 8A, C5, A2, 9D

Forming Two's Complement Negative numbers are stored in two's complement notation Complement (reverse) each bit Add 1 Why? Note that 00000001 + 11111111 = 00000000

Binary Addition Starting with the LSB, add each pair of digits, include the carry if present.

Hexadecimal Integers All values in memory are stored in binary. Because long binary numbers are hard to read, we use hexadecimal representation.

Translating Binary to Hexadecimal Each hexadecimal digit corresponds to 4 binary bits. Example: Translate the binary integer 000101101010011110010100 to hexadecimal:

Converting Hexadecimal to Decimal Multiply each digit by its corresponding power of 16: dec = (D3  163) + (D2  162) + (D1  161) + (D0  160) Hex 1234 equals (1  163) + (2  162) + (3  161) + (4  160), or decimal 4,660. Hex 3BA4 equals (3  163) + (11 * 162) + (10  161) + (4  160), or decimal 15,268.

Data representation: Number systems (bases) Number systems used Binary: The internal representation inside the computer. Externally, they may be represented in binary, decimal, or hexadecimal. Decimal: The system people use. ASCII representations of numbers used for I/O: ASCII binary ASCII octal ASCII decimal ASCII hexadecimal

Data representation: Hex Addition & Multiplication Hex addition and multiplication tables are large We can still do simple calculations by hand B852h 23Ah + 5A65h * 100h (Your turn) ABCh 2B3h + E F 0 h * 102h

Data representation: Converting to decimal 12345 = 1 * 104 + 2 * 103 + 3 * 102 + 4 * 101 + 5*100 (Human) conversions: hex to decimal ABCDh = 10*163 + 11*162+ 12 *161 + 13 *160 = 10*4096 + 11*256 + 12*16 + 13 = 40960 + 2816 + 192 + 13 = 43981

Data representation: Converting to decimal (Human) conversions to decimal ABCDh = (((10*16+11)*16+12)*16+13 = 43981 (easier on calculator)

Data representation: Your Turn: Conversion problems 1234 base 5 or (1234)5= _________ 10

Data representation: Conversion from decimal (Human) conversions from decimal 274810 = ??? In hex 2748 = 171 * 16 + 12 171 = 10 * 16 + 11 10 = 0 * 16 + 10 so value is ABCh How do we know this is the Hex representation? 2748 = 171 * 16 +12 = (10*16 + 11) * 16 + 12 = 10 * 162 + 11 * 161 + 12 * 160 = ABCh

Data representation: Your Turn: Conversion problems Write decimal 58 in binary. Write decimal 194 in base 5

Learn How To Do the Following: Form the two's complement of a hexadecimal integer Convert signed binary to decimal Convert signed decimal to binary Convert signed decimal to hexadecimal Convert signed hexadecimal to decimal

Ranges of Signed Integers The highest bit is reserved for the sign. This limits the range: Practice: What is the largest positive value that may be stored in 20 bits?

Character Storage Character sets Null-terminated String Standard ASCII (0 – 127) Extended ASCII (0 – 255) ANSI (0 – 255) Unicode (0 – 65,535) Null-terminated String Array of characters followed by a null byte Using the ASCII table back inside cover of book

Numeric Data Representation pure binary can be calculated directly ASCII binary string of digits: "01010101" ASCII decimal string of digits: "65" ASCII hexadecimal string of digits: "9C"

Character Representation ASCII (Table of ASCII Codes) American Standard Code for Information Interchange Standard encoding scheme used to represent characters in binary format on computers 7-bit encoding, so 128 characters can be represented 0 to 31 & 127 are "control characters" (cannot print) Ctrl-A or ^A is 1, ^B is 2, etc. Used for screen formatting & data communication 32 to 126 are printable (see the last page in textbook)

ASCII Character Codes CHAR DECIMAL HEX BINARY '9' 57d 39h 0011 1001b 'A' 65d 41h 0100 0001b 'Z' 90d 5Ah 0101 1010b 'a' 97d 61h 0110 0001b 'z' 122d 7Ah 0111 1010b

Binary Data Decimal, hex & character representations are easier for humans to understand; however… All the data in the computer is binary An int is typically 32 binary digits int y = 5; (y = 0x00000005;) In computer y = 00000000 00000000 00000000 00000101 int z = -5; (y = 0xFFFFFFFB;) In computer, z = 11111111 11111111 11111111 11111011

Binary Data A char is typically 8 binary digits char x = '5'; (or char x = 53, or char x = 0x35) In computer, x = 00110101 char x = 5; (or char x = 0x05;) In computer, x = 00000101 Note that the ASCII character 5 has a different binary value than the numeral 5 Also note that 1 ASCII character = 2 hex numbers

Storage Size Terminology Byte 8 bits (basic storage size for all data) Word 16 bits (2 bytes) Doubleword 32 bits (4 bytes) Quadword 64 bits (8 bytes)