SlideShare a Scribd company logo
AAsssseemmbbllyy LLaanngguuaaggee ffoorr IInntteell--BBaasseedd 
CCoommppuutteerrss,, 55tthh EEddiittiioonn 
Kip Irvine 
Chapter 1: Basic Concepts 
Slides prepared by the author 
Revision date: June 3, 2006 
(c) Pearson Education, 2006-2007. All rights reserved. You may modify and copy this slide show for your personal use, 
or for use in the classroom, as long as this copyright statement, the author's name, and the title are not changed.
OObbjjeeccttiivveess 
• Understand common applications of assembly 
language 
• Understand what an assembler does 
• Understand hardware and software requirements for 
the book 
• Know the basic history of PC Assemblers 
• Differentiate between protected mode and real-address 
mode 
• Learn basic principles of computer architecture as 
applied to the Intel IA-32 processor family 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 2
OObbjjeeccttiivveess ((ccoonnttiinnuuee)) 
• Learn how to recognize and convert boolean and 
hexadecimal integers 
• Perform binary addition and subtraction 
• Understand basic boolean operations 
• Differentiate between signed and unsigned binary 
integers 
• Understand ASCII character representation 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 3
CChhaapptteerr OOvveerrvviieeww 
• Welcome to Assembly Language 
• Virtual Machine Concept 
• Data Representation 
• Boolean Operations 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 4
WWeellccoommee ttoo AAsssseemmbbllyy LLaanngguuaaggee 
• Some Good Questions to Ask 
• Assembly Language Applications 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 5
QQuueessttiioonnss ttoo AAsskk 
• Why am I learning Assembly Language? 
• What background should I have? 
• What is an assembler? 
• What hardware/software do I need? 
• What types of programs will I create? 
• What do I get with this book? 
• What will I learn? 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 6
WWeellccoommee ttoo AAsssseemmbbllyy LLaanngguuaaggee ((ccoonntt)) 
• How does assembly language (AL) relate to machine 
language? 
• How do C++ and Java relate to AL? 
• Is AL portable? 
• Why learn AL? 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 7
AAsssseemmbbllyy LLaanngguuaaggee AApppplliiccaattiioonnss 
• Some representative types of applications: 
• Business application for single platform 
• Hardware device driver 
• Business application for multiple platforms 
• Embedded systems & computer games 
(see next panel) 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 8
CCoommppaarriinngg AASSMM ttoo HHiigghh--LLeevveell LLaanngguuaaggeess 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 9
WWhhaatt''ss NNeexxtt 
• Welcome to Assembly Language 
• Virtual Machine Concept 
• Data Representation 
• Boolean Operations 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 10
VViirrttuuaall MMaacchhiinnee CCoonncceepptt 
• Virtual Machines 
• Specific Machine Levels 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 11
VViirrttuuaall MMaacchhiinneess 
• 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 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 12
TTrraannssllaattiinngg LLaanngguuaaggeess 
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 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 13
SSppeecciiffiicc MMaacchhiinnee LLeevveellss 
(descriptions of individual levels 
follow . . . ) 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 14
HHiigghh--LLeevveell LLaanngguuaaggee 
• Level 5 
• Application-oriented languages 
• C++, Java, Pascal, Visual Basic . . . 
• Programs compile into assembly language 
(Level 4) 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 15
AAsssseemmbbllyy LLaanngguuaaggee 
• 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) 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 16
OOppeerraattiinngg SSyysstteemm 
• Level 3 
• Provides services to Level 4 programs 
• Translated and run at the instruction set 
architecture level (Level 2) 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 17
IInnssttrruuccttiioonn SSeett AArrcchhiitteeccttuurree 
• Level 2 
• Also known as conventional machine 
language 
• Executed by Level 1 (microarchitecture) 
program 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 18
MMiiccrrooaarrcchhiitteeccttuurree 
• Level 1 
• Interprets conventional machine instructions 
(Level 2) 
• Executed by digital hardware (Level 0) 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 19
DDiiggiittaall LLooggiicc 
• Level 0 
• CPU, constructed from digital logic gates 
• System bus 
• Memory 
• Implemented using bipolar transistors 
next: Data Representation 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 20
WWhhaatt''ss NNeexxtt 
• Welcome to Assembly Language 
• Virtual Machine Concept 
• Data Representation 
• Boolean Operations 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 21
DDaattaa RReepprreesseennttaattiioonn 
• Binary Numbers 
• Translating between binary and decimal 
• Binary Addition 
• Integer Storage Sizes 
• Hexadecimal Integers 
• Translating between decimal and hexadecimal 
• Hexadecimal subtraction 
• Signed Integers 
• Binary subtraction 
• Character Storage 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 22
BBiinnaarryy NNuummbbeerrss 
• Digits are 1 and 0 
• 1 = true 
• 0 = false 
• MSB – most significant bit 
• LSB – least significant bit 
• Bit numbering: 
MSB LSB 
1 0 1 1 0 0 1 0 1 0 0 1 1 1 0 0 
15 0 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 23
BBiinnaarryy NNuummbbeerrss 
• 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 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 24
TTrraannssllaattiinngg BBiinnaarryy ttoo DDeecciimmaall 
Weighted positional notation shows how to calculate the 
decimal value of each binary bit: 
dec = (Dn-1 ´ 2n-1) + (Dn-2 ´ 2n-2) + ... + (D1 ´ 21) + (D0 ´ 20) 
D = binary digit 
binary 00001001 = decimal 9: 
(1 ´ 23) + (1 ´ 20) = 9 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 25
TTrraannssllaattiinngg UUnnssiiggnneedd DDeecciimmaall ttoo BBiinnaarryy 
• Repeatedly divide the decimal integer by 2. Each 
remainder is a binary digit in the translated value: 
37 = 100101 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 26
BBiinnaarryy AAddddiittiioonn 
• Starting with the LSB, add each pair of digits, include 
the carry if present. 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 27
IInntteeggeerr SSttoorraaggee SSiizzeess 
Standard sizes: 
What is the largest unsigned integer that may be stored in 20 bits? 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 28
HHeexxaaddeecciimmaall IInntteeggeerrss 
Binary values are represented in hexadecimal. 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 29
TTrraannssllaattiinngg BBiinnaarryy ttoo HHeexxaaddeecciimmaall 
• Each hexadecimal digit corresponds to 4 binary bits. 
• Example: Translate the binary integer 
000101101010011110010100 to hexadecimal: 
Binary 000101101010011110010100 (2) equals hex 16A794 (16) 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 30
CCoonnvveerrttiinngg HHeexxaaddeecciimmaall ttoo DDeecciimmaall 
• Multiply each digit by its corresponding power of 16: 
dec = (D3 ´ 163) + (D2 ´ 162) + (D1 ´ 161) + (D0 ´ 160) 
• Hex 1234(16) equals (1 ´ 163) + (2 ´ 162) + (3 ´ 161) + (4 ´ 160), or 
decimal 4,660 (10) 
• Hex 3BA4 (16) equals (3 ´ 163) + (11 * 162) + (10 ´ 161) + (4 ´ 160), 
or decimal 15,268 (10) 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 31
PPoowweerrss ooff 1166 
Used when calculating hexadecimal values up to 8 digits 
long: 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 32
CCoonnvveerrttiinngg DDeecciimmaall ttoo HHeexxaaddeecciimmaall 
decimal 422 (10) = 1A6 (16) hexadecimal 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 33
HHeexxaaddeecciimmaall AAddddiittiioonn 
• Divide the sum of two digits by the number base (16). The quotient 
becomes the carry value, and the remainder is the sum digit. 
1 1 
36 28 28 6A 
42 45 58 4B 
78 6D 80 B5 
21 / 16 = 1, rem 5 
Important skill: Programmers frequently add and subtract the 
addresses of variables and instructions. 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 34
HHeexxaaddeecciimmaall SSuubbttrraaccttiioonn 
• When a borrow is required from the digit to the left, add 16 
(decimal) to the current digit's value: 
16 + 5 = 21 
-1 
C6 75 
A2 47 
24 2E 
Practice: The address of var1 is 00400020. The address of the next 
variable after var1 is 0040006A. How many bytes are used by var1? 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 35
SSiiggnneedd IInntteeggeerrss 
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 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 36
FFoorrmmiinngg tthhee TTwwoo''ss CCoommpplleemmeenntt 
• Negative numbers are stored in two's complement 
notation 
• Represents the additive Inverse 
Note that 00000001 + 11111111 = 00000000 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 37
BBiinnaarryy SSuubbttrraaccttiioonn 
• When subtracting A – B, convert B to its two's 
complement 
• Add A to (–B) 
0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 
– 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 1 
0 0 0 0 1 0 0 1 
Practice: Subtract 0101 from 1001. 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 38
FFoorrmm tthhee ttwwoo''ss ccoommpplleemmeenntt ooff aa 
hheexxaaddeecciimmaall iinntteeggeerr 
• Reverse all bits and add 1 
• Easy way: subtract the digits from 15 and add 1 
6A3D(16) → 95C2(16)→ 95C3 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 39
CCoonnvveerrtt ssiiggnneedd bbiinnaarryy ttoo ddeecciimmaall 
• If the highest bit is a 1, 
the number is in two’s 
complement 
• Form two’s 
complement 
• Convert decimal 
number and attach a 
minus sign to the 
beginning of the 
decimal integer 
Starting value 11110000(2) 
Step 1: Reverse the bits 00001111 
Step 2: Add 1 to the value 
from step 1 
00001111 
+ 1 
Step 3: Form the two’s 
complement 
00010000 
Step 4: Covert to decimal 
and attach sign 
-16(10) 
• If the highest bit is a 0, convert it to decimal integer 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 40
CCoonnvveerrtt ssiiggnneedd ddeecciimmaall ttoo bbiinnaarryy 
• Convert the absolute value 
into binary 
• If the original decimal 
number is negative, form 
the two’s complement of 
the binary number 
Starting value -16(10) 
Step 1: Convert the 
absolute value into 
binary 
00010000(2) 
Step 2: Reverse the bits 11101111(2) 
Step 3: Form the two’s 
complement 
11110000(2) 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 41
CCoonnvveerrtt ssiiggnneedd ddeecciimmaall ttoo hheexxaaddeecciimmaall 
• Convert the absolute 
value into hexadecimal 
• If the original decimal 
number is negative, 
form the two’s 
complement of the 
hexadecimal number 
Starting value -43(10) 
Step 1: Convert the 
absolute value into 
hexadecimal 
2B(16) 
Step 2: Form the 
two’s complement 
D5(16) 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 42
CCoonnvveerrtt ssiiggnneedd hheexxaaddeecciimmaall ttoo ddeecciimmaall 
• If the hexadecimal integer 
is negative, form it’s two’s 
complement otherwise 
retain the integer as is 
• Convert it to decimal 
number. If the original 
value is negative, attach a 
minus sign to the 
beginning of the decimal 
integer 
Starting value D5(16) 
Step 1: Form the 
two’s complement 
2B(16) 
Step 4: Covert to 
decimal and 
attach sign 
- 43(10) 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 43
RRaannggeess ooff SSiiggnneedd IInntteeggeerrss 
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? 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 44
CChhaarraacctteerr SSttoorraaggee 
• Character sets 
• 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 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 45
NNuummeerriicc DDaattaa RReepprreesseennttaattiioonn 
• pure binary 
• can be calculated directly 
• ASCII binary 
• string of digits: "01010101" 
• ASCII decimal 
• string of digits: "65" 
• ASCII hexadecimal 
• string of digits: "9C" 
next: Boolean Operations 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 46
WWhhaatt''ss NNeexxtt 
• Welcome to Assembly Language 
• Virtual Machine Concept 
• Data Representation 
• Boolean Operations 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 47
BBoooolleeaann OOppeerraattiioonnss 
• NOT 
• AND 
• OR 
• Operator Precedence 
• Truth Tables 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 48
BBoooolleeaann AAllggeebbrraa 
• Based on symbolic logic, designed by George Boole 
• Boolean expressions created from: 
• NOT, AND, OR 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 49
NNOOTT 
• Inverts (reverses) a boolean value 
• Truth table for Boolean NOT operator: 
Digital gate diagram for NOT: 
NOT 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 50
AANNDD 
• Truth table for Boolean AND operator: 
Digital gate diagram for AND: 
AND 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 51
OORR 
• Truth table for Boolean OR operator: 
Digital gate diagram for OR: 
OR 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 52
OOppeerraattoorr PPrreecceeddeennccee 
• Examples showing the order of operations: 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 53
TTrruutthh TTaabblleess ((11 ooff 33)) 
• A Boolean function has one or more Boolean inputs, 
and returns a single Boolean output. 
• A truth table shows all the inputs and outputs of a 
Boolean function 
Example: ØX Ú Y 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 54
TTrruutthh TTaabblleess ((22 ooff 33)) 
• Example: X Ù ØY 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 55
TTrruutthh TTaabblleess ((33 ooff 33)) 
• Example: (Y Ù S) Ú (X Ù ØS) 
Two-input multiplexer 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 56
SSuummmmaarryy 
• Assembly language helps you learn how software is 
constructed at the lowest levels 
• Assembly language has a one-to-one relationship 
with machine language 
• Each layer in a computer's architecture is an 
abstraction of a machine 
• layers can be hardware or software 
• Boolean expressions are essential to the design of 
computer hardware and software 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 57
5544 6688 6655 2200 4455 66EE 6644 
What do these numbers represent? 
Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 58

More Related Content

PPT
Chapt 01 basic concepts
PDF
Assembly Language for x86 Processors 7th Edition Chapter 1: Basic Concepts
PDF
Assembly Language for x86 Processors 7th Edition Chapter 2 : x86 Processor Ar...
PPT
Chapt 01 Assembly Language
PPT
Porting To Symbian
PDF
Assembly Langauge Chap 1
PPT
1. over view and history of c
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
Chapt 01 basic concepts
Assembly Language for x86 Processors 7th Edition Chapter 1: Basic Concepts
Assembly Language for x86 Processors 7th Edition Chapter 2 : x86 Processor Ar...
Chapt 01 Assembly Language
Porting To Symbian
Assembly Langauge Chap 1
1. over view and history of c
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...

Similar to Chapt 01 (20)

PPT
chapt_01.ppt
PPT
chapt_01.ppt
PPT
chapt_01Assembly_Language by Irvine_7_edition.ppt
PPT
Chapt 02 ia-32 processer architecture
PDF
lec01_introanalytics-for-the-internet-of-things-iot-intelligent-analytics-for...
PDF
chapt_01.pdf
PPT
chap3lec5.pptgfhgfhghghgfhgfhgfhfghgfhfg
PPTX
C Programming Lab_Program_Presentation__a
PPT
chapt_02.ppt PN COAL CH 03 SLIDES OF ASSEMBLY LANGUAGRE
PPTX
l1-introduction_to_computers_and_c_programming.pptx
PPT
chapter 1 intrYour score increases as you pick a category, fill out a long de...
PPTX
Introduction to Computer Networks and Networking
PPTX
Introduction of C Programming
PPTX
CSE_1201_Lecture_1_Introduction_to_Programming_0fd134f8149173dfa0821f1575f733...
PPTX
Computer Programming In C.pptx
PDF
A Brief History of Programming Languages.pdf
PDF
Introduction to Processor Design in System Verilog
PDF
Solution Manual for C++ How to Program: Late Objects Version, 7/E 7th Edition...
PPT
chapt_08.pptdsfdfdfdsffsdffsdfsdfsdfsdfsdfsdfsdf
PPTX
Programming language
chapt_01.ppt
chapt_01.ppt
chapt_01Assembly_Language by Irvine_7_edition.ppt
Chapt 02 ia-32 processer architecture
lec01_introanalytics-for-the-internet-of-things-iot-intelligent-analytics-for...
chapt_01.pdf
chap3lec5.pptgfhgfhghghgfhgfhgfhfghgfhfg
C Programming Lab_Program_Presentation__a
chapt_02.ppt PN COAL CH 03 SLIDES OF ASSEMBLY LANGUAGRE
l1-introduction_to_computers_and_c_programming.pptx
chapter 1 intrYour score increases as you pick a category, fill out a long de...
Introduction to Computer Networks and Networking
Introduction of C Programming
CSE_1201_Lecture_1_Introduction_to_Programming_0fd134f8149173dfa0821f1575f733...
Computer Programming In C.pptx
A Brief History of Programming Languages.pdf
Introduction to Processor Design in System Verilog
Solution Manual for C++ How to Program: Late Objects Version, 7/E 7th Edition...
chapt_08.pptdsfdfdfdsffsdffsdfsdfsdfsdfsdfsdfsdf
Programming language
Ad

Chapt 01

  • 1. AAsssseemmbbllyy LLaanngguuaaggee ffoorr IInntteell--BBaasseedd CCoommppuutteerrss,, 55tthh EEddiittiioonn Kip Irvine Chapter 1: Basic Concepts Slides prepared by the author Revision date: June 3, 2006 (c) Pearson Education, 2006-2007. All rights reserved. You may modify and copy this slide show for your personal use, or for use in the classroom, as long as this copyright statement, the author's name, and the title are not changed.
  • 2. OObbjjeeccttiivveess • Understand common applications of assembly language • Understand what an assembler does • Understand hardware and software requirements for the book • Know the basic history of PC Assemblers • Differentiate between protected mode and real-address mode • Learn basic principles of computer architecture as applied to the Intel IA-32 processor family Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 2
  • 3. OObbjjeeccttiivveess ((ccoonnttiinnuuee)) • Learn how to recognize and convert boolean and hexadecimal integers • Perform binary addition and subtraction • Understand basic boolean operations • Differentiate between signed and unsigned binary integers • Understand ASCII character representation Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 3
  • 4. CChhaapptteerr OOvveerrvviieeww • Welcome to Assembly Language • Virtual Machine Concept • Data Representation • Boolean Operations Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 4
  • 5. WWeellccoommee ttoo AAsssseemmbbllyy LLaanngguuaaggee • Some Good Questions to Ask • Assembly Language Applications Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 5
  • 6. QQuueessttiioonnss ttoo AAsskk • Why am I learning Assembly Language? • What background should I have? • What is an assembler? • What hardware/software do I need? • What types of programs will I create? • What do I get with this book? • What will I learn? Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 6
  • 7. WWeellccoommee ttoo AAsssseemmbbllyy LLaanngguuaaggee ((ccoonntt)) • How does assembly language (AL) relate to machine language? • How do C++ and Java relate to AL? • Is AL portable? • Why learn AL? Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 7
  • 8. AAsssseemmbbllyy LLaanngguuaaggee AApppplliiccaattiioonnss • Some representative types of applications: • Business application for single platform • Hardware device driver • Business application for multiple platforms • Embedded systems & computer games (see next panel) Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 8
  • 9. CCoommppaarriinngg AASSMM ttoo HHiigghh--LLeevveell LLaanngguuaaggeess Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 9
  • 10. WWhhaatt''ss NNeexxtt • Welcome to Assembly Language • Virtual Machine Concept • Data Representation • Boolean Operations Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 10
  • 11. VViirrttuuaall MMaacchhiinnee CCoonncceepptt • Virtual Machines • Specific Machine Levels Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 11
  • 12. VViirrttuuaall MMaacchhiinneess • 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 Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 12
  • 13. TTrraannssllaattiinngg LLaanngguuaaggeess 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 Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 13
  • 14. SSppeecciiffiicc MMaacchhiinnee LLeevveellss (descriptions of individual levels follow . . . ) Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 14
  • 15. HHiigghh--LLeevveell LLaanngguuaaggee • Level 5 • Application-oriented languages • C++, Java, Pascal, Visual Basic . . . • Programs compile into assembly language (Level 4) Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 15
  • 16. AAsssseemmbbllyy LLaanngguuaaggee • 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) Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 16
  • 17. OOppeerraattiinngg SSyysstteemm • Level 3 • Provides services to Level 4 programs • Translated and run at the instruction set architecture level (Level 2) Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 17
  • 18. IInnssttrruuccttiioonn SSeett AArrcchhiitteeccttuurree • Level 2 • Also known as conventional machine language • Executed by Level 1 (microarchitecture) program Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 18
  • 19. MMiiccrrooaarrcchhiitteeccttuurree • Level 1 • Interprets conventional machine instructions (Level 2) • Executed by digital hardware (Level 0) Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 19
  • 20. DDiiggiittaall LLooggiicc • Level 0 • CPU, constructed from digital logic gates • System bus • Memory • Implemented using bipolar transistors next: Data Representation Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 20
  • 21. WWhhaatt''ss NNeexxtt • Welcome to Assembly Language • Virtual Machine Concept • Data Representation • Boolean Operations Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 21
  • 22. DDaattaa RReepprreesseennttaattiioonn • Binary Numbers • Translating between binary and decimal • Binary Addition • Integer Storage Sizes • Hexadecimal Integers • Translating between decimal and hexadecimal • Hexadecimal subtraction • Signed Integers • Binary subtraction • Character Storage Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 22
  • 23. BBiinnaarryy NNuummbbeerrss • Digits are 1 and 0 • 1 = true • 0 = false • MSB – most significant bit • LSB – least significant bit • Bit numbering: MSB LSB 1 0 1 1 0 0 1 0 1 0 0 1 1 1 0 0 15 0 Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 23
  • 24. BBiinnaarryy NNuummbbeerrss • 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 Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 24
  • 25. TTrraannssllaattiinngg BBiinnaarryy ttoo DDeecciimmaall Weighted positional notation shows how to calculate the decimal value of each binary bit: dec = (Dn-1 ´ 2n-1) + (Dn-2 ´ 2n-2) + ... + (D1 ´ 21) + (D0 ´ 20) D = binary digit binary 00001001 = decimal 9: (1 ´ 23) + (1 ´ 20) = 9 Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 25
  • 26. TTrraannssllaattiinngg UUnnssiiggnneedd DDeecciimmaall ttoo BBiinnaarryy • Repeatedly divide the decimal integer by 2. Each remainder is a binary digit in the translated value: 37 = 100101 Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 26
  • 27. BBiinnaarryy AAddddiittiioonn • Starting with the LSB, add each pair of digits, include the carry if present. Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 27
  • 28. IInntteeggeerr SSttoorraaggee SSiizzeess Standard sizes: What is the largest unsigned integer that may be stored in 20 bits? Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 28
  • 29. HHeexxaaddeecciimmaall IInntteeggeerrss Binary values are represented in hexadecimal. Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 29
  • 30. TTrraannssllaattiinngg BBiinnaarryy ttoo HHeexxaaddeecciimmaall • Each hexadecimal digit corresponds to 4 binary bits. • Example: Translate the binary integer 000101101010011110010100 to hexadecimal: Binary 000101101010011110010100 (2) equals hex 16A794 (16) Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 30
  • 31. CCoonnvveerrttiinngg HHeexxaaddeecciimmaall ttoo DDeecciimmaall • Multiply each digit by its corresponding power of 16: dec = (D3 ´ 163) + (D2 ´ 162) + (D1 ´ 161) + (D0 ´ 160) • Hex 1234(16) equals (1 ´ 163) + (2 ´ 162) + (3 ´ 161) + (4 ´ 160), or decimal 4,660 (10) • Hex 3BA4 (16) equals (3 ´ 163) + (11 * 162) + (10 ´ 161) + (4 ´ 160), or decimal 15,268 (10) Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 31
  • 32. PPoowweerrss ooff 1166 Used when calculating hexadecimal values up to 8 digits long: Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 32
  • 33. CCoonnvveerrttiinngg DDeecciimmaall ttoo HHeexxaaddeecciimmaall decimal 422 (10) = 1A6 (16) hexadecimal Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 33
  • 34. HHeexxaaddeecciimmaall AAddddiittiioonn • Divide the sum of two digits by the number base (16). The quotient becomes the carry value, and the remainder is the sum digit. 1 1 36 28 28 6A 42 45 58 4B 78 6D 80 B5 21 / 16 = 1, rem 5 Important skill: Programmers frequently add and subtract the addresses of variables and instructions. Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 34
  • 35. HHeexxaaddeecciimmaall SSuubbttrraaccttiioonn • When a borrow is required from the digit to the left, add 16 (decimal) to the current digit's value: 16 + 5 = 21 -1 C6 75 A2 47 24 2E Practice: The address of var1 is 00400020. The address of the next variable after var1 is 0040006A. How many bytes are used by var1? Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 35
  • 36. SSiiggnneedd IInntteeggeerrss 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 Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 36
  • 37. FFoorrmmiinngg tthhee TTwwoo''ss CCoommpplleemmeenntt • Negative numbers are stored in two's complement notation • Represents the additive Inverse Note that 00000001 + 11111111 = 00000000 Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 37
  • 38. BBiinnaarryy SSuubbttrraaccttiioonn • When subtracting A – B, convert B to its two's complement • Add A to (–B) 0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 – 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 1 0 0 0 0 1 0 0 1 Practice: Subtract 0101 from 1001. Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 38
  • 39. FFoorrmm tthhee ttwwoo''ss ccoommpplleemmeenntt ooff aa hheexxaaddeecciimmaall iinntteeggeerr • Reverse all bits and add 1 • Easy way: subtract the digits from 15 and add 1 6A3D(16) → 95C2(16)→ 95C3 Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 39
  • 40. CCoonnvveerrtt ssiiggnneedd bbiinnaarryy ttoo ddeecciimmaall • If the highest bit is a 1, the number is in two’s complement • Form two’s complement • Convert decimal number and attach a minus sign to the beginning of the decimal integer Starting value 11110000(2) Step 1: Reverse the bits 00001111 Step 2: Add 1 to the value from step 1 00001111 + 1 Step 3: Form the two’s complement 00010000 Step 4: Covert to decimal and attach sign -16(10) • If the highest bit is a 0, convert it to decimal integer Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 40
  • 41. CCoonnvveerrtt ssiiggnneedd ddeecciimmaall ttoo bbiinnaarryy • Convert the absolute value into binary • If the original decimal number is negative, form the two’s complement of the binary number Starting value -16(10) Step 1: Convert the absolute value into binary 00010000(2) Step 2: Reverse the bits 11101111(2) Step 3: Form the two’s complement 11110000(2) Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 41
  • 42. CCoonnvveerrtt ssiiggnneedd ddeecciimmaall ttoo hheexxaaddeecciimmaall • Convert the absolute value into hexadecimal • If the original decimal number is negative, form the two’s complement of the hexadecimal number Starting value -43(10) Step 1: Convert the absolute value into hexadecimal 2B(16) Step 2: Form the two’s complement D5(16) Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 42
  • 43. CCoonnvveerrtt ssiiggnneedd hheexxaaddeecciimmaall ttoo ddeecciimmaall • If the hexadecimal integer is negative, form it’s two’s complement otherwise retain the integer as is • Convert it to decimal number. If the original value is negative, attach a minus sign to the beginning of the decimal integer Starting value D5(16) Step 1: Form the two’s complement 2B(16) Step 4: Covert to decimal and attach sign - 43(10) Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 43
  • 44. RRaannggeess ooff SSiiggnneedd IInntteeggeerrss 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? Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 44
  • 45. CChhaarraacctteerr SSttoorraaggee • Character sets • 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 Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 45
  • 46. NNuummeerriicc DDaattaa RReepprreesseennttaattiioonn • pure binary • can be calculated directly • ASCII binary • string of digits: "01010101" • ASCII decimal • string of digits: "65" • ASCII hexadecimal • string of digits: "9C" next: Boolean Operations Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 46
  • 47. WWhhaatt''ss NNeexxtt • Welcome to Assembly Language • Virtual Machine Concept • Data Representation • Boolean Operations Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 47
  • 48. BBoooolleeaann OOppeerraattiioonnss • NOT • AND • OR • Operator Precedence • Truth Tables Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 48
  • 49. BBoooolleeaann AAllggeebbrraa • Based on symbolic logic, designed by George Boole • Boolean expressions created from: • NOT, AND, OR Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 49
  • 50. NNOOTT • Inverts (reverses) a boolean value • Truth table for Boolean NOT operator: Digital gate diagram for NOT: NOT Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 50
  • 51. AANNDD • Truth table for Boolean AND operator: Digital gate diagram for AND: AND Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 51
  • 52. OORR • Truth table for Boolean OR operator: Digital gate diagram for OR: OR Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 52
  • 53. OOppeerraattoorr PPrreecceeddeennccee • Examples showing the order of operations: Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 53
  • 54. TTrruutthh TTaabblleess ((11 ooff 33)) • A Boolean function has one or more Boolean inputs, and returns a single Boolean output. • A truth table shows all the inputs and outputs of a Boolean function Example: ØX Ú Y Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 54
  • 55. TTrruutthh TTaabblleess ((22 ooff 33)) • Example: X Ù ØY Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 55
  • 56. TTrruutthh TTaabblleess ((33 ooff 33)) • Example: (Y Ù S) Ú (X Ù ØS) Two-input multiplexer Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 56
  • 57. SSuummmmaarryy • Assembly language helps you learn how software is constructed at the lowest levels • Assembly language has a one-to-one relationship with machine language • Each layer in a computer's architecture is an abstraction of a machine • layers can be hardware or software • Boolean expressions are essential to the design of computer hardware and software Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 57
  • 58. 5544 6688 6655 2200 4455 66EE 6644 What do these numbers represent? Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. Web site Examples 58