0% found this document useful (0 votes)
52 views8 pages

Introduction To Assembly Langauge Programming

Introduction to Assembly Langauge Programming

Uploaded by

justin naitira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views8 pages

Introduction To Assembly Langauge Programming

Introduction to Assembly Langauge Programming

Uploaded by

justin naitira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Assembly Language Programming September 15

Chapter Overview
Assembly Language for x86 Processors
6th Edition
Kip Irvine • Welcome to Assembly Language
• Virtual Machine Concept
• Data Representation
Chapter 1: Basic Concepts • Boolean Operations

Slides prepared by the author


Revision date: 2/15/2010

(c) Pearson Education, 2010. 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. Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 2

Comparing ASM to High-Level Languages What's Next

• Welcome to Assembly Language


• Virtual Machine Concept
• Data Representation
• Boolean Operations

Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 3 Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 4

Virtual Machine Concept Virtual Machines

• Tanenbaum: Virtual machine concept


• Virtual Machines • Programming Language analogy:
• Specific Machine Levels • 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 6/e, 2010. 5 Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 6

Introduction: Obuhuma J. 1
Assembly Language Programming September 15

Translating Languages Specific Machine Levels

English: Display the sum of A times B plus C.

C++: cout << (A * B + C);

Assembly Language: Intel Machine Language:


mov eax,A A1 00000000
mul B F7 25 00000004
add eax,C
03 05 00000008
call WriteInt (descriptions of individual levels
E8 00500000 follow . . . )

Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 7 Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 8

High-Level Language Assembly Language

• Level 4 • Level 3
• Application-oriented languages • Instruction mnemonics that have a one-to-
• C++, Java, Pascal, Visual Basic . . . one correspondence to machine language
• Programs compile into assembly language • Programs are translated into Instruction Set
(Level 4) Architecture Level - machine language
(Level 2)

Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 9 Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 10

Instruction Set Architecture (ISA) Digital Logic

• Level 2 • Level 1
• Also known as conventional machine • CPU, constructed from digital logic gates
language • System bus
• Executed by Level 1 (Digital Logic) • Memory
• Implemented using bipolar transistors

next: Data Representation

Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 11 Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 12

Introduction: Obuhuma J. 2
Assembly Language Programming September 15

What's Next Data Representation


• Binary Numbers
• Welcome to Assembly Language • Translating between binary and decimal
• Virtual Machine Concept • Binary Addition
• Data Representation • Integer Storage Sizes
• Boolean Operations • Hexadecimal Integers
• Translating between decimal and hexadecimal
• Hexadecimal subtraction
• Signed Integers
• Binary subtraction
• Character Storage

Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 13 Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 14

Binary Numbers Binary Numbers

• Each digit (bit) is either 1 or 0 1 1 1 1 1 1 1 1


• Digits are 1 and 0 • Each bit represents a power of 2: 27 26 25 24 23 22 21 20

• 1 = true
• 0 = false
• MSB – most significant bit
• LSB – least significant bit
Every binary
MSB LSB number is a
• Bit numbering: 1011001010011100 sum of powers
15 0 of 2

Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 15 Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 16

Translating Binary to Decimal Translating Unsigned Decimal to Binary


• Repeatedly divide the decimal integer by 2. Each
Weighted positional notation shows how to calculate the remainder is a binary digit in the translated value:
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

37 = 100101

Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 17 Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 18

Introduction: Obuhuma J. 3
Assembly Language Programming September 15

Binary Addition Integer Storage Sizes


• Starting with the LSB, add each pair of digits, include
byte 8

word 16
Standard sizes:
the carry if present. doubleword 32

quadword 64

carry: 1

0 0 0 0 0 1 0 0 (4)

+ 0 0 0 0 0 1 1 1 (7)

0 0 0 0 1 0 1 1 (11)
bit position: 7 6 5 4 3 2 1 0

What is the largest unsigned integer that may be stored in 20 bits?

Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 19 Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 20

Hexadecimal Integers Translating Binary to Hexadecimal


Binary values are represented in hexadecimal.
• Each hexadecimal digit corresponds to 4 binary bits.
• Example: Translate the binary integer
000101101010011110010100 to hexadecimal:

Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 21 Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 22

Converting Hexadecimal to Decimal Powers of 16

• Multiply each digit by its corresponding power of 16: Used when calculating hexadecimal values up to 8 digits
dec = (D3  163) + (D2  162) + (D1  161) + (D0  160) long:

• 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.

Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 23 Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 24

Introduction: Obuhuma J. 4
Assembly Language Programming September 15

Converting Decimal to Hexadecimal Hexadecimal Addition

• 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

decimal 422 = 1A6 hexadecimal


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 6/e, 2010. 25 Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 26

Hexadecimal Subtraction Signed Integers

• When a borrow is required from the digit to the left, add 16 The highest bit indicates the sign. 1 = negative,
(decimal) to the current digit's value: 0 = positive

sign bit
16 + 5 = 21

1 1 1 1 0 1 1 0
Negative
-1
C6 75 0 0 0 0 1 0 1 0 Positive
A2 47
24 2E

If the highest digit of a hexadecimal integer is > 7, the value is


Practice: The address of var1 is 00400020. The address of the next
variable after var1 is 0040006A. How many bytes are used by var1?
negative. Examples: 8A, C5, A2, 9D

Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 27 Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 28

Forming the Two's Complement Binary Subtraction


• Negative numbers are stored in two's complement • When subtracting A – B, convert B to its two's
notation complement
• Represents the additive Inverse • Add A to (–B)

00001100 00001100
– 00000011 11111101
00001001

Note that 00000001 + 11111111 = 00000000 Practice: Subtract 0101 from 1001.

Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 29 Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 30

Introduction: Obuhuma J. 5
Assembly Language Programming September 15

Learn How To Do the Following: Ranges of Signed Integers

The highest bit is reserved for the sign. This limits the range:
• 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

Practice: What is the largest positive value that may be stored in 20 bits?

Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 31 Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 32

Character Storage Numeric Data Representation


• Character sets
• pure binary
• Standard ASCII (0 – 127)
• can be calculated directly
• Extended ASCII (0 – 255)
• ANSI (0 – 255)
• ASCII binary
• Unicode (0 – 65,535)
• string of digits: "01010101"

• Null-terminated String • ASCII decimal


• Array of characters followed by a null byte • string of digits: "65"

• Using the ASCII table • ASCII hexadecimal


• back inside cover of book • string of digits: "9C"

next: Boolean Operations

Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 33 Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 34

What's Next Boolean Operations

• Welcome to Assembly Language • NOT


• Virtual Machine Concept • AND
• Data Representation • OR
• Boolean Operations • Operator Precedence
• Truth Tables

Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 35 Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 36

Introduction: Obuhuma J. 6
Assembly Language Programming September 15

Boolean Algebra NOT

• Based on symbolic logic, designed by George Boole • Inverts (reverses) a boolean value
• Boolean expressions created from: • Truth table for Boolean NOT operator:
• NOT, AND, OR

Digital gate diagram for NOT:

NOT

Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 37 Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 38

AND OR
• Truth table for Boolean AND operator: • Truth table for Boolean OR operator:

Digital gate diagram for AND: Digital gate diagram for OR:

AND OR

Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 39 Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 40

Operator Precedence Truth Tables (1 of 3)


• A Boolean function has one or more Boolean inputs,
• Examples showing the order of operations: 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 6/e, 2010. 41 Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 42

Introduction: Obuhuma J. 7
Assembly Language Programming September 15

Truth Tables (2 of 3) Truth Tables (3 of 3)


• Example: X  Y • Example: (Y  S)  (X  S)

X
mux Z
Y

Two-input multiplexer

Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 43 Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, 2010. 44

Introduction: Obuhuma J. 8

You might also like