Chapter 1: Basic Concepts

Slides:



Advertisements
Similar presentations
Week 3. Assembly Language Programming  Difficult when starting assembly programming  Have to work at low level  Use processor instructions >Requires.
Advertisements

Assembly Language for Intel-Based Computers, 4 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and.
ICS312 Set 2 Representation of Numbers and Characters.
HEXADECIMAL NUMBERS Code
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#4)
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.
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.
Mantıksal Tasarım – BBM231 M. Önder Efe
Assembly Language for Intel-Based Computers, 5th Edition
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.
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.
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
Logic and Digital System Design - CS 303
ACOE2511 ACOE251/AEEC335 -Assembly Language for the 80X86/Pentium Intel Microprocessors Lecturer: Dr. Konstantinos Tatas.
EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,
1 Introduction Chapter 1 n What is Assembly Language? n Data Representation.
1 Digital Systems and Binary Numbers EE 208 – Logic Design Chapter 1 Sohaib Majzoub.
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
ICS312 Set 1 Representation of Numbers and Characters.
Assembly Language for x86 Processors 7 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and copy this.
Number Systems. Why binary numbers? Digital systems process information in binary form. That is using 0s and 1s (LOW and HIGH, 0v and 5v). Digital designer.
Information Representation. Digital Hardware Systems Digital Systems Digital vs. Analog Waveforms Analog: values vary over a broad range continuously.
Data Representation Dr. Ahmed El-Bialy Dr. Sahar Fawzy.
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 #)
ACOE2511 Assembly Language for the 80X86/Pentium Intel Microprocessors Lecturer: Dr. Konstantinos Tatas.
Computer Math CPS120 Introduction to Computer Science Lecture 4.
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
Preliminary to Assembly Language Programming CE 140 A1/A2 28 June 2003.
BINARY SYSTEMS ENGR. KASHIF SHAHZAD 1. BINARY NUMBERS 1/2 Internally, information in digital systems is of binary form groups of bits (i.e. binary numbers)
Computer Math CPS120 Introduction to Computer Science Lecture 7.
CHAPTER 3 BINARY NUMBER SYSTEM. Computers are electronic machines which operate using binary logic. These devices use two different values to represent.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
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.
CS2100 Computer Organisation
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 and Assembly Language
Microprocessor Systems Design I
CS1010 Programming Methodology
Assembly Language for x86 Processors 6th Edition
Introduction to Assembly Language
Autumn Term Year 10 Slides
Computer Organization and Assembly Language
Part I Data Representation and 8086 Microprocessors
Presentation transcript:

Chapter 1: Basic Concepts Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine

Introduction 1.1 Context of assembly language 1.2 Virtual Machine Concept 1.3 Data representation 1.3.1 Binary numbers 1.3.2 Hexadecimal numbers 1.3.3 Arithmetic A. Introducing assembly language

1.1 Context of assembly language: Why study assembly language (ASM)? To learn how high-level language (HLL) code gets translated into machine language Machine language: The language a particular processor understands Assembly language: machine-specific language with a one-to-one correspondence with the machine language for that computer

1.1 Context of assembly language: Example High-Level Language: 10 + 20; MOV AX, 10 ADD AX, 20 Assembly Language: Machine language: B8 000A 83 C014 op code Immediate operand

1.1 Context of assembly language: Why study assembly language (ASM)? To learn the computer (i.e., architecture, hardware, operating system…) by direct access to memory, video controller, sound card, keyboard… by communicating with the operating system To speed up applications direct access to hardware (ex: writing directly to I/O ports instead of doing a system call) good ASM code is faster and smaller Avoid restrictions of high level languages

1.1 Context of 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

1.2 Virtual Machine Concept Virtual Machines Tanenbaum: Virtual machine concept Programming Language analogy: Each computer has a native machine language (language L0) that runs directly on its hardware A more human-friendly language is usually constructed above machine language, called Language L1 Programs written in L1 can run two different ways: Interpretation – L0 program interprets and executes L1 instructions one by one Translation – L1 program is completely translated into an L0 program, which then runs on the computer hardware

Translating Languages 1.2 Virtual Machine Concept Translating Languages 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

Specific Machine Levels 1.2 Virtual Machine Concept Specific Machine Levels (descriptions of individual levels follow . . . )

1.2 Virtual Machine Concept High-Level Language Level 5 Application-oriented languages C++, Java, Pascal, Visual Basic . . . Programs compile into assembly language (Level 4)

1.2 Virtual Machine Concept Assembly Language Level 4 Instruction mnemonics that have a one-to-one correspondence to machine language Calls functions written at the operating system level (Level 3) Programs are translated into machine language (Level 2)

1.2 Virtual Machine Concept Operating System Level 3 Provides services to Level 4 programs Translated and run at the instruction set architecture level (Level 2)

Instruction Set Architecture 1.2 Virtual Machine Concept Instruction Set Architecture Level 2 Also known as conventional machine language Executed by Level 1 (microarchitecture) program

1.2 Virtual Machine Concept Microarchitecture Level 1 Interprets conventional machine instructions (Level 2) Executed by digital hardware (Level 0)

1.2 Virtual Machine Concept Digital Logic Level 0 CPU, constructed from digital logic gates System bus Memory Implemented using bipolar transistors

1.3 Data representation: Binary Numbers Digital computers store information in binary Binary allows two states On yes true 1 Off no false 0 Each digit in a binary number is called a bit MSB – most significant bit LSB – least significant bit 0 1 1 0 1 0 0 0 MSB LSB bit

1.3 Data representation: Data types byte: 8 bits: 10010101 2 word: 16 bits or __ bytes: 1110101101100010 32 4 double word: __ bits or __ bytes : 11010110111001011101011011001011 8 quad word: __ bits or __ bytes: 64 01011110110101011101010011001011 11110110110001011101011011001101

1.3 Data representation: Range of a unsigned number Question: What is the range of numbers that can be represented with ? 1 bit? 2 bits? 4 bits? n bit?

1.3 Data representation: Integer Storage Sizes Standard sizes:

1.3 Data representation: Numbering Systems A number system of base n is a system that uses distinct symbols for n digits

1.3 Data representation: Numbering Systems A written number is meaningful only with respect to a base To tell the assembler which base we use: Hexadecimal 25 is written as 25h Octal 25 is written as 25o or 25q Binary 1010 is written as 1010b Decimal 1010 is written as 1010 or 1010d

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

1.3 Data representation: Number systems (bases) Example

1.3 Binary numbers: Addition & Multiplication Binary addition table + 0 1 0 0 1 1 1 10 Binary multiplication * 0 1 0 0 0 1 0 1

1.3 Binary numbers: Addition & Multiplication Examples: 1001100b 1110b + 1101011b * 1101b 10110101b 111101b + 1101101b * 1111b 10110111 10110110 100100010 1110010011

1.3 Hexadecimal numbers: Addition & Multiplication Hex addition and multiplication tables are large We can still do simple calculations by hand B852h 23Ah + 5A65h * 100h ABCh 2B3h + E F 0 h * 102h

1.3 Arithmetic: Converting to decimal Binary to Decimal 1010b =1 * 23 + 0 * 22 + 1 * 21 + 0*20 =10 Hex to Decimal ABCh = 10 * 162 + 11 * 161+ 12 * 160 = 10 * 256 + 11 * 16 + 12 * 1 = 2560 + 176 + 12 = 2748

1.3 Arithmetic: Converting to decimal Octal to Decimal 256o = 2 * 82 + 5 * 81+ 6 * 80 =174 Conclusion: (Number)n = (multiply each digit by an integer power of n)

1.3 Arithmetic: Conversion problems 1234 base 5 or (1234)5=_________ 111010b = ________ 45677h = ________ 736.4o = ________

1.3 Arithmetic: Conversion from decimal Decimal integer to Binary quotient remainder 54 = 27 * 2+ 0 1 1 0 1 1 0 27 = 13 * 2 + 1 13 = 6 * 2 +1 1 = 0 * 2 + 1 3 = 1 * 2 + 1 6 = 3 * 2 + 0

1.3 Arithmetic: Conversion from decimal Decimal integer to Hex : 54= 3 * 16 + 6 3 = 0 * 16 + 3 3 6 h Decimal integer to octal 54 = 6 * 8+ 6 6 = 0 * 8 + 6 6 6 o

1.3 Arithmetic: Conversion from decimal Decimal fraction to Binary (Octal, Hex) integer (0. 6 8 7 5)10 = (0.1011)2 0.1 0 1 1 2 X 1 . 3 7 5 0 2 X 1 . 0 0 0 0 0 . 7 5 0 0 1 . 5 0 0 0

1.3 Arithmetic: Conversion from decimal Conclusion a decimal integer to a base n representation successive division by n accumulation of the remainders a decimal fraction to a base n representation successive multiplication by n accumulation of the integer digits

1.3 Arithmetic: Conversion problems (1234)10=(________)2 (41.6875)10=(________)2 (1234)10=(________)8 (1234)10=(________)16

1.3 Arithmetic: Conversions: hex, octal and binary Conversion between base 2 and base 8 = 23 111010b = 111 010 = 72o Conversion between base 2 and base 16 = 24 111010b = 11 1010 = 3Ah Note: we often write binary numbers in hex: binary numbers can be very long it is easy to convert back and forth

1.3 Arithmetic: Conversion problems Write ABCh in binary. Write 101110100010100b in hex. Write 101110100010100b in octal

1.3 Arithmetic: Signed numbers Signed numbers: The number of bits must be fixed. In every case, the highest bit is the sign bit. 0 means + 1 means - Example: Unsigned number: 1101b = 13 Signed number: 1101b = ?

1.3 Arithmetic: Two’s complement 1101 b (signed binary number) 0010 b (reverse all bits) + 1 0011 b (unsigned value = 3) - 3d = reversible One’s complement Two’s complement two’s complement of n = NOT(n) +1

1.3 Arithmetic: Practice problems Find the 8 bit two’s complement representation of -2Ch Find the 8 bit two’s complement representation of 2Ch What is decimal representation of the two’s complement number 11110100?

1.3 Arithmetic: Range of signed numbers Two's complement: Sizes Signed byte: -128 to +127 = 27 - 1 Signed word: -32,768 to +32,767 = 215 - 1 Singed double word: -2,147,483,648 to +2,147,483,647 = 231 - 1 Comments: There is one more negative than positive value There are (about) half as many positive signed values as unsigned values

1.3 Arithmetic: Addition & Subtraction (signed) Algorithm to add in signed decimal (sign and magnitude) If both numbers have the same sign Add the two magnitudes Prefix with the common sign else Subtract the number with smaller magnitude from the number with the larger magnitude Prefix with the sign of the number with the larger magnitude.

1.3 Arithmetic: Addition & Subtraction (signed) Two's complement: Addition add two numbers including their sign bits discard any carry out of the sign position Example: + 6 0 0 0 0 0 1 1 0 + 13 0 0 0 0 1 1 0 1 - 6 1 1 1 1 1 0 1 0 - 13 1 1 1 1 0 0 1 1 + 19 0 0 0 1 0 0 1 1 - 19 1 1 1 0 1 1 0 1

1.3 Arithmetic: Addition & Subtraction (signed) Take the 2’s complement of the subtrahend (including the sign bit) Add it to the minuend (including the sign bit) Example: 6 0 0 0 0 0 1 1 0 - 13 - 6 13 0 0 0 0 1 1 0 1 1 1 1 1 0 0 1 1 1 1 1 1 1 0 1 0 - 7 1 1 1 1 1 0 0 1 + 7 0 0 0 0 0 1 1 1

1.3 Arithmetic: Character Storage Characters are stored as numbers Coding schemes ASCII (7 or 8 bit) EBCDIC (8 bit) Unicode (16 bit) ASCII Examples: “A” = 65d = 41h “a” = 97d = 61h “B” = 66d = 42h “b” = 98d = 62h “0” = 48d = 30h “1” = 49d = 31h “ “ = 32d = 20h “*” = 42d = 2Ah

A. Introducing Assembly Language: MASM Installation Insert CD in CD-Rom Go to Desktop, select My Computer Select CD-Rom directory (\IRVINE) Double click “index.html” On the new screen, follow the links, install MASM615, sample program, link library etc.

A. Introducing Assembly Language: A simple Debug program Assembler: converts programs from assembly language to machine language Store 10 into register AX MOV AX, 10 ADD AX, 20 SUB AX, 5 MOV [130], AX INT 20 Store AX in memory location 130h Terminate program

A. Introducing Assembly Language: Running a Debug program Select Start | Programs (| Accessories) |MS-DOS (Command) Prompt Type Debug Type A 100, type the program, press return Type R (registers) to display the registers Type T (trace) as needed to step through program Type G (go) to execute the rest of program Type D 130 131 to display locations 130 and 131 Type Q (quit) to exit Debug

A. Introducing Assembly Language: Debug register display Contents of AX (hex) -R AX=0030 BX=0000 CX=0000 SP=FFEE ... DS=1FA6 ES=1FA6 SS=1FA6 CS=0106 ... 1FA6:0106 2D0500 SUB AX, 0005 Next instruction

A. Introducing Assembly Language: Debug memory display -D 130 131 1FA6:0130 2B 00 Contents of locations 130 and 131. Namely 002Bh Note: The individual bytes in binary are reversed when stored in memory Example: 234567 would be stored in memory as 674523

A. Introducing Assembly Language: Debug disassembly -U 100 1FA6:0100 B81000 MOV AX, 0010 1FA6:0103 052000 ADD AX, 0020 1FA6:0106 2D0500 SUB AX, 0005 1FA6:0109 A33001 MOV [0130],AX 1FA6:010C CD20 INT 20 1FA6:010E 1F POP DS Memory locations Machine code Disassembled assembly code