Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 35

WELCOME TO COSC3025

What to expect:
 Microprocessor Architecture, interrupt, interfacing

 Assembly language Concept
Fundamentals
Data Transfer in Memory and Registers
How conditional and Loop Works
Assembly for MP programming
Assembly for OS programming (inline Assembly)
C compiler
Procedure, Macro, Array, String (???)
COURSE LOGISTICS

Course Material:
https://elearning.ju.edu.et/course/view.php
?id=262
Blog:
https://csassembly.weebly.com/
Telegram Group
https://t.me/joinchat/UaLxVm2SWZ7N1I
70
N D
A
O R G E R
S

S
S G U A S
S
O

E
E
C
C N
O LA G R O P
R
O

P R Y N
O L I IC

C R MB M T M O
M

I E A ION
M S R CT
AS OGO D U
PR T R
IN
WHAT IS A MICROPROCESSOR?

A circuit of transistors and other electrical


components on a chip that can process
programs, remember information, or
perform calculations.
The heart of every CPU
Requires programmed input
Advantages over a customized digital circuit
Cost
Scalable © Intel Corp.

Single design – multiple use


DESIGN OBJECTIVES OF MP
Maximize Performance
 Speed of operation: How quickly an operation can be completed
 Throughput: No of operations completed in unit time, not necessarily the same as
speed, consider Servers.

Maximize Productivity
 Interface provided must be easy

Be one step ahead of market needs and two steps ahead of


competition
DRAMATIC PROGRESS OVER THE YEARS

© Intel 4004 Processor


© Intel P4 Processor
 Introduced in 1971
 Introduced in 2000
 2300 Transistors
 42,000,000 Transistors
 108 KHz Clock
 1.5 GHz Clock (Initial)
DESIGN CONSTRAINT
Power consumed
 Today’s processors consume a peak power of 100 W, which means a peak
current of nearly 80A.

Area
Cost
Backward compatibility
 Windows running on Intel P3 Processor should run on Intel P4 too.

Time taken to design the processor should not be very


large or else the competitor may get ahead
Other factors like security, scalability, reliability also need
to be considered in processor design
MARKET
Desktop
 Processor for desktop computers. Cost, backward compatibility are very important. Eg:
Intel Pentium, AMD Athlon
Servers
 Processor for applications requiring huge amount of computation, data handling like
web servers, database servers, scientific computation servers. In general, multiple
processors are used. Throughput is a very important metric for servers in general. Eg:
Google servers, vsnlproxy
Embedded
 For applications in electronic appliances, robots, cars, mobiles etc. Power consumption,
cost are very important metrics. Eg: Microcontrollers like 8051, PIC, specifically
designed processors for cars, mobiles etc.
STRUCTURE

The processor is a computing unit which needs to interact


with memory for getting instructions as well as data

Address Address
(PC) (reg)

Instruction Processor Data


Memory Data Memory
(loads)
Instruction
Data
(stores)
INTERNAL STRUCTURE OF THE PROCESSOR

Control Unit
 Fetches instructions from memory, Interprets them, Controls ALU

ALU
 Does all computations
Register File
 Stores variables

Data Instr
Out Register File Instr In
r1
r2
r3
r4 ALU
Control Control Unit
Data Data (Calculator)
Inst
In Flags Address
PC
Data
Address
EVOLUTION OF MP
Intel Microprocessor History

Intel 8086, 80286


IA-32 processor family
P6 processor family
CISC and RISC
EARLY
•Intel 8080
 –64K addressable RAM
 –8-bit registers
 –CP/M operating system
 –S-100 BUS architecture
 –8-inch floppy disks!
•Intel 8086/8088
 –IBM-PC Used 8088
 –1 MB addressable RAM
 –16-bit registers
 –16-bit data bus (8-bit for 8088)
 –separate floating-point unit (8087)
THE IBM-AT

•Intel 80286
–16 MB addressable RAM
–Protected memory
–several times faster than 8086
–introduced IDE bus architecture
–80287 floating point unit
INTEL IA-32 FAMILY

•Intel386
–4 GB addressable RAM, 32-bit registers,
paging (virtual memory)
•Intel486
–instruction pipelining
•Pentium
–superscalar, 32-bit address bus, 64-bit
internal data path
64-BIT PROCESSORS

•Intel64
–64-bit linear address
–Intel: Pentium Extreme, Xeon, Celeron D,
PendiumD, Core 2, and Core i7
•IA-32e Mode
–Compatibility mode for legacy 16-and 32-bit
applications
–64-bit Mode uses 64-bit addresses and operands
INTEL PROCESSOR FAMILIES

Currently Used:
Pentium & Celeron –dual core
Core 2 Duo -2 processor cores
Core 2 Quad -4 processor cores
Core i7 –4 processor cores
A HIERARCHY OF LANGUAGES
ASSEMBLY AND MACHINE LANGUAGE
Machine language
 Native to a processor: executed directly by hardware
 Instructions consist of binary code: 1s and 0s
Assembly language
 Slightly higher-level language
 Readability of instructions is better than machine language
 One-to-one correspondence with machine language
instructions
Assemblers translate assembly to machine code
Compilers translate high-level programs to machine
code
 Either directly, or
 Indirectly via an assembler
COMPILER AND ASSEMBLER
rg/
DEMO b ol
t. o
od
// g
s:
tp
ht
INSTRUCTIONS AND MACHINE LANGUAGE

Each command of a program is called an


instruction (it instructs the computer
what to do).
Computers only deal with binary data,
hence the instructions must be in binary
format (0s and 1s) .
The set of all instructions (in binary form)
makes up the computer's machine
language. This is also referred to as the
instruction set.
INSTRUCTION FIELDS
Machine language instructions usually are made up of several
fields. Each field specifies different information for the
computer. The major two fields are:
Opcode field which stands for operation code and it specifies
the particular operation that is to be performed.
 Each operation has its unique opcode.
Operands fields which specify where to get the source and
destination operands for the operation specified by the
opcode.
 The source/destination of operands can be a constant, the
memory or one of the general-purpose registers.
ASSEMBLY VS. MACHINE CODE
Instruction Address Machine Code Assembly Instruction
0005 B8 0001 MOV AX, 1
0008 B8 0002 MOV AX, 2
000B B8 0003 MOV AX, 3
000E B8 0004 MOV AX, 4
0011 BB 0001 MOV BX, 1
0014 B9 0001 MOV CX, 1
0017 BA 0001 MOV DX, 1
001A 8B C3 MOV AX, BX
001C 8B C1 MOV AX, CX
001E 8B C2 MOV AX, DX
0020 83 C0 01 ADD AX, 1
0023 83 C0 02 ADD AX, 2
0026 03 C3 ADD AX, BX
0028 03 C1 ADD AX, CX
002A 03 06 0000 ADD AX, i
002E 83 E8 01 SUB AX, 1
0031 2B C3 SUB AX, BX
0033 05 1234 ADD AX, 1234h
TRANSLATING LANGUAGES

English: D is assigned the sum of A times B plus 10.

High-Level Language: D = A * B + 10

A statement in a high-level language is translated typically


into several machine-level instructions

Intel Assembly Language: Intel Machine Language:


mov eax, A A1 00404000
mul B F7 25 00404004
add eax, 10 83 C0 0A
mov D, eax A3 00404008
ADVANTAGES OF HIGH-LEVEL LANGUAGES

Program development is faster


 High-level statements: fewer instructions to code
Program maintenance is easier
Programs are portable
 Contain few machine-dependent details
Can be used with little or no modifications on
different machines
 Compiler translates to the target machine language
 However, Assembly language programs are not
portable
VIRTUAL MACHINE CONCEPT

An effective way to explain how a computer’s hardware and


software are related is called the virtual machine concept.
A computer can usually execute programs written in its
native machine language. Each instruction in this language
is simple enough to be executed using a relatively small
number of electronic circuits. For simplicity, we will call
this language L0.
Programmers would have a difficult time writing programs
in L0 because it is enormously detailed and consists purely
of numbers. If a new language, L1 , could be constructed
that was easier to use, programs could be written in L1.
There are two ways to achieve this:
Interpretation:
As the L1 program is running, each of its
instructions could be decoded and executed by a
program written in language L0. The L1 program
begins running immediately, but each instruction
has to be decoded before it can execute.
Translation:
The entire L1 program could be converted into an
L0 program by an L0 program specifically
designed for this purpose. Then the resulting L0
program could be executed directly on the
computer hardware.
Virtual Machines
Rather than using only languages, it is easier to
think in terms of a hypothetical computer, or
virtual machine , at each level. we can define a
virtual machine as a software program that
emulates the functions of some other physical or
virtual computer.
The virtual machine VM1 , can execute commands
written in language L1. The virtual machine VM0
can execute commands written in language L0.
Each virtual machine can be constructed of either
hardware or software.
WHY LEARN ASSEMBLY LANGUAGE?
Two main reasons:
 Accessibility to system hardware
 To use space and time efficiently

 Some application of assembly languages are:


Real time system. E.g Traffic control system
Embedded system. Where there is no compiler.
E.g Micro chips.
Operating system. Specially kernel part of
operating system. Where direct access of hard
ware is necessary.
ASSEMBLER
Software tools are needed for editing, assembling,
linking, and debugging assembly language programs
An assembler is a program that converts source-code
programs written in assembly language into object
files in machine language
Popular assemblers have emerged over the years for the
Intel family of processors. These include …
 TASM (Turbo Assembler from Borland)
 NASM (Netwide Assembler for both Windows and
Linux), and
 MASM (Macro Assembler from Microsoft)
LINKER AND LINK LIBRARIES

You need a linker program to produce


executable files
It combines your program's object file created
by the assembler with other object files and
link libraries, and produces a single
executable program
LINK32.EXE is the linker program provided
with the MASM distribution for linking 32-
bit programs
ASSEMBLE AND LINK PROCESS

Source Object
File Assembler File

Source Object Executable


File Assembler File Linker
File

Source Object Link


File Assembler File Libraries

A project may consist of multiple source files


Assembler translates each source file separately into an object file
Linker links all object files together with link libraries
WHERE WE CAN WRITE ASSEMBLY

Locally: Online:(NASM)
 MASM
 Tutorial Point As
 NASM
 TASM
sembler
EMULATOR:  JDOODLE
 Emu8086  My-Compiler
 Online
NUMBER SYSTEMS

Decimal Binary (B) Hexadecimal


(D) (H or X)
Zero 0 0 0

Nine 9 1001 9

Ten 10 1010 A

Eleven 11 1011 B

Twelve 12 1100 C

Thirteen 13 1101 D

Fourteen 14 1110 E

Fifteen (Largest 4 bit no.) 15 1111 F

Forty Two 42 0010 1010 2A

Largest 8 bit no. 255 1111 1111 FF

Largest 16 bit no. 65535 1111 1111 1111 1111 FF FF

You might also like