0% found this document useful (0 votes)
35 views

Microprocessor I - Lecture 01

Dr. Ahmed ElShafee gave a lecture on microprocessors and assembly language. He began by explaining the basic components of a computer and how the CPU, memory, and system bus interact. He then discussed the general purpose registers inside the CPU and their uses. The lecture covered data movement and arithmetic instructions in assembly language. Examples were given of injecting assembly code into C++ programs and for pure assembly programs.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Microprocessor I - Lecture 01

Dr. Ahmed ElShafee gave a lecture on microprocessors and assembly language. He began by explaining the basic components of a computer and how the CPU, memory, and system bus interact. He then discussed the general purpose registers inside the CPU and their uses. The lecture covered data movement and arithmetic instructions in assembly language. Examples were given of injecting assembly code into C++ programs and for pure assembly programs.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Lecture (01)

By:
Dr. Ahmed ElShafee

1 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1


• Assembly language is a low level programming language. You
need to get some knowledge about computer structure in
order to understand anything.
• The simple computer model as I see it:

2 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1


• The system bus (shown in yellow) connects the various
components of a computer.
• The CPU is the heart of the computer, most of computations
occur inside the CPU.
• RAM is a place to where the programs are loaded in order to
be executed.

3 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1


• Inside the CPU

4 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1


• GENERAL PURPOSE REGISTERS
• 8086 CPU has 8 general purpose registers, each register has
its own name:
• · AX - the accumulator register (divided into AH / AL).
• · BX - the base address register (divided into BH / BL).
• · CX - the count register (divided into CH / CL).
• · DX - the data register (divided into DH / DL).
• · SI - source index register.
• · DI - destination index register.
• · BP - base pointer.
• · SP - stack pointer.
5 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1
• Despite the name of a register, it's the programmer who
determines the usage for each general purpose register. The
main purpose of a register is to keep a number (variable).
• The size of the above registers is 16 bit, it's something like:
0011000000111001b (in binary form), or 12345 in decimal
(human) form.
• 4 general purpose registers (AX, BX, CX, DX) are made of two
separate 8 bit registers, for example if AX=
0011000000111001b, then AH=00110000b and
AL=00111001b.

6 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1


• Therefore, when you modify any of the 8 bit registers 16 bit
register is also updated, and vice-versa.
• The same is for other 3 registers, "H" is for high and "L" is for
low part.
• Because registers are located inside the CPU, they are much
faster than memory.
• Accessing a memory location requires the use of a system bus,
so it takes much longer.
• Accessing data in a register usually takes no time.

7 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1


• Therefore, you should try to keep variables in the registers.
• Register sets are very small and most registers have special
purposes which limit their use as variables, but they are still
an excellent place to store temporary data of calculations.

8 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1


C VS Assembly
• Mov : Data Movement Instruction
• The mov instruction copies the data item referred to by its
second operand (i.e. register contents, memory contents, or a
constant value) into the location referred to by its first
operand
• Syntax
mov <reg>,<reg>
mov <reg>,<mem>
mov <mem>,<reg>
mov <reg>,<const>
mov <mem>,<const>

9 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1


• Arithmetic and Logic Instructions
• add — Integer Addition The add instruction adds together its
two operands, storing the result in its first operand
• Syntax
add <reg>,<reg>
add <reg>,<mem>
add <mem>,<reg>
add <reg>,<con>
add <mem>,<con>

10 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1


Example 01
We learned
that before,…
so what’s new

Native C++
high level
language

11 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1


12 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1
Example 02, injecting Assembly
into C++ code
• move
contents of
two memory
locations in
two registers
Execute
addition
inside
processor,
move result
back to
memory
13 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1
14 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1
Example 03, injecting Assembly
into C++ code
• move contents
of one memory
locations in one
register
Execute addition
inside processor
between
memory location
and register put
result onto
register then,
move result back
to memory
15 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1

16 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1


Example 04, injecting Assembly
into C++ code
move contents of
one memory
locations in one
register
Execute addition
inside processor
between memory
location and
register put result
onto memory
location then,
move result back
to memory
17 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1

18 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1


Pure Assembly
• Variables
• Variable is a memory location. For a programmer it is much
easier to have some value be kept in a variable named "var1“
• Assembly supports two types of variables: BYTE and WORD.
• Syntax for a variable declaration:
– name DB value
– name DW value
– DB - stays for Define Byte.
– DW - stays for Define Word.

19 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1


– name - can be any letter or digit combination, though it
should start with a letter. It's possible to declare unnamed
variables by not specifying the name (this variable will
have an address but no name).
– value - can be any numeric value in any supported
numbering system (hexadecimal, binary, or decimal), or
"?" symbol for variables that are not initialized.

20 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1


Example 01
Moving two
memory
locations to two
registers,
execute
addition inside
processor,
move result
back to
memory
location

21 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1


22 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1
23 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1
24 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1
25 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1
26 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1
Thanks,..

27 Dr. Ahmed ElShafee, ACU : Fall 2022, Microprocessors 1

You might also like