Microprocessors

66322
Dr. Aladdin Masri
Course Outline
• Introduction to Microprocessor and Computer
• The Microprocessor and its Architecture
• Addressing modes
• Data Movement Instructions
• Arithmetic and Logic Instructions
• Program Control Instructions
• Using Assembly Language With C/C++
Microprocessors (66322) Dr. Aladdin Masri 2
Text Book and Grades
• “The Intel Microprocessors”, Barry B. Brey
• “Assembly Language for Intel-Based
Computers”, Kip R. Irvine
• First Exam 20%
• Second Exam 20%
• Quizzes and HW 10%
• Final Exam 50%
Microprocessors (66322) Dr. Aladdin Masri 3
Microprocessors (66322) Dr. Aladdin Masri 4
Introduction to Microprocessor
and Computer
1–1 What is a computer?
• A programmable electronic device that can
store, retrieve, and process data.
• A machine that manipulates data according to
a list of instructions.
• Classification of Computers
– Personal computers
– Mainframes
– Supercomputers
– Dedicated controllers – Embedded controllers
Microprocessors (66322) Dr. Aladdin Masri 5
What is a computer?
• Central Processing Unit (CPU)
• Memory
• Input / Output (I/O) circuitry
• Buses:
– Address bus
– Data bus
– Control bus
Microprocessors (66322) Dr. Aladdin Masri 6
What is a microprocessor?
• Also known as central processing unit – CPU
• An integrated circuit built on a tiny piece of silicon
• Contains thousands, or even millions, of transistors,
which are interconnected via superfine traces of
aluminum
• The transistors work together to store and manipulate
data so that the microprocessor can perform a wide
variety of useful functions
• The particular functions a microprocessor performs are
dictated by software
– fetch, decode, and then executes binary instructions in a
sequence stored in memory
Microprocessors (66322) Dr. Aladdin Masri 7
What is a microprocessor?
• One most common task microprocessors perform is to serve as
“brains” inside personal computers (PC), but they deliver
"intelligence" to other devices as well.
• Contains:
– ALU: performs computing tasks – manipulates the data/ performs
numerical and logical computations
– Registers: are used for temporary storage
– Control unit: is used for timing and other controlling functions –
contains a program counter (next instruction’s address and status
register)
• Characteristics:
– General purpose CPU
– Binary
– Register-based
– Clock-driven
– Programmable
Arithmetic
Logic
Unit
Register
Arrays
Control Unit
Microprocessors (66322) Dr. Aladdin Masri 8
Computer Pre-history
• Electric Motors were used in mechanical
calculators in 1800s by Bomar, Monroe, etc. (for
up to 4 functions)
• 1889: Herman Holerith designed a real
computing calculator
– He founded Tabulated Machine Company, now known
as IBM.
• 1941: Konrad Zuse created Z3 (German)
• 1943: Alan Turing created Colossus (for code
breaking)
Microprocessors (66322) Dr. Aladdin Masri 9
Electronic Numerical Integrator and
Calculator – ENIAC
• A huge machine, in1946
– over 17,000 vacuum tubes; 500 miles of wires
– weighed over 30 tons
– about 100,000 operations per second
• Programmed by rewiring its circuits
– process took many workers several days
– workers changed electrical connections on plug-boards
like early telephone switchboards
• Required frequent maintenance
– vacuum tube service life is a problem
Microprocessors (66322) Dr. Aladdin Masri 10
Programming Advancements
• The first, machine language, was constructed of ones
and zeros using binary codes.
– Stored in the computer memory system as groups of
instructions called a program
– Difficult to decipher and write
– Prone to cause many errors in writing
• Once systems such as UNIVAC became available in
early 1950s, assembly language was used to simplify
entering binary code.
– Assembly language an aid to programming.
– Assembler allows programmer to use mnemonic codes
(such as ADD for addition) in place of a binary number
(such as 0100 0111)
Microprocessors (66322) Dr. Aladdin Masri 11
Programming Advancements
• High-Level Languages (such as C and C++)
– Written in statements of spoken languages (such as
English)
– machine independent
– easy to write and troubleshoot
– requires large memory and less efficient in
execution
Microprocessors (66322) Dr. Aladdin Masri 12
The Intel 4004 Microprocessor
• World’s first microprocessor
• A 4-bit microprocessor-
programmable controller on a chip.
– 2,250 transistors
– 12 mm
2
– Clock: 108 kHz
• Addressed 4096, 4-bit-wide
memory locations.
– 4-bit-wide memory location often
called a nibble
• The 4004 instruction set contained
45 instructions.
Microprocessors (66322) Dr. Aladdin Masri 13
The 4040 Microprocessor
• Evolution of 4-bit microprocessor ended when
Intel released the 4040, an updated 4004.
– operated at a higher speed
• Texas Instruments and others also produced 4-bit
microprocessors.
– still survives in low-end applications such as
microwave ovens and small control systems
– Calculators still based on 4-bit BCD (binary-coded
decimal) codes
• Main problems with early microprocessor were
speed, word width, and memory size.
Microprocessors (66322) Dr. Aladdin Masri 14
The 8008 Microprocessor 1971
The 8080 Microprocessor 1973
• The 8008 microprocessor is an extended 8-bit version of
4004 microprocessor
– Addressed expanded memory of 16K bytes.
– Contained additional instructions, 48 total.
– Provided opportunity for application in more advanced systems
• The 8080 microprocessor was the first of the modern 8-bit
microprocessors
– 8080 addressed four times more memory.
• 64K bytes vs. l6K bytes for 8008
– Executed additional instructions; 10x faster.
– TTL (transistor-transistor logic) compatible.
• the 8008 was not directly compatible
– Interfacing made easier and less expensive.
Microprocessors (66322) Dr. Aladdin Masri 15
Early 8-bit Microprocessors
Microprocessors (66322) Dr. Aladdin Masri 16
The 8085 Microprocessor 1977
• An updated version of the 8080
• Last 8-bit, general-purpose microprocessor
developed by Intel.
• Slightly more advanced than 8080
– 246 instructions
– executed software at an even higher speed.
– 769,230 instructions per second vs. 500,000 per
second on the 8080.
Microprocessors (66322) Dr. Aladdin Masri 17
The 8086/8088 Microprocessors 1978
• Both devices are 16-bit
microprocessors.
• Executed instructions in 400 ns
(2.5millions of instructions per
second)
• Addressed 1M byte of memory.
– Led to many sophisticated applications
• Improvements to the instruction set
included multiply and divide
instructions.
– missing on earlier microprocessors
• Number of instructions increased.
– over 20,000 variations
Microprocessors (66322) Dr. Aladdin Masri 18
The 80286 Microprocessor 1983
• Even the 1M-byte memory system proved
limiting for databases and other applications.
– an updated 8086
• Almost identical to the 8086/8088.
– addressed 16M-byte memory system instead of a 1M-
byte system
• Instruction set almost identical except for a few
additional instructions.
– managed the extra 15M bytes of memory
• Executed some instructions in as little as 250 ns
(4.0 MIPs)
Microprocessors (66322) Dr. Aladdin Masri 19
The 80386 Microprocessor 1986
• Intel’s first practical microprocessor to contain a 32-bit data
bus and 32-bit memory address.
– addressed up to 4G bytes of memory.
• 80386SX addressed 16M bytes of
memory through a 16-bit data and 24-bit
address bus.
• 80386SL/80386SLC addressed 32M bytes
memory via 16-bit data, 25-bit address
bus.
• 80386SLC contained an internal cache to
process data at even higher rates.
• 80386EX: embedded PC, 24 lines for
input/output data, 26-bit address bus,
DRAM refresh controller.
Microprocessors (66322) Dr. Aladdin Masri 20
The 80486 Microprocessor 1989
• Highly integrated package.
– 80386-like microprocessor.
– 80387-like numeric coprocessor.
– 8K-byte cache memory system.
• Internal structure of 80486 modified so
about half of its instructions executed
in one clock instead of two clocks.
– in a 50 MHz version, about half of
instructions executed in 25ns (50 MIPs)
– 50% over 80386 operated at same clock
speed
Microprocessors (66322) Dr. Aladdin Masri 21
The Pentium Microprocessor 1993
• Similar to 80386 and 80486
microprocessors
• Originally labeled the P5 or 80586
– Intel decided not to use a number
because it appeared to be impossible to
copyright a number
• Introductory versions operated with a
clocking frequency of 60 MHz and 66
MHz, and a speed of 110 MIPs
• Cache size was increased to 16K bytes
from the 8K cache found in 80486
• Memory system up to 4G bytes
• Data bus width increased to a full 64
bits
Microprocessors (66322) Dr. Aladdin Masri 22
Pentium Pro Processor
• Formerly named the P6.
• 21 million transistors, integer units, floating-point unit,
clock frequency 150 and 166 MHz
• Internal 16K level-one (L1) cache.
– 8K data, 8K for instructions
– Pentium Pro contains 256K level-two (L2) cache
• Pentium Pro uses three execution engines, to execute
up to three instructions at a time.
– can conflict and still execute in parallel
• Pentium Pro can address 4G-byte or a 64G-byte
memory system.
– 36-bit address bus if configured for a 64G memory system
Microprocessors (66322) Dr. Aladdin Masri 23
Pentium II Microprocessor 1997
Pentium Xeon Microprocessor 1998
• Pentium II represents new direction for Intel.
– Intel has placed Pentium II on a small circuit board, instead
of being an integrated circuit.
– Microprocessor on the Pentium II module actually Pentium
Pro with MMX extensions.
• Intel designed Xeon specifically for high-end
workstation and server applications
– Xeon available with 32K L1 cache and L2 cache size of:
512K, 1M, or 2M bytes.
– Xeon functions with the 440GX chip set.
– Also designed to function with four Xeons in the same
system, similar to Pentium Pro.
Microprocessors (66322) Dr. Aladdin Masri 24
Pentium III Microprocessor
• Faster core than Pentium II
– still a P6 or Pentium Pro
processor.
• Available in slot 1 version
mounted on a plastic cartridge.
• Also in socket 370 version
called a flip-chip which looks
like older Pentium package.
• Pentium III available with clock
frequencies up to 1 GHz.
• Slot 1 version contains a 512K
cache; flip-chip version
contains 256K cache.
Microprocessors (66322) Dr. Aladdin Masri 25
Pentium 4 and Core2 Microprocessors
• Pentium 4 first made available in late 2000.
– most recent version of Pentium called Core2
– uses Intel P6 architecture
• Pentium 4 available to 3.2 GHz and faster.
– supporting chip sets use RAMBUS or DDR
memory in place of SDRAM technology
• Core2 is available at speeds of up to 3 GHz.
– improvement in internal integration, at present
the 0.045 micron or 45 nm technology
• A likely change is a shift from aluminum to
copper interconnections inside the
microprocessor.
• Another event to look for is a change in the speed of the front side
bus.
– increase beyond current maximum 1033 MHz
Microprocessors (66322) Dr. Aladdin Masri 26
Pentium 4 and Core2, 64-bit and
Multiple Core Microprocessors
• Recent modifications to Pentium 4 and Core2
include a 64-bit core and multiple cores.
• 64-bit modification allows address of over 4G
bytes of memory through a 64-bit address.
– 40 address pins in these newer versions allow up to 1T
(terabytes) of memory to be accessed
• Also allows 64-bit integer arithmetic.
– Less important than ability to address more memory
• Intel manufactures dual and quad core versions
– Number of cores will likely increase to eight or even
sixteen.
Microprocessors (66322) Dr. Aladdin Masri 27
Itanium Microprocessor 2002
• A new architecture of 64 bits in width
with a 128-bit data bus.
• Joint venture called EPIC (Explicitly
Parallel Instruction Computing) of Intel
and Hewlett-Packard.
• The Itanium architecture allows greater
parallelism than traditional architectures
– 128 general-purpose integer
– 128 floating-point registers
– 64 predicate registers.
• Many execution units to ensure enough
hardware resources for software.
Microprocessors (66322) Dr. Aladdin Masri 28
No. of Transistors
Model Year of Introduction No. of Transistors
4004 1971 2,250
8008 1972 2,500
8080 1974 5,000
8086 1978 29,000
80286 1982 120,000
80386™ processor 1985 275,000
80486™ DX processor 1989 1,180,000
Pentium® processor 1993 3,100,000
Pentium II processor 1997 7,500,000
Pentium III processor 1999 24,000,000
Pentium 4 processor 2000 42,000,000
Pentium D 900 2006 376,000,000
Microprocessors (66322) Dr. Aladdin Masri 29
Microprocessor bus and memory sizes
Microprocessors (66322) Dr. Aladdin Masri 30
Conceptual views
Microprocessors (66322) Dr. Aladdin Masri 31
Conceptual views
Microprocessors (66322) Dr. Aladdin Masri 32
1-2 Microprocessor-based computer
system
Microprocessors (66322) Dr. Aladdin Masri 33
The Memory System
• Internal storage areas in the computer
– A group of registers each storing one byte (8 bits) in
general
– A read operation to a particular location always returns
the last value stored in that location
• Serves two major purposes:
1. Storing the binary codes for the sequence of
instructions specified by programs
2. Storing binary data that the computer needs to
execute instructions (data)
Microprocessors (66322) Dr. Aladdin Masri 34
Memory Types
• RAM: Random Access memory
– Volatile: losses information as power is removed
– Read/Write Memory (R/W)
• Write means the processor can store information
• Read means the processor can receive information from the
memory
– Acts like a Blackboard!
• ROM: Read-Only memory;
– It is typically non-volatile (permanent) – can be
erasable
– It is similar to a Page from your textbook
Microprocessors (66322) Dr. Aladdin Masri 35
Memory Classification
Microprocessors (66322) Dr. Aladdin Masri 36
The memory map of a personal
computer
• Main memory system divided into three parts:
– TPA (transient program area)
– System Area
– XMS (extended memory system)
• Type of microprocessor present determines whether an
extended memory system exists.
– Computers based on 8086 and 8088 have no extended
memory
• First 1M byte of memory often called the real or
conventional memory system.
– Intel microprocessors designed to function in this area
using real mode operation
Microprocessors (66322) Dr. Aladdin Masri 37
The memory map of a personal
computer
Microprocessors (66322) Dr. Aladdin Masri 38
The memory map of a personal
computer
• 80286 through the Core2 contain the TPA (640K
bytes) and system area (384K bytes).
– also contain extended memory
– often called AT class machines
• Extended memory up to:
– 15M bytes in the 80286 and 80386SX
– 4095M bytes in 80386DX, 80486 and Pentium
microprocessors.
– Up to 1M less than 4G or 1 M less than 64G in
Pentium Pro through Core2 computer systems
• Servers tend to use the larger memory map.
Microprocessors (66322) Dr. Aladdin Masri 39
The Memory System
Other versions memory
• The PS/1 and PS/2 by IBM are other versions of
the same basic memory design.
– Also referred to as ISA (industry standard architecture)
or EISA (extended ISA).
– The PS/2 referred to as a micro-channel architecture or
ISA system
• depending on the model number
• Pentium and ATX class machines feature addition
of the PCI (peripheral component interconnect)
bus.
– used in all Pentium through Core2 systems
– either a 32 or 64-bit bus
Microprocessors (66322) Dr. Aladdin Masri 40
The Memory System
Other versions memory
• The ISA machine
– Contains an 8-bit peripheral bus used to interface 8-bit
devices, in the 8088/8088-based PC or XT computers
– Uses a 16-bit peripheral bus for interface, in the AT class
machine and 80286+
• The EISA bus is a 32-bit peripheral interface bus
• The VESA local bus or VL bus
– In many 80486 systems
– Interfaces disk and video to the microprocessor
– Allows 32-bit interfaces to function at the same clocking
speed
– recent modification supporting 64-bit data bus has
generated little interest
Microprocessors (66322) Dr. Aladdin Masri 41
The Memory System
Other versions memory
• USB: universal serial bus
– Connecting peripheral devices to the microprocessor
through a serial data path and a twisted pair of wires
– Data transfer rates are 10 Mbps for USB1.
– Increase to 480 Mbps in USB2.
• AGP: advanced graphics port (for video cards)
• Serial ATA interface (SATA) for hard disk drives
– The SATA bus transfers data from PC to hard disk at
rates of 150M bytes per second; 300M bytes for
SATA-2.
• PCI Express bus for the video card.
Microprocessors (66322) Dr. Aladdin Masri 42
The TPA Area
• Length of the TPA is 640K bytes, holding:
– DOS (disk operating system) operating system
– Other programs that control the computer system
– It also stores any currently active or inactive DOS
application programs
• The TPA is a DOS concept and not really
applicable in Windows
Microprocessors (66322) Dr. Aladdin Masri 43
The memory map of the TPA
• DOS memory map shows how areas of
TPA are used for system programs, data
and drivers.
– also shows a large area of memory
available for application programs
• Hexadecimal number to left of each
area represents the memory addresses
that begin and end each data area
– Hexadecimal memory addresses number
each byte of the memory system.
– Often a hexadecimal number ends with
an H to indicate it is a hexadecimal value.
• 1234H is 1234 hexadecimal
– also represent hexadecimal data as
0x1234 for a 1234 hexadecimal
Microprocessors (66322) Dr. Aladdin Masri 44
The memory map of the TPA
• Though not used by Windows, still used to
execute DOS applications, even with Win XP.
• Windows uses a file called SYSTEM.INI to
load drivers used by Windows.
• Newer versions of Windows have a registry
added to contain information about the system
and the drivers used.
– You can view the registry with the REGEDIT
program.
Microprocessors (66322) Dr. Aladdin Masri 45
The System Area
• The system area contains
programs on read-only (ROM)
or flash memory, and areas of
read/write (RAM) memory for
data storage.
– Smaller than the TPA
– Just as important
– Includes various areas
Microprocessors (66322) Dr. Aladdin Masri 46
Windows Systems
• Modern computers use a
different memory map with
Windows than DOS memory
maps.
– The difference between it and
the DOS memory map are sizes
and locations of these areas.
• TPA is first 2G bytes
– Every Windows program can
use up to 2G bytes of memory.
• System area is last 2G bytes.
Microprocessors (66322) Dr. Aladdin Masri 47
I/O Space
• I/O devices allow the
microprocessor to communicate
with the outside world.
• I/O (input/output) space in a
computer system extends from I/O
port 0000H to port FFFFH.
– I/O port address is similar to a
memory address
– instead of memory, it addresses an
I/O device
• Access to most I/O devices should
always be made through Windows,
DOS, or BIOS function calls.
• The map shown is provided as a
guide to illustrate the I/O space in
the system.
Microprocessors (66322) Dr. Aladdin Masri 48
The Microprocessor Functions
• Microprocessor performs three main tasks:
1. Data transfer between itself and the memory or I/O
systems
2. Simple arithmetic and logic operations
3. Program flow via simple decisions
• Memory and I/O controlled via instructions stored in
memory, executed by the microprocessor.
– Controls memory and I/O through connections called
buses.
– Buses select an I/O or memory device, transfer data
between I/O devices or memory and the microprocessor,
control I/O and memory systems
Microprocessors (66322) Dr. Aladdin Masri 49
Buses
• A collection of wires through which data is transmitted from
one part of a computer to another
• Three buses exist: address, data, and control
– Transfer address, data, and control information between
microprocessor, memory and I/O.
• The microprocessor reads a memory location by sending the
memory an address through the address bus.
• Next, it sends a memory read control signal to cause the
memory to read data.
• Data read from memory are passed to the microprocessor
through the data bus.
• Whenever a memory write, I/O write, or I/O read occurs,
the same sequence ensues.
Microprocessors (66322) Dr. Aladdin Masri 50
The address, data, and control bus
structure
Microprocessors (66322) Dr. Aladdin Masri 51
The Address Bus
• Unidirectional, consists of 16, 20, 24, or 32
parallel signal lines
– 64-bit extensions to Pentium provide 40 address pins,
allowing up to 1T byte of memory to be accessed.
• The CPU requests a memory location from the
memory or an I/O location from the I/O devices.
– If I/O is addressed, the address bus contains a 16-bit
I/O address from 0000H through FFFFH.
– If memory is addressed, the bus contains a memory
address, varying in width by type of microprocessor.
Microprocessors (66322) Dr. Aladdin Masri 52
The Data Bus
• The data bus transfers information between the
microprocessor and its memory and I/O address space.
– bi-directional
– only one device at a time can have its outputs enabled
• Data transfers vary in size, from 8 bits wide to 64 bits wide
in various Intel microprocessors.
– 8088 has an 8-bit data bus that transfers 8 bits of data at a time
– 8086, 80286, 80386SL, 80386SX, and 80386EX transfer 16 bits
of data
– 80386DX, 80486SX, and 80486DX, 32 bits
– Pentium through Core2 microprocessors transfer 64 bits of data
• Advantage of a wider data bus is speed in applications
using wide data.
Microprocessors (66322) Dr. Aladdin Masri 53
The physical memory systems
Microprocessors (66322) Dr. Aladdin Masri 54
The physical memory systems
Microprocessors (66322) Dr. Aladdin Masri 55
The Control Bus
• Control bus lines select and cause memory or I/O
to perform a read or write operation.
– consists of 4 to 10 (or more) parallel signal lines
• In most computer systems, there are four control
bus connections:
– : memory read control
– : memory write control
– : I/O read control
– : I/O write control
• Over-bar indicates the control signal is active-low
active when logic zero appears on control line
Microprocessors (66322) Dr. Aladdin Masri 56
Microprocessor: Fetch – Decode –
Execute
• Read first word of the present instruction
from the data bus (using a read bus
cycle).
• Inspect the “operation code” in the first
word of the instruction, decide which
kind of instruction is being performed.
• Update the PC, place PC contents on the
address bus, and read additional data
words (if necessary) using read bus
cycles.
• Update all CPU registers (including the
PC) according to the present register
contents and the present instruction type.
• If necessary, update words in memory
and I/O devices using write bus cycles.
Microprocessors (66322) Dr. Aladdin Masri 57
1-3 Number Systems
• In any numbering system, the number of symbols
used is called the base or radix of the number
system.
– A decimal (base 10) number is constructed with 10
digits: 0 through 9.
– An octal (base 8) number; 8 digits: 0 through 7.
– A binary (base 2) number; 2 digits: 0 and 1.
• If the base exceeds 10, additional digits use letters
of the alphabet, beginning with an A.
– A hexadecimal (base 16) is constructed with 10 digits:
0 through 9, followed by A, B, C, D, E and F.
Microprocessors (66322) Dr. Aladdin Masri 58
1-3 Number Systems
Microprocessors (66322) Dr. Aladdin Masri 59
Positional Notation
• Position to the left of the radix (number base)
point is always the units position in system.
– called a decimal point only in the decimal system
– position to left of the binary point always 2
0
, or 1
– position left of the octal point is 8
0
, or 1
• Any number raised to its zero power is always
one (1), or the units position.
• In any system, positions right of the decimal point
have negative powers.
– First digit to the right of the decimal point has a value
of 10
−1
, or 0.1.
Microprocessors (66322) Dr. Aladdin Masri 60
Binary Number System
• Binary numbers use base 2 or radix 2, have
just two digits 0 and 1
• Bit numbering:
• Rightmost bit: Least Significant Bit (LSB)
• Leftmost bit: Most Significant Bit (MSB)
• Example:
– 1101
2
= 2
3
*1 +2
2
*1 + 2
1
*0 + 2
0
*1
Microprocessors (66322) Dr. Aladdin Masri 61
0 15
1 0 1 1 0 0 1 0 1 0 0 1 1 1 0 0
MSB LSB
Binary Number System
• Evaluate the decimal equivalent of binary
number 1011.01
2
• Solution:
1011.01
2
= 2
3
*1+2
2
*0+2
1
*1+2
0
*1+2
-1
*0+2
-2
*1
= 8 + 0 + 2 + 1 + 0 + 0.25
= 11.25
10
Microprocessors (66322) Dr. Aladdin Masri 62
Binary Number System
• Convert the decimal number 30.8125
10
to binary
• Solution:
• So, 30.8125
10
= 11110.1101
2
Microprocessors (66322) Dr. Aladdin Masri 63
30 2
15 0
7 1
3 1
1 1
0 1
2*0.8125 = 1.625 1
2*0.625 = 1.25 1
2*0.25 = 0.5 0
2*0.5 = 1.0 1
LSB
MSB
MSB
Hexadecimal Number System
• Hex is very useful when it comes to memory mapping.
– Today’s memories are so large, it is much easier to describe data
locations in hex.
• A shorthand notation for binary, because each hex number
represents 4 bits.
• A binary number is converted to a hex number by taking 4
bits at a time.
– Example: 101011010111
Binary: 1010 1101 0111
Hex: A D 7
So, (101011010111)
2
=(AD7)
16
• The letters correspond to 2 digit numbers:
– A = 10, B = 11, C = 12, D = 13, E = 14, F = 15
Microprocessors (66322) Dr. Aladdin Masri 64
1–4 Data Format: Byte-Sized Data
• Stored as unsigned and signed integers.
– 1 byte = 8 bits
• Difference in these forms is the weight of the
leftmost bit position.
– unsigned integer: from 0 – 255
– singed integer: from -128 – 127
• In signed integer format, the leftmost bit
represents the sign bit of the number.
– also a weight of -128
• A special directive to define data byte(s): DB
– Define both ASCII code and BCD (binary-coded data)
Microprocessors (66322) Dr. Aladdin Masri 65
Byte-Sized Data Examples
• ASCII data
• Unpacked BCD data
• Packed BCD data
Microprocessors (66322) Dr. Aladdin Masri 66
0000 4D 69 63 72 6F 70 72
6F 63 65 73 73 6F 72
20 43 6F 75 72 73 65
Class DB ‘Microprocessor Course’
0015 41 6C 61 64 64 69 6E
20 4D 61 73 72 69
Name DB ‘Aladdin Masri’
0000 02 03 06 Unp1 DB 2,3,6 ;defines the number 632
0003 09 07 Unp2 DB 9,7 ;defines the number 79
0000 39 55 Pack1 DB 39H, 55H ;defines the number 5539
0002 08 20 Pack2 DB 8,20H ;defines the number 2008
Complement Representation
• Positive numbers
– Signed value = Unsigned value
• Negative numbers
– 1's complement
– 2's complement
• Negative weight for MSB
– Another way to obtain the
signed value is to assign a
negative weight to most-
significant bit
= -128 + 32 + 16 + 4 = -76
8-bit Binary
value
Unsigned
value
Signed
value
00000000 0 0
00000001 1 +1
00000010 2 +2
. . . . . . . . .
01111110 126 +126
01111111 127 +127
10000000 128 -128
10000001 129 -127
. . . . . . . . .
11111110 254 -2
11111111 255 -1
1 0 1 1 0 1 0 0
-128 64 32 16 8 4 2 1
Microprocessors (66322) Dr. Aladdin Masri 67
Byte-Sized Data Examples
• Unsigned data
• Signed data
– 2’s complement
Microprocessors (66322) Dr. Aladdin Masri 68
Word-Sized Data
• A data word is formed with two bytes (16 bits)
• A special directive to define data byte(s): DW
Microprocessors (66322) Dr. Aladdin Masri 69
The storage format for a 16-bit word
• The figure shows how data,
1234H, is stored in the
memory.
– The least significant byte
always stored in the lowest-
numbered memory location
(3000H).
– Most significant byte is stored
in the highest (3001H).
• This method of storing a number is called the little
endian format.
Microprocessors (66322) Dr. Aladdin Masri 70
Doubleword-Sized Data
• Requires four bytes of memory because it is a
32-bit number.
– appears as a product after a multiplication
– also as a dividend before a division
• Defined using the assembler directive define
doubleword, DWORD or DD.
Microprocessors (66322) Dr. Aladdin Masri 71
The storage format for a 32-bit word
• The figure shows how double
word data 12345678H is
stored in the memory
locations from
00100H – 00103H
• Examples of double word data
Microprocessors (66322) Dr. Aladdin Masri 72
Real Numbers
• Since many high-level languages use Intel microprocessors,
real numbers are often encountered.
• A real, or a floating-point number contains two parts:
– an exponent
– a mantissa, significand, or fraction
• A 4-byte number is called single-precision.
• The 8-byte form is called double-precision.
Microprocessors (66322) Dr. Aladdin Masri 73
Real Numbers
• The assembler can be used to define real numbers
in single- and double-precision forms:
– the DD directive for single-precision 32-bit numbers
– define quadword, or DQ to define 64-bit double-
precision real numbers
• Optional directives are REAL4, REAL8, and
REAL10.
– for defining single-, double-, and extended precision
real numbers
Microprocessors (66322) Dr. Aladdin Masri 74
How real numbers are stored
• Get the binary format of the real number
• Normalize the number by adjusting it
– its value is at least 1 but less than 2
• The fraction of the normalized number is the mantissa part
• The exponent is stored as a biased exponent:
– For single-precision, add a bias of 127, or 7FH, to the power of
exponent
– For double-precision, add a bias of 1023, or 3FFH, to the power
of exponent
• The sign depends on the sign of the real number
• Two exceptions:
– 0 is stored as all zeros
– ±∞ is stored as all ones
Microprocessors (66322) Dr. Aladdin Masri 75
Real Numbers
• Defining single-, double-, and extended precision real numbers
example:
Microprocessors (66322) Dr. Aladdin Masri 76
? Directive
• Memory is reserved for use in the future by using
a question mark ? as an operand for a DB, DW, or
DD directive.
– when ? is used in place of a numeric or ASCII value,
the assembler sets aside a location and does not
initialize it to any specific value
• It is important that word-sized data are placed at
word boundaries and doubleword-sized data are
placed at doubleword boundaries.
– if not, the microprocessor spends additional time
accessing these data types
Microprocessors (66322) Dr. Aladdin Masri 77
ALIGN
• Aligns a variable in memory
• Syntax: ALIGN bound
– Where bound can be 1, 2, 4, or 16
• Address of a variable should be a multiple of bound
• Assembler inserts empty bytes to enforce alignment
.DATA
b1 DB ? ; Address of b1 = 00404000h
ALIGN 2 ; Skip one byte
w1 WORD ? ; Address of w1 = 00404002h
w2 WORD ? ; Address of w2 = 00404004h
ALIGN 4 ; Skip two bytes
d1 DWORD ? ; Address of d1 = 00404008h
d2 DWORD ? ; Address of d2 = 0040400Ch
Microprocessors (66322) Dr. Aladdin Masri 78
w1 b1 404000
w2 404004
d1 404008
d2 40400C
Using the DUP Operator
• Use DUP to allocate space for an array or string
– Advantage: more compact than using a list of initializers
• Syntax
– counter DUP ( argument )
– Counter and argument must be constants expressions
• The DUP operator may also be nested:
Microprocessors (66322) Dr. Aladdin Masri 79
Defining Strings
• A string is implemented as an array of characters
– it is usually enclosed in quotation marks, and terminated with a NULL
char (byte value = 0) or end-of-line character sequence:
• carriage return 0DH
• line feed 0AH
str1 DB "Enter your name", 0
str2 DB 'A','E','I','O',‘U'
greeting DB "Welcome to the Encryption“
DB "Demo Program", 0
• To continue a single string across multiple lines, end each line with
a comma
menu DB "Checking Account",0dh,0ah,0dh,0ah,
"1. Credit the account",0dh,0ah,
"2. Debit the account",0dh,0ah,
"3. Exit",0ah,0ah,
"Choice> ",0
Microprocessors (66322) Dr. Aladdin Masri 80