You are on page 1of 12

Basic Concepts Chapter Overview

• Welcome to Assembly
Language
• Virtual Machine Concept
• Data Representation
Javed Ahmed Shahani
• Boolean Operations

Welcome to Assembly Language Some Good Questions to Ask


• Some Good Questions to Ask • Why am I taking this course (reading this
book)?
• Assembly Language Applications • 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?

3 4

1
Welcome to Assembly Language Assembly Language Applications
(cont)

• How does assembly language (AL) relate to • Some representative types of applications:
– Business application for single platform
machine language?
– Hardware device driver
• How do C++ and Java relate to AL? – Business application for multiple platforms
• Is AL portable? – Embedded systems & computer games

• Why learn AL?


(see next panel)

5 6

Comparing ASM to High-Level Languages Virtual Machine Concept


• Virtual Machines
• Specific Machine Levels

7 8

2
Virtual Machines Translating Languages
• Tanenbaum: Virtual machine concept English: Display the sum of A times B plus C.
• Programming Language analogy:
– Each computer has a native machine language (language L0) that
runs directly on its hardware C++: cout << (A * B + C);
– A more human-friendly language is usually constructed above
machine language, called Language L1

• Programs written in L1 can run two different ways: Assembly Language: Intel Machine Language:
• Interpretation – L0 program interprets and executes L1 mov eax,A A1 00000000
instructions one by one mul B F7 25 00000004
• Translation – L1 program is completely translated into an L0 add eax,C
03 05 00000008
program, which then runs on the computer hardware call WriteInt
E8 00500000

9 10

Specific Machine Levels High-Level Language


High-Level Language Level 5 • Level 5
Assembly Language Level 4 • Application-oriented languages
– C++, Java, Pascal, Visual Basic . . .
Operating System
Level 3
• Programs compile into assembly
Instruction Set
Architecture Level 2 language (Level 4)
Microarchitecture Level 1

Digital Logic Level 0 (descriptions of individual levels


follow . . . )

11 12

3
Assembly Language Operating System
• Level 4
• Level 3
• Instruction mnemonics that have a one-to-
one correspondence to machine language • Provides services to Level 4 programs
• Calls functions written at the operating • Translated and run at the instruction
system level (Level 3)
• Programs are translated into machine set architecture level (Level 2)
language (Level 2)

13 14

Instruction Set Architecture Microarchitecture


• Level 2 • Level 1
• Also known as conventional • Interprets conventional machine
machine language instructions (Level 2)
• Executed by Level 1 • Executed by digital hardware (Level
(microarchitecture) program 0)

15 16

4
Digital Logic Data Representation
• Binary Numbers
• Level 0 – Translating between binary and decimal
• CPU, constructed from digital logic • Binary Addition
gates • Integer Storage Sizes
• System bus • Hexadecimal Integers
• Memory – Translating between decimal and hexadecimal
• Implemented using bipolar transistors – Hexadecimal subtraction
• Signed Integers
– Binary subtraction
• Character Storage
next: Data Representation

17 18

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: 1 0 1 1 0 0 1 0 1 0 0 1 1 1 0 0 sum of powers
15 0 of 2

19 20

5
Translating Binary to Decimal Translating Unsigned Decimal to Binary
• Repeatedly divide the decimal integer by 2. Each
Weighted positional notation shows how to remainder is a binary digit in the translated value:
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
37 = 100101

21 22

Binary Addition Integer Storage Sizes


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

word
8

16
Standard sizes:
include 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?

23 24

6
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:

25 26

Converting Hexadecimal to Decimal


Powers of 16
• Multiply each digit by its corresponding Used when calculating hexadecimal values up to 8 digits
long:
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.

27 28

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

29 30

Hexadecimal Subtraction Signed Integers


• When a borrow is required from the digit to the left, add 10h to
The highest bit indicates the sign. 1 = negative,
the current digit's value: 0 = positive
sign bit
10h + 5 = 15h

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

31 32

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

00001100 00001100
– 00000011 11111101
Note that 00000001 + 11111111 = 00000000 01001.
Practice: Subtract 0101 from 0001001

33 34

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?

35 36

9
Character Storage Numeric Data Representation
• Character sets
• pure binary
– Standard ASCII (0 – 127) – can be calculated directly
– Extended ASCII (0 – 255) • ASCII binary
– ANSI (0 – 255) – string of digits: "01010101"
– Unicode (0 – 65,535) • ASCII decimal
• Null-terminated String – string of digits: "65"
– Array of characters followed by a null byte • ASCII hexadecimal
• Using the ASCII table – string of digits: "9C"
– back inside cover of book
next: Boolean Operations

37 38

Boolean Operations Boolean Algebra


• Based on symbolic logic, designed by George
• NOT Boole
• AND • Boolean expressions created from:
– NOT, AND, OR
• OR
• Operator Precedence
• Truth Tables

39 40

10
NOT AND
• Inverts (reverses) a boolean value • Truth table for Boolean AND operator:
• Truth table for Boolean NOT operator:

Digital gate diagram for NOT:


Digital gate diagram for AND:

NOT
AND

41 42

OR Operator Precedence
• Truth table for Boolean OR operator:
• Examples showing the order of operations:

Digital gate diagram for OR:

OR

43 44

11
Truth Tables (1 of 3) Truth Tables (2 of 3)
• A Boolean function has one or more Boolean • Example: X  Y
inputs, and returns a single Boolean output.
• A truth table shows all the inputs and outputs of
a Boolean function

Example: X  Y

45 46

Truth Tables (3 of 3)
• Example: (Y  S)  (X  S)

X
mux Z
Y

Two-input multiplexer

47

12

You might also like