0% found this document useful (0 votes)
41 views26 pages

Chapter 1

The document provides an introduction to microprocessors and assembly language programming. It discusses the architecture of microprocessors including registers, buses, and instruction sets. It also explains the basic functions of a microprocessor like performing arithmetic operations, moving data, and making decisions. Key components like the ALU, program counter, and memory are described. Finally, it provides an example assembly language program to calculate a factorial and compares it to a high-level language program.

Uploaded by

Nardos Tesema
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views26 pages

Chapter 1

The document provides an introduction to microprocessors and assembly language programming. It discusses the architecture of microprocessors including registers, buses, and instruction sets. It also explains the basic functions of a microprocessor like performing arithmetic operations, moving data, and making decisions. Key components like the ALU, program counter, and memory are described. Finally, it provides an example assembly language program to calculate a factorial and compares it to a high-level language program.

Uploaded by

Nardos Tesema
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Microprocessor and Assembly

Language Programming
Chapter 1
Introduction
• In general, the following points should be
emphasized before learning an Assembly Language
programming:

 Getting to know the architecture of a


Microprocessor (the registers, the buses, the bus
width etc.. and how it communicates with Memory)
 Getting to know the assembly instruction set of the
Microprocessor and their syntaxes.
 Getting to know the assembler platform you are
working on.
Microprocessor Logic
• A microprocessor executes a collection of machine
instructions that tell the processor what to do.
• Based on the instructions, a microprocessor does three basic
things:
• Using its ALU (Arithmetic/Logic Unit), a microprocessor can
perform mathematical operations like addition, subtraction,
multiplication and division.
– Modern microprocessors contain complete floating point
processors that can perform extremely sophisticated
operations on large floating point numbers.
• A microprocessor can move data from one memory location
to another.
• A microprocessor can make decisions and jump to a new set
of instructions based on those decisions.
• This microprocessor has:
 An address bus (that may be 8, 16 or 32 bits wide) that
sends an address to memory
 A data bus (that may be 8, 16 or 32 bits wide) that can
send data to memory or receive data from memory
 An RD (read) and WR (write) line to tell the memory
whether it wants to set or get the addressed location
 A clock line that lets a clock pulse sequence the
processor
 A reset line that resets the program counter to zero (or
whatever) and restarts execution
• Let's assume that both the address and data buses are 8
bits wide in this example.
• Here are the components of this simple microprocessor
 Registers A, B and C are simply latches made out of flip-
flops.
 The address latch is just like registers A, B and C.
 The program counter is a latch with the extra ability to
increment by 1 when told to do so, and also to reset to
zero when told to do so.
 The ALU could be as simple as an 8-bit adder or it might
be able to add, subtract, multiply and divide 8-bit values.
Let's assume the latter here.
 The test register is a special latch that can hold
values from comparisons performed in the ALU.
o An ALU can normally compare two numbers and
determine if they are equal, if one is greater than the
other, etc.
o The test register can also normally hold a carry bit
from the last stage of the adder.
o It stores these values in flip-flops and then the
instruction decoder can use the values to make
decisions. In general terms, this is called Flag register.
• A tri-state buffer can pass a 1, a 0 or it can essentially
disconnect its output (imagine a switch that totally
disconnects the output line from the wire that the output
is heading toward).

• A tri-state buffer allows multiple outputs to connect to a


wire, but only one of them to actually drive a 1 or a 0 onto
the line. (Like a multiplexer, but with better capabilities).

• The instruction register and instruction decoder are


responsible for controlling all of the other components.
Microprocessor Memory
• ROM chip
• The buses and lines connect either to RAM or ROM
-- generally both.
• In our sample microprocessor, we have an address
bus 8 bits wide and a data bus 8 bits wide. That
means that the microprocessor can address (28)
256 bytes of memory, and it can read or write 8
bits of the memory at a time.
• Let's assume that this simple microprocessor has
128 bytes of ROM starting at address 0 and 128
bytes of RAM starting at address 128.
• ROM stands for read-only memory.
• A ROM chip is programmed with a permanent
collection of pre-set bytes.
• The address bus tells the ROM chip which byte
to get and place on the data bus.
• When the RD line changes state, the ROM chip
presents the selected byte onto the data bus.
RAM chip

• RAM stands for random-access memory.


• RAM contains bytes of information, and the
microprocessor can read or write to those
bytes depending on whether the RD or WR
line is signaled.
• One problem with RAM chips is that they
forget everything once the power goes off.
That is why the computer needs ROM.
Microprocessor Instructions
• The collection of instructions is implemented as bit
patterns, each one of which has a different meaning when
loaded into the instruction register.
• Humans are not particularly good at remembering bit
patterns, so a set of short words are defined to represent
the different bit patterns.
• This collection of words is called the assembly language of
the processor.
• An assembler can translate the words into their bit
patterns very easily, and then the output of the assembler
is placed in memory for the microprocessor to execute.
Example
• LOADA mem - Load register A from memory address
• LOADB mem - Load register B from memory address
• CONB con - Load a constant value into register B
• SAVEB mem - Save register B to memory address
• SAVEC mem - Save register C to memory address
• ADD - Add A and B and store the result in C
• SUB - Subtract A and B and store the result in C
• MUL - Multiply A and B and store the result in C
• DIV - Divide A and B and store the result in C
• COM - Compare A and B and store the result in test
• JUMP addr - Jump to an address
• JEQ addr - Jump, if equal, to address
• Giving a solution to the problem with this simple piece
of C code and calculate the factorial of 5 (where the
factorial of 5 = 5! = 5 * 4 * 3 * 2 * 1 = 120):

• a=1;
f=1;
while (a <= 5)
{
f = f * a;
a = a + 1;
}
Assembly Language

• // Assume a is at address 128


// Assume F is at address 129
0 CONB 1 // a=1;
1 SAVEB 128
2 CONB 1 // f=1;
3 SAVEB 129
4 LOADA 128 // if a > 5 the jump to 17
5 CONB 5
6 COM
7 JG 17
8 LOADA 129 // f=f*a;
9 LOADB 128
10 MUL
11 SAVEC 129
12 LOADA 128 // a=a+1;
13 CONB 1
14 ADD
15 SAVEC 128
16 JUMP 4 // loop back to if
17 STOP
Factorial sample
• a=1;
f=1;
while (a <= 5)
{
f = f * a;
a = a + 1;
Assembly Language
• // Assume a is at address 128
// Assume F is at address 129
0 CONB 1 // a=1;
1 SAVEB 128
2 CONB 1 // f=1;
3 SAVEB 129
4 LOADA 128 // if a > 5 the jump to 17
5 CONB 5
6 COM
7 JG 17
8 LOADA 129 // f=f*a;
9 LOADB 128
10 MUL
11 SAVEC 129
12 LOADA 128 // a=a+1;
13 CONB 1
14 ADD
15 SAVEC 128
16 JUMP 4 // loop back to if
17 STOP
What is Assembly Language?

• It is a machine (CPU) Specific programming


language.
• There is a one-to-one correspondence between
statements (assembly instruction) and machine
language.
• Matches machine instructions and underlying
architecture.
• More difficult to learn than High Level
Programming language.
What is an Assembler?

• System level software that translates


assembly language source code to machine
language.
Why Learn Assembly?

• Learn how a microprocessor works.


• Understand basic computer Architecture.
• Explore the internal representation of data and instructions.
• Gain an insight into hardware concepts.
• Allows creation of small and efficient programs.
• Allow programmers to bypass high-level programming
language restrictions.
• Might be necessary to accomplish certain tasks, for
example, to program embedded processors inside different
machines.
• Computer Architecture:-is the study of blocks or components
that make up a computer system and how they are
interconnected. Two famous architectures are broadly known:
1) Von Neumann or Stored Program Architecture:
2) Harvard Architecture
Computer Organization:-is concerned with the implementation
of computer architecture.
• Computer Engineering:-is a field of study that concerned with
the actual construction of the system. Examples include
length of wires, size of circuits, cooling, electrical
requirements etc.
Data Organization

 Bits
• The smallest unit of data on a binary
computer is a single bit.
• Since a single bit is capable of representing
only two different values (typically zero or
one) you may get the impression that there
are a very small number of items you can
represent with a single bit.
Nibbles
• A nibble is a collection of four bits.
• It wouldn’t be a particularly interesting data structure except for
two items: BCD (binary coded decimal) numbers and
hexadecimal numbers.
• It takes four bits to represent a single BCD or hexadecimal digit.
• With a nibble, we can represent up to 16 distinct values. In the
case of hexadecimal numbers, the values 0, 1, 2, 3, 4, 5, 6, 7, 8,
9, A, B, C, D, E, and F are represented with four bits (see The
Hexadecimal Numbering System on page 17).
• BCD uses ten different digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) and
requires four bits.
• In fact, any sixteen distinct values can be represented with a
nibble, but hexadecimal and BCD digits are the primary items we
can represent with a single nibble.
Bytes

• Without question, the most important data structure used


by the 80x86 microprocessor is the byte.
• A byte consists of eight bits and is the smallest
addressable datum (data item) on the 80x86
microprocessor.
• Main memory and I/O addresses on the 80x86 are all byte
addresses.
• This means that the smallest item that can be individually
accessed by an 80x 86 programs is an eight-bit value.
• To access anything smaller requires that you read the byte
containing the data and mask out the unwanted bits.
Words

• A word is a group of 16 bits. We will number


the bits in a word starting from zero on up to
fifteen.
Double Words
• A double word is exactly what its name
implies, a pair of words. Therefore, a double
word quantity is 32 bits long .

You might also like