MICROPROCESSOR AND
ASSEMBLY LANGUAGE
LECTURE-1-INTRDUCTION
MUHAMMAD HAFEEZ
DEPARTMENT OF COMPUTER SCIENCE
GC UNIVERSITY LAHORE
TODAY’S AGENDA
Introduction to Course
Background-Prerequisites
Number System
Memory
MY INTRODUCTION
Office: Room-103
Course Blog: csience1234.wordpress.com
Email: [email protected]
COURSE INTRODUCTION
Course Title: Microprocessor and Assembly
Language
Course Code: CS-2207
Recommended Books:
8086 IBM-PC Assembly Language by M.A.Mazidi
Intel Microprocessors Architecture, Programming
and Interfacing by Bary B. Bray
Assembly Language Programming and
Organization of the IBM PC By Ytha Y. Yu,
Charles Marut
COURSE INTRODUCTION
Reference Material:
Google It
Taste It
COURSE DESCRIPTION
This is a semester long course introducing
fundamentals of a computer organization.
Primarily the course focus on Assembly
Language for the Intel x86 series of chips
which is the heart of the IBM PC.
Assembly Language is a link between
microprocessor and High Level Language
Write, Understand and Debug a Program
written in Assembly Language
Control I/O Devices
COURSE PREREQUISITES
Digital Logic Design
Minimum familiarity with IBM PC and MS-
DOS
PROCESSOR
UNDERSTANDING
Bottom-Up View
Logic Gates (Transistors)
Flip-Flops, Registers, Multiplexers, Decoders,
Adders
Memory, Processor, I/O Controllers
Build Complete Computer System
PROCESSOR
UNDERSTANDING
Top-Down View
A Programmer’s View
Study tasks that processor executes to execute a
HLL program
Learn the Set of very basic steps processor
performs – Instruction Set
Can be Learned at Machine Level – difficult to
understand
Assembly Language Level – Symbolic equivalent to
machine level instructions
PROCESSOR
UNDERSTANDING
Top-Down View
Example, for the Intel Processor:
MOV AL, 5 ;Assembly language
10110000 00000101 ;Machine language
MOTIVATION
Link between High Level Language and
Assembly
Assembler is developed for particular processor
Reasons to Learns Assembly:
In-depth understanding of assembly is required
to understand device drivers
Compiler Development and Code Optimization
Helpful in working with Operating System and
embedded systems
A conceptual bridge between Abstraction of real
world in (compiler) and microprocessor
COURSE WORK AND
GRADING
Quiz-05%
Assignment-05%
Term Project-10%
Mid Term-20%
Final Term-60%
This is tentative distribution and liable to change
under certain circumstances.
ATTENDANCE &
ASSIGNMENT SUBMISSION
80% attendance mandatory to qualify for
final examination
Assignments should be submitted on due
date and time, no further extension shall be
given. Assignments should be
submitted in hard-copy on A4 paper
with proper binding and titled in the
format
StudentFirstName-RollNo-CourseCode-Section-
AssignmentNo
e.g. kaleem-001BSCS14-CS2207-A-01
NUMBER SYSTEM
Data Represented in Computer is in the
form of digital signals (on-off)
Best represented by Binary Number System
(1-0)
One binary digit is not enough to represent
real world information
Need at least 08 bits called a ‘Byte’; that is
smallest addressable unit in modern
computers
For x86 following units are used
01 Byte = 08 Bits
01 Word = 02 Bytes
01 Double Word = 02 Words
NUMBER SYSTEM
The contents of 1 bytes stored in computer
memory needs ‘Interpretation’
For Example, the memory content 0100
0001, can be represented as Number 65 or
Letter ‘A’
It is upto the programmer to provide
interpretation
NUMBER SYSTEM
A written number is only meaningful when
we define its Base
Hexadecimal 25 is written as 25h
Binary 1010 is written as 1010b
Decimal 1010 is written as 1010 or 1010d
Significance of Bases to demonstrate
quantity
Larger base represent large quantities in fewer
digits
BINARY NUMBER SYSTEM
Digits are 1 and 0
1 = true
0 = false
MSB – Most Significant Bit
LSB – Least Significant Bit
Bit Numbering: MSB LSB
1011001010011100
15 0
BINARY NUMBER SYSTEM
Each digit (bit) is either 1 or 0
Each bit represents a power of 2:
1 1 1 1 1 1 1 1
27 26 25 24 23 22 21 20
Every binary number is a sum of powers of 2
CONVERTING BINARY TO
DECIMAL
Weighted positional notation shows how to calculate
the decimal value of each binary bit:
Decimal Number = (Dn-1 2n-1) + (Dn-2 2n-2) + ... + (D1 21) + (D0 20)
D = Binary Digit
(1010)2 =1x23+0x22+1x21+0x20 =8+0+2+0= (10)10
CONVERTING UNSIGNED
DECIMAL TO BINARY
Repeatedly divide the decimal integer by 2. Each
remainder is a binary digit in the translated value:
BINARY ARITHMETIC
Binary Addition
Binary Subtraction
Binary Multiplication
Binary Division
UNSIGNED INTEGER
NUMBER STORAGE SIZE IN
MEMORY
Standard Sizes
What is the Largest Number stored in 20 Bits
HEXADECIMAL NUMBER
SYSTEM
Binary, Decimal and Hexadecimal Numbers
HEXADECIMAL NUMBER
SYSTEM
Binary, Decimal and Hexadecimal Numbers
CONVERTING
HEXADECIMAL TO BINARY
Each Hexadecimal digit is equivalent to 4 Binary
Digits
Prove the same with repeated division method by 2
CONVERTING
HEXADECIMAL TO DECIMAL
Multiply each digit by its corresponding power of 16:
Decimal = (Dn-1 16n-1)+…+(D3 163) + (D2 162) + (D1 161) + (D0 160)
Hex 1234 equals (1 163) + (2 162) + (3 161) +
(4 160)= decimal 4,660.
Hex 3BA4 equals (3 163) + (11 * 162) + (10 161)
+ (4 160)= decimal 15,268.
Another way
CONVERTING
HEXADECIMAL VALUES
UPTO 8 DIGITS
CONVERTING DECIMAL TO
HEXADECIMAL
decimal 422 = 1A6 hexadecimal
HEXADECIMAL ADDITION
Starting from LSB if sum of each two digits is
greater than or equal to 16, divide it with 16, the
quotient become carry digit and remainder become
sum digit
Carry will be 1
36 28 28 6A
42 45 58 4B
78 6D 80 B5
21 / 16 = 1, rem 5
Important skill to do arithmetic in Hexadecimal for
Assembly Language
HEXADECIMAL ADDITION
HEXADECIMAL
SUBTRACTION
When a Borrow is required from the digit on left
hand side, add sixteen (16) to the digit on right
hand side
Borrow will be 16 16 + 5 = 21
-1
C6 75
A2 47
24 2E
The address of var1 is 00400020. The address of
the next variable after var1 is 0040006A. How many
bytes are used by var1?
TWO REPRESENTATIONS
FOR INTEGERS
The unsigned representation: in that case all the
bits are used to represent a magnitude
Can be positive number or Zero
Signed Representation
For What purpose signed number could be used?
Can you recognize a number for even or odd by
looking at bit pattern?
SIGNED REPRESENTATIONS
FOR INTEGERS
The Singed Representation forms:
Sign Magnitude Form
Uses most significant bit of the word to represent the sign.
0 - Positive
1 - Negative.
Rest of the number is encoded in magnitude part
37 = 00000000 00100101
-37 = 10000000 00100101
6712 = 00011010 00111000
-6712 = 10011010 00111000
Can represent numbers from -32,767 to 32,767.
-215+1 .. 215-1
But, two representations for zero:
0 = 00000000 00000000
-0 = 10000000 00000000
Arithmetic can be cumbersome.
SIGNED REPRESENTATIONS
FOR INTEGERS
Sign Magnitude Form
Uses most significant bit of the word to represent the sign.
0 - Positive
1 - Negative.
Rest of the number is encoded in magnitude part
37 = 00000000 00100101
-37 = 10000000 00100101
6712 = 00011010 00111000
-6712 = 10011010 00111000
Can represent numbers from -32,767 to 32,767.
-215+1 .. 215-1
But, two representations for zero:
0 = 00000000 00000000
-0 = 10000000 00000000
Arithmetic can be cumbersome.
SIGNED REPRESENTATIONS
FOR INTEGERS
1’s Compliment Form
Negative number is stored as bit-wise complement of
corresponding positive number.
Leftmost bit of positive number is 0. That of negative number
is 1.
196 = 00000000 11000100
-196 = 11111111 00111011
Can represent numbers from -32,767 to 32,767.
-215+1 .. 215-1
Arithmetic is easier than sign-magnitude.
But, still have two representations for zero:
0 = 00000000 00000000
-0 = 11111111 11111111
Add 5 and -5 using 1’s Complement and see the
result?
SIGNED REPRESENTATIONS
FOR INTEGERS
2’s Compliment Form
Modern Method
Positive number represented in same way as other two
methods
Negative number obtained by taking 1's Complement of
positive number and adding 1.
6713 = 00011000 00011101
1's Comp = 11100111 11100010
2's Comp = 11100111 11100011
Word integer can represent numbers from -32,768 to 32,767.
-215 .. 215-1
Byte integer can represent numbers from -128 to 127.
-27 .. 27-1
One version of zero:
00000000 00000000
Find 2’s complement of 2’s complement of 6
SIGNED REPRESENTATIONS
FOR INTEGERS
Represent -97d in 2’s Complement Form using 8 bits
and 16 bits?
Sol: Represent 97 in Hex
Convert hex representation into binary
Take 2’s complement of binary
Convert into Hex … this how it is represented
5ABAH – 2A91H
Use 2’s complement to solve it
RANGE OF SIGNED
INTEGERS
MSB is reserved for Sign; this factor limits the range
For Signed Representation; what largest value can
be stored in 20 bits
SIGNED AND UNSIGNED IN
COMPUTER MEMORY TO
DECIMAL
To use a number in computer memory; we need to
provide it either signed or unsigned interpretation
How can we do that?
Unsigned: Just convert binary to decimal, better to
convert to hex and then to decimal
Signed: If msb=0, convert like unsigned numbers,
if msb=1, call the N number as –N, take 2’s
complement and then convert to decimal, place –
sign in front
1111 1111 can be interpreted as 255 (unsigned) Or
-1 (minus one) as signed
Its upto the programmer to provide memory
contents suitable interpretation for program
SIGNED AND UNSIGNED IN
COMPUTER MEMORY TO
DECIMAL
SIGNED AND UNSIGNED IN
COMPUTER MEMORY TO
DECIMAL
SIGNED AND UNSIGNED IN
COMPUTER MEMORY TO
DECIMAL
Any Observation in previous two slides?
Computer memory contents are FE0CH, give it
signed and unsigned representation?
SIGNED AND UNSIGNED IN
COMPUTER MEMORY TO
DECIMAL
Another Observation:
From 0000H-7FFFH Signed Number = Unsigned Numbers
From 8000H-FFFFHSigned Number = Unsigned Number-65536
Can you Observe the same for Byte?
Give FE0CH a singed and unsigned representation
through this method?
MINIMUM AND MAXIMUM
VALUES FOR SIGNED
NUMBERS
MSB used to represent sign, fever bits left for
magnitude representation
For Example, a signed byte have
Smallest Positive 0000 0000 (0 in decimal)
Largest Positive 0111 1111 (127 in decimal)
Smallest Negative 1000 0000 (-128)
Largest Negative 1111 1111 (-1)
First low byte is stored memory then high byte [Little
Endian]
REPRESENTATION
THROUGH MEMORY
CONTENTS
Each Character is represented with 7 bit Code called
ASCII Character
ASCII Code from 00H to 07FH
Codes from 20H to 7EH are printable, rest of them are control
code
An extended character set is obtained by setting the
most significant bit (MSB) to 1 (codes 80h to FFh)
so that each character is stored in 1 byte
ASCII CHARACTER SET
CR = Carriage Return
LF = Line Feed (Cursor Moved one line below)
SPC = Blank Space
TEXT FILES USING ASCII
CHARACTER SET
Text Files contain printable and non-printable ASCII
Characters
Different OS represent non-printable characters
(control characters) i.e. moving to cursor to start of
line through different ways,
Windows: <CR>+<LF>
UNIX: <LF>
MAC: <CR>
Origin of problem when we move text files from one
OS to other
CHARACTER STORAGE
ASCII (0-127)
Extended ASCII (0-255)
Uni-Code (0-65,535)
QUESTIONS
????????????????????????