1.
Basic Concepts
Assembly Language for x86 Processors
Slides by the Autor Kip R. Irvine
Edited by Fernando H. Calderon
Chapter Overview
• Welcome to Assembly Language
• Virtual Machine Concept
• Data Representation
• Boolean Operations
Questions to Ask
• 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 will I learn?
• How does Assembly Language (AL) relate to machine language?
• How do C++ and Java Relate to al?
Assembly Language Applications
• Some representative types of applications:
• Business application for single platform
• Hardware device driver
• Business application for multiple platforms
• Embedded systems and computer games
Comparing ASM to High-Level Languages
Virtual Machine Concept
• Virtual Machines
• Specific Machine Levels
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
Virtual Machine Concept
• Java programming language is based on the virtual machine concept.
• A program written in the Java language is translated by a Java compiler into
Java byte code.
• The latter is a low-level language interprets and executed at run time by a
program known as a Java Virtual Machine (JVM).
• The JVM has been implemented on many different computer systems, making
Java programs relatively system independent.
Translating Languages
Specific Machine Levels
Digital Logic
• Level 1
• CPU, constructed from digital logic gates
• System Bus
• Memory
• Implemented using bipolar transistors
Instruction Set Architecture
• Level 2
• Also known as Conventional Machine Language
• Each machine-language instruction is executed either directly by the
computer’s hardware or by a program embedded in the
microprocessor chip called a microprogram
Assembly Language
• Level 3
• Instruction ”words” that have a one-to-one correspondence to
machine language
• Programs are translated into Instruction Set Architecture Level –
machine language (level 2)
High-Level Language
• Level 4
• Application-oriented languages
• C, C++, Java…
• Programs compile into assembly language (Level 3)
Data Representation
Data Representation
• 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
Binary Numbers
• Digits are 1 and 0
• 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
Binary Numbers
Translating Binary to Decimal
Weighted positional notation shows how to calculate the decimal value
of each binary bit:
𝑑𝑒𝑐 = 𝐷𝑛−1 × 2𝑛−1 + 𝐷𝑛−2 × 2𝑛−2 … + 𝐷1 × 21 + 𝐷0 × 20
D = binary digit
Binary 00001001 = decimal 9:
1 × 23 + 1 × 20 = 9
Translating Unsigned Decimal to Binary
• Repeatedly divide the decimal integer by 2. Each remainder in a
binary digit in the translated value:
37 = 100101
Binary Addition
• Starting with the LSB, add each pair of digits, include the carry if
present.
Integer Storage Sizes
Standard sizes:
Hexadecimal Integers
Binary values are represented in hexadecimal.
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:
𝑑𝑒𝑐 = 𝐷3 × 163 + 𝐷2 + 162 + 𝐷1 × 161 + 𝐷0 × 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
Powers of 16
• Used when calculating the hexadecimal values op to 8 digits long:
Converting Decimal to Hexadecimal
Decimal 422 = 1A6 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.
Hexadecimal Subtraction
• When a borrow is required from the digit to the left, add 16 (decimal)
to the current digit’s value:
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
Signed Integers
Forming the Two's Complement
• Negative numbers are stored in two's complement notation
• Represents the additive Inverse
• Note that 00000001 + 11111111 = 00000000
Signed Integers
• Binary Subtraction
• When subtracting A – B, convert B to its two's complement
• Add A to (–B)
00001100 00001100
–00000011 +11111101
00001001
Character Storage
• 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
• 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"
Range of Signed Integers
• Ranges of Signed Integers
• The highest bit is reserved for the sign. This limits the range:
Boolean Operations
Boolean Operations
• Boolean algebra defines a set of operations on the values true and
false.
• Boolean expression involves a Boolean operator and one or more
operands.
• Boolean Algebra
• Based on symbolic logic,
designed by George Boole
• Boolean expressions
created from: NOT, AND, OR
Boolean Operations
NOT AND
• Inverts (reverses) a boolean • Truth table for Boolean AND
value operator:
• Truth table for Boolean NOT
operator:
• Digital gate diagram for AND:
• Digital gate diagram for NOT:
Boolean Operations
OR
• Truth table for Boolean OR
operator:
• Digital gate diagram for OR:
Boolean Operations
Operator Proecedence
• The NOT operator has the highest precedence followed by AND and
OR.
• To avoid ambiguity, use parentheses to force the initial evaluation of
an expression.
• Examples showing the order of operations:
Truth Tables for Boolean Functions
• 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
Truth Table for Boolean Functions
• Example: X ∨ ¬Y
Truth Table for Boolean Functions
• Example: (Y ∧ S) ∨ (X ∧ ¬S)
This Boolean function describes a
multiplexer: two-input multiplexer