0% found this document useful (0 votes)
14 views32 pages

Cte 221 Note

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)
14 views32 pages

Cte 221 Note

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/ 32

GATEWAY (ICT) POLYTECHNIC SAAPADE

DEPARTMENT OF COMPUTER ENGINEERING TECHNOLOGY


2ND SEMESTER ND II 2022/2023 SESSION CTE 221
LECTURE NOTE
INTRODUCTION TO MICROPROCESSORS & ASSEMBLY LANGUAGE

CHAPTER ONE INTRODUCTION

INTRODUCTION TO PROGRAMMING LANGUAGES


Programmers write instructions in various programming languages, some directly
understandable by computers and others requiring intermediate translation steps. Hundreds of
computer languages are in use today.
These can be divided into three general types namely:
a. Machine Language
b. Low Level Language
c. High level Language

1.1 MACHINE LANGUAGE


Any computer can directly understand its own machine language. Machine language is
the “natural language” of a computer and such is defined by its hardware design. Machine
languages generally consist of strings of numbers (ultimately reduced to 1s and 0s) that
instruct computers to perform their most elementary operations one at a time. Machine
languages are machine dependent (i.e a particular machine language can be used on only
one type of computer). Such languages are cumbersome for humans, as illustrated by the
following section of an early machine language program that adds overtime pay to base
pay and stores the result in gross pay.
+1200021552
+1300482318
+1200274027
Advantages of Machine Language
i. It uses computer storage more efficiently
ii. It takes less time to process in a computer than any other programming language
1|Page CTE 221
Disadvantages of Machine Language
i. It is time consuming
ii. It is very tedious to write
iii. It is subject to human error
iv. It is expensive in program preparation and debugging stages

1.2 LOW LEVEL LANGUAGE


Machine Language were simply too slow and tedious for most programmers. Instead of
using strings of numbers that computers could directly understand, programmers began
using English-like abbreviations to represent elementary operations. These abbreviations
form the basis of Low Level Language. In low level language, instructions are coded using
mnemonics. E.g. DIV, ADD, SUB, MOV. Assembly language is an example of a low
level language.

AN ASSEMBLY LANGUAGE is a low-level language for programming computers. It


implements a symbolic representation of the numeric machine codes and other constants
needed to program a particular CPU architecture.

This representation is usually defined by the hardware manufacturer, and is based on


abbreviations (called mnemonics) that help the programmer remember individual
instructions, registers, etc. An assembly language is thus specific to certain physical or
virtual computer architecture (as opposed to most high-level languages, which are usually
portable). A utility program called an assembler is used to translate assembly language
statements into the target computer's machine code. The assembler performs a more or less
isomorphic translation (a one-to-one mapping) from mnemonic statements into machine
instructions and data. (This is in contrast with high-level languages, in which a single
statement generally results in many machine instructions.) Today, assembly language is
used primarily for direct hardware manipulation, access to specialized processor

2|Page CTE 221


instructions, or to address critical performance issues. The following section of an
assembly language program also adds overtime to base pay and stores the result in gross
pay:
Load basepay
Add overpay
Store grosspay
Each personal computer has a microprocessor that manages the computer's arithmetical,
logical, and control activities.
Each family of processors has its own set of instructions for handling various operations such
as getting input from keyboard, displaying information on screen and performing various other
jobs. These set of instructions are called 'machine language instructions'.
A processor understands only machine language instructions, which are strings of 1's and 0's.
However, machine language is too obscure and complex for using in software development.
So, the low-level assembly language is designed for a specific family of processors that
represents various instructions in symbolic code and a more understandable form.
Advantages of Low Level Language
i. It is more efficient than machine language
ii. Symbols make it easier to use than machine language
iii. It may be useful for security reasons
iv. It requires less memory and execution time;
v. It allows hardware-specific complex jobs in an easier way;
vi. It is suitable for time-critical jobs;
vii. It is most suitable for writing interrupt service routines and other memory resident
programs.

Disadvantages of Low Level Language


i. It is defined for a particular processor
ii. Assemblers are difficult to get
iii. Although, low level language codes are clearer to humans, they are incomprehensible
to computers until they are translated to machine language.

3|Page CTE 221


1.3 HIGH LEVEL LANGUAGE:
Computers usage increased rapidly with the advent of assembly languages, but
programmers still had to use many instructions to accomplish even the simplest tasks. To
speed up the programming process, high level language were developed in which simple
statements could be written to accomplish substantial tasks. Translator programs called
compilers convert high level language programs into machine language. High level
language allows programmers to write instructions that look almost like everyday English
and contain commonly used mathematical notations. A payroll program written in high
level language might contain a statement such as
grossPay = basePay + overtime Pay
Advantages of High Level Language (HLL)
i. Compilers are easy to get
ii. It is easier to use than any other programming language
iii. It is easier to understand compared to any other programming language
Disadvantages of High Level Language
i. It takes more time to process in a computer than any other programming language
FIVE DIFFERENCES BETWEEN ASSEMBLY LANGUAGE AND MACHINE
LANGUAGE
S/N ASSEMBLY LANGUAGE MACHINE LANGUAGE
1 Instruction and registers are given names Machine language is represented using
using mnemonics strings of 0’s and 1’s,
2 It is more efficient and useful for security It is slow, tedious and cumbersome for
reason programmers
3 It requires an assembler to translate the It is a set of instruction executed directly
instruction into machine code. by the C.P.U
4 it easily readable and understood by it not easily understood by human
humans
5 It is cost effective It is expensive in program preparation and
debugging stages

4|Page CTE 221


DIFFEENCES BETWEEN AN INSTRUCTION AND A DIRECTIVE IN ASSEMBLY
LANGUAGE

S/N Assembler Instruction Assembler Directive

1 Generates Machine code Does not create any machine code

2 Contributes towards the size of the Does not contribute to program size
program (opcode length)

3 Is a task to be carried out by the It direct how assembler handles the


processor at run time program and how data is arranged in
the memory

4 Instruction are assembled into machine Directives are only used at assembly
code and eventually linked into the time because they do not generate
final executable code.

EXERCISE ONE
1. What is Assembly Language?
2 Differentiate between Assembly Language and Machine Language
3 Enumerate the difference between AN INSTRUCTION and A DIRECTIVE in
Assembly Language?
4 List the Advantages and Disadvantages of HLL respectively?

5|Page CTE 221


CHAPTER TWO

2.0 DATA REPRESENTATION AND NUMBERING SYSTEMS

Most modern computer systems do not represent numeric values using the decimal system.
Instead, they use a binary or two’s complement numbering system. To understand the
limitations of computer arithmetic, one must understand how computers represent numbers.
With two such levels we can represent exactly two different values. These could be any two
different values, but by convention we use the values zero and one. These two values,
coincidentally, correspond to the two digits used by the binary numbering system.

2.1 THE BINARY NUMBERING SYSTEM

The binary numbering system works just like the decimal numbering system, with two
exceptions: binary only allows the digits 0 and 1 (rather than 0-9), and binary uses powers of
two rather than powers of ten. Therefore, it is very easy to convert a binary number to decimal.
For each "1" in the binary string, add in 2**n where "n" is the zero-based position of the binary
digit. For example, the binary value 11001010 represents:

1*2**7 + 1*2**6 + 0*2**5 + 0*2**4 + 1*2**3 + 0*2**2 + 1*2**1 + 0*2**0

=128 + 64 + 8 + 2

=202 (base 10)

A. Binary to other bases e,g x10, x8, x16


Example: (110001101)2
1X28+1X27+1X23+1X22+1X20
256+128+8+4+1
= 397

6|Page CTE 221


B. Octal to other bases e,g x2, x10, x 16.

THE OCTAL NUMBERING SYSTEM

Octal numbers are numbers to base 8. The primary advantage of the octal number system is
the ease with which conversion can be made between binary and decimal numbers. Octal is
often used as shorthand for binary numbers because of its easy conversion. The octal
numbering system is shown below;

Decimal Number Octal Equivalence

0 001

1 001
2 010
3 011
4 100
5 101
6 110
7 111
Example 6238
6X82+2X81+3X80
384+16+3
=403

C. Decimal to other bases e.g x2, x8, x16

THE DECIMAL NUMBERING SYSTEM

The decimal (base 10) numbering system has been used for so long that people take it for
granted. When you see a number like “123”, you don’t think about the value 123, rather,
you generate a mental image of how many items this value represents in reality, however,
the number 123 represents” 1*102 + 2*101 + 3*100 or 100+20+3 Each digit appearing to

7|Page CTE 221


the left of the decimal point represents a value between zero and nine times an increasing
power of ten. Digits appearing to the right of the decimal point represent a value between
zero and nine times an increasing negative power of ten.

Example: 123.456 means 1*102 + 2*101 + 3*100 + 4*10-1 + 5*10-2 +6*10-3

or 100 + 20 +3 +0.4 + 0.05 +0.006

Example 512 to x16


= 512/16 = 32 r0
32/16 = 2 r0
= 200H

To convert decimal to binary is slightly more difficult. You must find those powers of two
which, when added together, produce the decimal result. The easiest method is to work from
a large power of two down to 2**0. Consider the decimal value 1359:
2**10=1024, 2**11=2048. So 1024 is the largest power of two less than 1359. Subtract
1024 from 1359 and begin the binary value on the left with a "1" digit. Binary = "1",
Decimal result is 1359 - 1024 = 335.

The next lower power of two (2**9= 512) is greater than the result from above, so add a "0"
to the end of the binary string. Binary = "10", Decimal result is still 335.

The next lower power of two is 256 (2**8). Subtract this from 335 and add a "1" digit to the
end of the binary number. Binary = "101", Decimal result is 79.

128 (2**7) is greater than 79, so tack a "0" to the end of the binary string. Binary = "1010",
Decimal result remains 79.

8|Page CTE 221


The next lower power of two (2**6 = 64) is less than79, so subtract 64 and append a "1" to
the end of the binary string. Binary = "10101", Decimal result is 15.
15 is less than the next power of two (2**5 = 32) so simply add a "0" to the end of the binary
string. Binary = "101010", Decimal result is still 15.

16 (2**4) is greater than the remainder so far, so append a "0" to the end of the binary string.
Binary = "1010100", Decimal result is 15.

2**3(eight) is less than 15, so stick another "1" digit on the end of the binary string.
Binary = "10101001", Decimal result is 7.

2**2 is less than seven, so subtract four from seven and append another one to the binary
string. Binary = "101010011", decimal result is 3.

2**1 is less than three, so append a one to the end of the binary string and subtract two from
the decimal value. Binary = "1010100111", Decimal result is now 1.

Finally, the decimal result is one, which is2**0, so add a final "1" to the end of the binary
string. The final binary result is "10101001111"

D. Hexadecimal to other bases

THE HEXADECIMAL NUMBERING SYSTEM


A big problem with the binary system is verbosity. To represent the value 202
(decimal) requires eight binary digits. The decimal version requires only three decimal
digits and, thus, represents numbers much more compactly than does the binary
numbering system. This fact was not lost on the engineers who designed binary
computer systems. When dealing with large values, binary numbers quickly become

9|Page CTE 221


too unwieldy. Unfortunately, the computer thinks in binary, so most of the time it is
convenient to use the binary numbering system. Although we can convert between
decimal and binary, the conversion is not a trivial task. The hexadecimal (base 16)
numbering system solves these problems. Hexadecimal numbers offer the two features
we're looking for: they're very compact, and it's simple to convert them to binary and
vice versa. Because of this, most binary computer systems today use the hexadecimal
numbering system. Since the radix (base) of a hexadecimal number is 16, each
hexadecimal digit to the left of the hexadecimal point represents some value times a
successive power of 16. For example, the number 1234 (hexadecimal) is equal to:
1 * 16**3 + 2 * 16**2 + 3 * 16**1 + 4 * 16**0 or
4096 + 512 + 48 + 4 = 4660 (decimal).

Each hexadecimal digit can represent one of sixteen values between 0 and 15. Since
there are only ten decimal digits, we need to invent six additional digits to represent the
values in the range 10 through 15. Rather than create new symbols for these digits,
we'll use the letters A through F.

Example: 1AB16
Convert fromX16 X10
(1AB) 16
1 x 162 + 10 x 161 + 11 x 160
256 + 160 + 11
= 42710

The following are all examples of valid hexadecimal numbers:

1234h DEADh BEEFh 0AFBh FEEDh DEAFh

10 | P a g e CTE 221
As you can see, hexadecimal numbers are compact and easy to read. In addition, you can
easily convert between hexadecimal and binary.
Consider the following table:

Binary/Hex Conversion
Binary Hexadecimal
0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010 A
1011 B
1100 C
1101 D
1110 E
1111 F

This table provides all the information you'll ever need to convert any hexadecimal number
into a binary number or vice versa.
To convert a hexadecimal number into a binary number, simply substitute the corresponding
four bits for each hexadecimal digit in the number.
Example
Convert 0ABCDh into its binary value

11 | P a g e CTE 221
Answer:
Convert each hexadecimal digit according to the table above:
0 A B C D Hexadecimal
= (0000 1010 1011 1100 1101)2
To convert a binary number into hexadecimal format is almost as easy. The first step is to pad
the binary number with zeros to make sure that there is a multiple of four bits in the number.

Example: Find the hexadecimal equivalent, given the binary number 1011001010?
Step 1: add two bits to the left of the number so that it contains 12 bits.
The converted binary value is 001011001010
Step 2: separate the binary value into groups of four bits
0010 1100 1010
Step 3: look up these binary values in the table above and substitute the appropriate
hexadecimal digits,
0010 1100 1010.
2 C A.

A comparison of the afore mentioned numbering systems is shown below;


Binary octal decimal Hexadecimal
0 0 0 0
1 1 1 1
10 2 2 2
11 3 3 3
100 4 4 4
101 5 5 5
110 6 6 6
111 7 7 7
1000 10 8 8
1001 11 9 9

12 | P a g e CTE 221
1010 12 10 A
1011 13 11 B
1100 14 12 C
1101 15 13 D
1110 16 14 E
1111 17 15 F

Examples:

1a. Convert the following

i. Convert (1101.11)2 to its Decimal equivalent

Mathematically, we can write it as

1101.112 = (1 × 23) + (1 × 22) + (0 × 21) + (1 × 20) + (1 × 2-1) +

(1 × 2-2)

⇒ 1101.112 = 8 + 4 + 0 + 1 + 0.5 + 0.25 = 13.75


⇒ 1101.112 = 13.7510

Therefore, the decimal equivalent of binary number 1101.11 is 13.75

ii. Convert (10110111.1101)2 to its Octal equivalent

Solution:

Step 1: Separate the binary numbers into groups of 3 bits on both sides of binary point.

10 110 111. 110 1

Step 2: Here, on right side of binary point, the last group is having only 2 bits. So, include one
zero on extreme side in order to make it as group of 3 bits.

⇒ 010 110 111. 110 100

13 | P a g e CTE 221
Step 3 − Write the octal digits corresponding to each group of 3 bits.

⇒ 010110111.1101002 = 267.648

Therefore, the octal equivalent of binary number 010110111.110100 is 267.648

iii. Convert binary number 110001.10101 to its Hexadecimal equivalent

Step 1 − Make the groups of 4 bits on both sides of binary point.

11 0001.1010 1

Here, the first group is having only 2 bits. So, include two zeros on extreme side in order to
make it as group of 4 bits.

Similarly, include three zeros on extreme side in order to make the last group also as group of
4 bits.

⇒ 0011 0001.1010 1000

Step 2 − Write the Hexa-decimal digits corresponding to each group of 4 bits.

⇒ 0011 0001.1010 10002= 31.A816


Therefore, the Hexadecimal equivalent of binary number 110001.10101 is 31.A816

1. Hexadecimal Addition
Example:

Add (5BC) 16 and (2BF) 16

Solution:
In hexadecimal addition of alphabets, we add the corresponding numbers they represent and
then subtract the result from 16, then generate a carry of 1 to the next set of numbers.
Here, 5+2=7

C+F=12+15=27-16=11 i. e B (carry 1)
B + B+1(carry) = 11 +11= 23-16 = 7 (carry 1) again
5+2+1(carry) =8

14 | P a g e CTE 221
HEXADECIMAL ADDITION is done as follows:

5BC
+ 2BF

________
87B

EXERCISE TWO
1. The decimal equivalent of (11101010) 2

2. Find the decimal equivalent of 5188

3. Find the decimal equivalent of 415.035


4. Convert 640 to hexadecimal
5. Find the binary equivalent of 978
6. Find the decimal equivalent of (2ACE)16
7. Find the decimal equivalent of (FAD)16

8. Convert (10110.011)2 to its Decimal equivalent

9. Convert (0101001.10101)2 to its Octal equivalent


10.The Hexa-decimal equivalent of binary number 1101101001.101101
11. 512 to Hexadecimal ________________________

12. (110001101)2 to decimal _____________________

13.Octal subtraction of (220)8 from (515)8 will give ______________

14.Add (39D)16 and (19F)16

15 | P a g e CTE 221
CHAPTER THREE
3.0 TYPES OF ENCODING
When numbers, letters and words are represented by a special group of symbols, this is called
“Encoding” and the group of symbol encoded is called a “code”. Any decimal number can be
represented by an equivalent binary number. When a decimal number is represented by its
equivalent binary number, it is called “straight binary coding”.

Basically, there are three methods of encoding and they are;


 American Standard Code for Information Interchange (ASCII)
 Binary Coded Decimal (BCD)
 Extended Binary Coded Decimal Interchange Code (EBCDIC)
3.1 ASCII CODING SYSTEM
In addition to numeric data, a computer must be able to handle non- numeric information. In
order words, a computer should recognize codes that represents letters of the alphabets,
punctuation marks, other special characters as well as numbers. These codes are called
alphanumeric codes. The most widely used alphanumeric code is ASCII code (American
Standard Code for Information Interchange). ASCII is used in most micro computers and mini
computers and in many main frames. The ASCII code is a seven bit code, thus it has 2 7 =128
possible code groups. In the 7 bits code, the first 3 bits represent the zone bits and the last 4
bits represent the numeric bits. Despite some major shortcomings, ASCII data is the standard
for data interchange across computer systems and programs. Most programs can accept ASCII
data; likewise most programs can produce ASCII data. Since you will be dealing with ASCII
characters in assembly language, it would be wise to study the layout of the character set and
memorize a few key ASCII codes (e.g., "0", "A", "a", etc.).

3.2 BINARY CODED DECIMAL


If each digit of a decimal number is represented by binary equivalence, this produces a code
called Binary Coded Decimal. Since a decimal digit can be as large as 9, 4 bits are required to
code each digit in the decimal number.

16 | P a g e CTE 221
E.g. 87410 = 1000011101002
94310 = 1001010000112
Only the four bits binary numbers from 0000 through 1001 are used for binary coded decimal.
The BCD code does not use the numbers 10, 11, 12, 13, 14, 15. In other words, 10 of the 16
possible 4 bits binary codes are used. If any of these forbidden 4 bits number ever occurs in a
machine using the BCD, it is usually an indication that an error has occurred.

Comparison of BCD and Binary


It is important to realize that BCD is not another number system like binary, octal,
hexadecimal and decimal. It is in fact the decimal system with each digit encoded in its binary
equivalence. It is also important to understand that a BCD number is not the same as binary
number. A straight binary code takes the complete decimal number and represents it in binary
while the BCD code converts each decimal digit to binary individually.
e.g. 13710 to straight binary coding is 10001001
13710 to BCD is 0001 0011 0111

EXERCISE THREE

1. Convert 78110 to BCD

2. Convert 36410 to BCD

3. Convert 5210 to BCD

17 | P a g e CTE 221
CHAPTER FOUR

4.0 MODES OF DATA REPRESENTATION

Most data structures are abstract structures and are implemented by the programmer
with a series of assembly language instructions. Many cardinal data types (bits, bit strings,
bit slices, binary integers, binary floating point numbers, binary encoded decimals, binary
addresses, characters, etc.) are implemented directly in hardware for at least parts of the
instruction set. Some processors also implement some data structures in hardware for
some instructions — for example, most processors have a few instructions for directly
manipulating character strings.

An assembly language programmer has to know how the hardware implements these
cardinal data types. Some examples: Two basic issues are bit ordering (big endian or little
endian) and number of bits (or bytes). The assembly language programmer must also pay
attention to word length and optimum (or required) addressing boundaries. Composite
data types will also include details of hardware implementation, such as how many bits of
mantissa, characteristic, and sign, as well as their order.

4.1 INTEGER REPRESENTATION

A. Sign-magnitude is the simplest method for representing signed binary numbers.


One bit (by universal convention, the highest order or leftmost bit) is the sign bit,
indicating positive or negative, and the remaining bits are the absolute value of the
binary integer. Sign-magnitude is simple for representing binary numbers, but has
the drawbacks of two different zeros and much more complicates (and therefore,

18 | P a g e CTE 221
slower) hardware for performing addition, subtraction, and any binary integer
operations other than complement (which only requires a sign bit change).

In sign magnitude, the sign bit for positive is represented by 0 and the sign bit for
negative is represented by 1.

Examples:

1. Convert +52 to binary using an 8 bits machine

Answer:

The binary equivalence of 52 is 110100 but 0 is used to represent positive


magnitude, hence 0 is added to the front of this binary equivalence. This makes a
total of 7bits, since we are working on an eight bit machine, we have to pad the
numbers with 0 so as to make it a total of 8bits.

Thus the binary equivalence 0f 52 is 00110100.

2. Convert -52 to binary using an 8 bits machine Answer: The binary equivalence of
52 is 110100 but 1 is used to represent negative magnitude, hence 1 is added to the
front of this binary equivalence. This makes a total of 7bits, since we are working
on an eight bit machine, we have to pad the numbers with 0 so as to make it a total
of 8bits. In this case, the sign bit has to come first and the padded 0 follows.

Thus the binary equivalence 0f -52 is 10110100.

In one’s complement representation, positive numbers are represented in the


“normal” manner (same as unsigned integers with a zero sign bit), while negative
numbers are represented by complementing all of the bits of the absolute value of
the number. Numbers are negated by complementing all bits. Addition of two
integers is performed by treating the numbers as unsigned integers (ignoring sign
bit), with a carry out of the leftmost bit position being added to the least significant

19 | P a g e CTE 221
bit (technically, the carry bit is always added to the least significant bit, but when it
is zero, the add has no effect). The ripple effect of adding the carry bit can almost
double the time to do an addition. And there are still two zeros, a positive zero (all
zero bits) and a negative zero (all one bits).

1’s and 2’s COMPLEMENT

The 1’s complement form of any binary number is simply by changing each 0 in the
number to a 1 and vice versa.

Examples 1. Find the 1’s complement of -7

Answer: -7 in the actual representation without considering the machine bit is 1111.
To change this to 1’s complement, the sign bit has to be retained and other bits have
to be inverted. Thus, the answer is: 1000. 1 denotes the sign bit.

3. Find the1’s complement of -7.25

The actual magnitude representation of -7.25 is 1111.01 but retaining the sign bits
and inverting the other bits gives: 1000.10

In two’s complement representation, positive numbers are represented in the “normal” manner
(same as unsigned integers with a zero sign bit), while negative numbers are represented by
complementing all of the bits of the absolute value of the number and adding one. Negation of
a negative number in two’s complement representation is accomplished by complementing all
of the bits and adding one. Addition is performed by adding the two numbers as unsigned
integers and ignoring the carry. Two’s complement has the further advantage that there is only
one zero (all zero bits). Two’s complement representation does result in one more negative
number (all one bits) than positive numbers.

20 | P a g e CTE 221
Two’s complement is used in just about every binary computer ever made. Most processors
have one more negative number than positive numbers. Some processors use the “extra”
neagtive number (all one bits) as a special indicator, depicting invalid results, not a number
(NaN), or other special codes. 2’s complement is used to represent negative numbers because
it allows us to perform the operation of subtraction by actually performing addition. The 2’s
complement of a binary number is the addition of 1 to the rightmost bit of its 1’s complement
equivalence.

Examples

1. Convert -52 to its 2’s complement

The 1’s complement of -52 is 11001011

To convert this to 2’s complement we have

11001011

+ 1

11001100

2. Convert -419 to 2’s complement and hence convert the result to hexadecimal
The sign magnitude representation of -419 on a 16 bit machine is
1000000110100011

The I’s complement is 1111111001011100

To convert this to 2’s complement, we have:

1111111001011100

+ 1

1111111001011101

21 | P a g e CTE 221
Dividing the resulting bits into four 1111 1110 0101 1101gives an
hexadecimal equivalence of FE5D16

Example: Find the 8’s complement of 72458

Answer:

7777

-7245

0532

+1

0533

Thus the 8’s complement of 72458

is 0533

3. Add +9 and +4 for 5 bits machine

= 01001

00100

01101

01101 is equivalent to +13

22 | P a g e CTE 221
EXERCISE FOUR:

1. Find the 1’s complement of -47

2. Find the 1’s complement of -467 and convert the answer to hexadecimal.

3. Convert +47 to binary on an 8 bits machine

4. Convert -7 to binary on a 5 bits machine

5. Convert -567 on a 16 bits machine

6. Using a 5-bit machine add +9 and -4

7. Find the equivalent 2’s complement representation of EF2H

B. FLOATING POINT REPRESENTATIONS


Floating point numbers are the computer equivalent of “scientific notation” or
“engineering notation”. A floating point number consists of a fraction (binary or
decimal) and an exponent (binary or decimal). Both the fraction and the exponent
each have a sign (positive or negative). . Floating point numbers are almost always
binary representations, although a few early processors had (binary coded) decimal
representations. Many processors (especially early mainframes and early
microprocessors) did not have any hardware support for floating point numbers.
Even when commonly available, it was often in an optional processing unit (such as
in the IBM 360/370 series) or coprocessor (such as in the Motorola 680x0 and pre-
Pentium Intel 80x86 series). Hardware floating point support usually consists of
two sizes, called single precision (for the smaller) and double precision (for the
larger). Usually the double precision format had twice as many bits as the single
precision format (hence, the names single and double). Double precision floating
point format offers greater range and precision, while single precision floating point
format offers better space compaction and faster processing.

23 | P a g e CTE 221
CHAPTER FIVE

5.0 REGISTERS

To speed up the processor operations, the processor includes some internal memory storage
locations, called registers. Namely:

I. General purpose Register and

II. Dedicated Register,

GENERAL REGISTERS are further subdivided into −

 Data registers,
 Pointer registers, and
 Index registers.

DATA REGISTER

As 32-bit data register we have:

EAX (Accumulator), EBX (base), ECX (counter), EDX (data)

As 16- bit we have the:

AX, BX, CX, DX which is divided into higher and lower halves i.e

As 8-bit we have AX (AH, AL),

BX (BH, BL),

CX (CH, CL),

DX (DH, DL)

depending on the size of the operand

24 | P a g e CTE 221
POINTER REGISTER:

As 32- bit we have EIP (Instruction pointer), ESP (stack pointer), EBP (base pointer)

As 16- bit we have IP (source index pointer &destination index pointer), SP and BP

Dedicated REGISTERS are also further subdivided into −

 Control registers
 Segment registers.

5.1 ADDRESSING MODE


The process through which the processor controls the execution of instructions is referred to
as the Fetch-Decode-Execute cycle or the execution cycle. It consists of three continuous
steps −
I. Fetching the instruction from memory
II. Decoding or identifying the instruction
III. Executing the instruction
The processor may access one or more bytes of memory at a time. Let us consider a
hexadecimal number 0725H. This number will require two bytes of memory. The high-order
byte or most significant byte is 07 and the low-order byte is 25.
The processor stores data in reverse-byte sequence, i.e., a low-order byte is stored in a low
memory address and a high-order byte in high memory address. So, if the processor brings the
value 0725H from register to memory, it will transfer 25 first to the lower memory address
and 07 to the next memory address.

25 | P a g e CTE 221
x: memory address
When the processor gets the numeric data from memory to register, it again reverses the bytes.
There are two kinds of memory addresses −
Absolute address - a direct reference of specific location.
Segment address (or offset) - starting address of a memory segment with the offset value.
The three basic modes of addressing are −
I. Register addressing
II. Immediate addressing
III. Memory addressing

Example:
i. Determine the value of the Accumulator for the instruction below:
MOV A, #7FH
ADD A, #01H
Answer:

7FH = 0111 1111


01H = + 0000 0001
1000 0000

Accumulator: 80H

ii. Write an assembly language program to copy the value of 50H into RAM
location 60H to 65H using; Register indirect addressing mode with a loop.

Answer:
MOV A, #50 ; A = 50H

MOV R0, #60H ; load pointer R0 = 60H RAM address

MOV R2, #05 ; load counter, R2 = 5

AGAIN: MOV @R0, A ; copy 50H to RAM location which R0 points to

INC R0 ; increment R0 pointer

DJNZ R2, AGAIN ; loop until counter = zero

26 | P a g e CTE 221
5.2 ASSEMBLY - BASIC SYNTAX
An assembly program can be divided into three sections −

I. The data section:- The data section is used for declaring initialized data or constants
II. The bss section:-The bss section is used for declaring variables, and
III. The text section:- The text section is used for keeping the actual code. This section
must begin with the declaration global _start.
Below is a simple assembly language program to print “Hello World”:

.mode1 small

.stack 100h

.data tot db “HelloWorld$”

.code

Start:

Mov ax, @data

Mov ds, ax

Mov ah, 09h

Mov dx, offset tot

Int 21h

Mov ah, 4ch

Int 21h

End start.

27 | P a g e CTE 221
5.3 ASSEMBLY - LOGICAL INSTRUCTIONS
The processor instruction set provides the instructions AND, OR, XOR, TEST, and NOT
Boolean logic, which tests, sets, and clears the bits according to the need of the program.

5.4 ASSEMBLY – CONDITIONS


Conditional execution in assembly language is accomplished by several looping and branching
instructions. These instructions can change the flow of control in a program. Conditional
execution is observed in two scenarios −
I. Unconditional jump
This is performed by the JMP instruction. Conditional execution often involves a transfer of
control to the address of an instruction that does not follow the currently executing instruction.
Transfer of control may be forward, to execute a new set of instructions or backward, to re-
execute the same steps.
II. Conditional jump
This is performed by a set of jump instructions j<condition> depending upon the condition.
The conditional instructions transfer the control by breaking the sequential flow and they do it
by changing the offset value in IP.

Example
Assume that RAM location 30 – 34 have the following values; write a program to
find the sum of the values. [Note Register (A) should contain the low byte and
Register (R7) should contain the high byte, all values are in hex].

30 = (70); 31 = (EB); 32 = (C5); 33 = (5B); 34 = (30)

Answer:

MOV R0, 30H ; load pointer R0 = 30H RAM location

MOV R2, #5 ; load counter R2 = 5

CLR A ;A=0

MOV R7, A ; clear R7

AGAIN: ADD A, @R0 ; Add the byte pointer to A by R0

JNC NEXT ; if CY = 0; don’t accumulate carry

INC R7 ; keep track of carries

28 | P a g e CTE 221
INC R0 ; increment pointer

DJNZ R2, AGAIN ; Repeat until R2 is zero.

EXERCISE FIVE
1. Write a simple Assembly Language program to Print ‘Hello World’ on the screen
2. Explain Assembly Register
3. List any five (5) General purpose Register for x86 microprocessor.
4. Highlight five (5) functions of Addressing mode in the 8086 microprocessor
5. Explain Register Addressing mode with appropriate example

29 | P a g e CTE 221
6.0 CHAPTER SIX
MICROPROCESSOR

A MICROPROCESSOR CAN BE CLASSIFIED INTO THREE CATEGORIES –


RISC PROCESSOR
CISC PROCESSOR
SPECIAL PROCESSOR

These are the processors which are designed for some special purposes

6.1 COMPUTER INSTRUCTION SET

An instruction set is a list of all the instructions, and all their variations, that a processor can
execute.

 Arithmetic such as add and subtract


 Logic instructions such as and, or, and not
 Data instructions such as move, input, output, load, and store
 Control flow instructions such as goto, if ... goto, call, and return.

30 | P a g e CTE 221
An instruction set, or instruction set architecture (ISA), is the part of the computer
architecture related to programming, including the native data types, instructions, registers,
addressing modes, memory architecture, interrupt and exception handling, and external I/O.
An ISA includes a specification of the set of opcodes (machine language), the native
commands implemented by a particular CPU design.

6.2 REDUCED INSTRUCTION SET

The acronym RISC (pronounced risk), for reduced instruction set computing, represents a
CPU design strategy emphasizing the insight that simplified instructions that "do less" may
still provide for higher performance if this simplicity can be utilized to make instructions
execute very quickly. Many proposals for a "precise" definition have been attempted, and the
term is being slowly replaced by the more descriptive load-store architecture. Well known
RISC families include Alpha, ARC, ARM, AVR, MIPS, PA-RISC, Power Architecture
(including PowerPC), SuperH, and SPARC.

RISC stands for Reduced Instruction Set Computer. It is designed to reduce the execution
time by simplifying the instruction set of the computer

6.3 COMPLEX INSTRUCTION SET COMPUTER (CISC)

CISC stands for Complex Instruction Set Computer. It is designed to minimize the number
of instructions per program, ignoring the number of cycles per instruction

31 | P a g e CTE 221
TEST EXECISE
1. Write a simple Assembly Language program to Print ‘Hello World’ on the screen

2. Itemize five (5) functions of Addressing mode in the 8086 microprocessor


3. Highlight any eight (8) General purpose Register for x86 microprocessor.
4. Explain Assembly Register with respect to Assembly Language.

5. Enumerate five (5) Differences between Assembly Language and Machine


Language.
6. List Merits and Demerits of HLL
7. Explain Low Level Language and give an example.

8. The decimal equivalent of (11101010) 2

9. Convert binary number 101110.01101 to its Hexadecimal equivalent

10.Convert binary number 11101.111011 to its Hexadecimal equivalent

11.Convert (101110.01101)2 to its Octal equivalent

12.Convert (11111.1011)2 to its Octal equivalent

13. Convert 53210 to BCD

14. Convert 26710 to BCD

15.Convert -17 to binary on an 8 bits machine

16. Convert -28 to binary on an 8 bits machine

17. Using a 5-bit machine add -9 and +4 and find its 2’s complement.

18. Using a 5-bit machine Add -9 and +9

19. Find the 2’s complement representation of 76


20. Determine the value of the Accumulator for the instruction below:
MOV A, #6AH
ADD A, #0FH

32 | P a g e CTE 221

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy