0% found this document useful (0 votes)
20 views79 pages

4 Intro To Assembly 1

The document provides an introduction to assembly language and computer organization. It discusses basic computer architecture, microprocessors, evolution of computers, levels of programming languages, advantages and reasons for using assembly language. It also covers topics like memory addressing, word representation, bus interconnection schemes.

Uploaded by

emansheraz7
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)
20 views79 pages

4 Intro To Assembly 1

The document provides an introduction to assembly language and computer organization. It discusses basic computer architecture, microprocessors, evolution of computers, levels of programming languages, advantages and reasons for using assembly language. It also covers topics like memory addressing, word representation, bus interconnection schemes.

Uploaded by

emansheraz7
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/ 79

Computer Organization and Assembly Language

(CS2523)

Introduction to Assembly Language


Chapter 1 of
Assembly language for x88 processors, Belal Hashmi

Department of Computer Science,


Capital University of Science and Technology, Islamabad
Spring Semester, 2023
Lecture Outlines
 Basic Computer Architecture
 Registers
 Instruction Groups
 Intel iapx88 Architecture
 iAPX (Intel Advanced Performance
Architecture with X standing in for the
Greek letter χ (chi), romanised as "ch")
was a short lived designation used for
several Intel microprocessors, including
some 8086 family processors.
Lecture Outlines
 History
 Register Architecture
 Our First Program
 Segmented Memory Model
History

Basic Computer Architecture


What are microprocessor-based systems?
 Microprocessor-based systems are electrical systems
consisting of microprocessors, memories, I/O units, other
peripherals.
 Microprocessors are the brains of the systems

 Microprocessors access memories and other units


through buses
 The operations of microprocessors are controlled by
instructions stored in memories
What are microprocessors?
 A microprocessor is a processor (or Central Processing Unit,
CPU) fabricated on a single integrated circuit.
 MAR – Memory Address Register
Evolution of Computers
1. First Generation (1939-1954) – vacuum tube
2. Second Generation (1954-1959) – transistor
3. Third Generation (1959-1971) – IC
4. Fourth Generation (1971-present) – microprocessor
 Microprocessor is an intelligent piece of integrated circuits. It
forms the brain of circuits that require computing capability.

 A microprocessor is an integrated circuit, but not all integrated


circuits are microprocessors
Hardware
• Team from IBM building
PC prototypes in 1979

• 8088 is 8-bit bus version


of 8086 => allows
cheaper system

• Estimated sales of
250,000

[ Personal Computing Ad, 11/81] 8


Levels of Programming Languages
1. Machine Language
 Consists of individual instructions that will be executed by the
CPU one at a time
2. Assembly Language (Low Level Language)
 Designed for a specific family of processors (different processor
groups/family has different Assembly Language)
 Consists of symbolic instructions directly related to machine
language instructions one-for-one and are assembled into
machine language.
3. High Level Languages
 e.g. : C, C++
 Designed to eliminate the technicalities of a particular
computer.
 Statements compiled in a high level language typically generate
Advantages of Assembly Language

1.Shows how program interfaces with the


processor, operating system, and BIOS.
2.Shows how data is represented and stored in
memory and on external devices.
3.Clarifies how processor accesses and
executes instructions and how instructions
access and process data.
4.Clarifies how a program accesses external
devices.
Reasons for using Assembly Language
1. A program written in Assembly Language requires considerably
less memory and execution time than one written in a high-
level language.
2. Assembly Language gives a programmer the ability to perform
highly technical tasks that would be difficult, if not impossible
in a high-level language.
3. Although most software specialists develop new applications
in high-level languages, which are easier to write and
maintain, a common practice is to recode in assembly
language those sections that are time-critical.
4. Resident programs (that reside in memory while other
program execute) and interrupt service routines (that handle
input and output) are almost always develop in Assembly
Language.
Reasons for using Assembly Language

 Assembly language is a low-level


programming language that provides direct
access to the hardware of a computer.

 Here are some examples of real-world use for


assembly language:
Reasons for using Assembly Language

1. Operating Systems:
 Assembly language is often used in the
development of operating systems, as it
provides low-level access to the system's
hardware and is capable of executing
critical operations that are not possible
with higher-level languages.
Reasons for using Assembly Language

2. Device Drivers:
 Assembly language is used to develop
device drivers, which are software
components that allow a computer to
interact with specific hardware devices.
Reasons for using Assembly Language

3. Embedded Systems:
 Assembly language is widely used in the
development of embedded systems,
such as microcontrollers and other
specialized devices that have limited
processing power and memory.
Reasons for using Assembly Language

4. Performance-critical applications:
 Assembly language can be used to
optimize performance-critical sections of
code in high-performance applications,
such as video games, simulations, and
scientific computing.
Reasons for using Assembly Language

5. Reverse Engineering:
 Assembly language is often used in
reverse engineering, as it provides a
detailed understanding of the
underlying machine code and can be
used to analyze malware, debug
software, and study the internal
workings of operating systems and
other software.
Reasons for using Assembly Language
 These were some examples of the real-world use of
assembly language.

 Although it is not as widely used as higher-level


programming languages, assembly language continues to
play an important role in many critical applications due to
its low-level access to the computer's hardware and its
ability to execute complex operations efficiently.
Dimensions of Memory
Horizontal Dimensions = Width of Memory Cell

00000000
00000001
Binary Vertical
Dimensions

Addresses
=

Of
Size of

Memory 00100011 Memory

00100100
Cells
00100101 20
Addressing Data in Memory
 Intel Personal Computer (PC) addresses its memory
according to bytes. (Every byte has a unique
address beginning with 0)

 Depending to the model of a CP, CPU can access 1


or more bytes at a time.

 Processor (CPU) keeps data in memory in reverse


bye sequence (reverse-byte sequence: low order
byte low memory address and high-order byte in
the high memory address.
Addressing Data in Memory
Example: Consider value 052916 (0529H)

When the processor takes data (a word or 2 bytes), it


will re-reverse the byte to its actual order 052916
fir.lst: Word Representation (Little Endian, Big Endian)

23
Word Representation

• When we have number of 16 bit or greater than we have to decide


how to place the number in the memory which means that what
will be the byte order.

• Intel uses little endian Notation which means that lesser


significant byte at lesser address.

• For the example of assembly code

• The instruction add ax,bx the value shown by the list file i.e. fir.lst is
01D8 this is a two byte instruction and 01 is the opcode of add and
the D8 shows two registers ie ax,bx

• Generally we can not change the values of these two registers


Word Representation

• 4 Byte Word MSB LSB

• Representation in Memory
Representation 1
Little Endian
MSB LSB
Notation
3 2 1 0

Representation 2
Big Endian
LSB MSB
Notation
0 1 2 3
Bus Interconnection Scheme
...ha?
Some buzz words
CISC – Complex Instruction Set Computers
• Refers to number and complexity of instructions
• Improvements was: Multiply and Divide
• The number of instruction increased from
• 45 on 4004 to:
• 246 on 8085
• 20,000 on 8086 and 8088

RISC – Reduced Instruction Set Computer


• Executes one instruction per clock

Newer RISC - Superscaler Technology


• Execute more than one instruction per clock
Computer Organization
• Computer Organization is concerned with the
structure and behavior of a computer system as seen
by the user.

• It acts as the interface between hardware and software.

• It deals with the components of a connection in a system.

• Computer Architecture helps us to understand the


functionalities of a system.
Buses
• There are a number of possible
interconnection systems

• e.g. Control/Address/Data bus (PC)

• What is a Bus?
• A communication pathway connecting two or more devices
• A number of channels in one bus
• e.g. 32 bit data bus is 32 separate single bit channels
Computer Organization

• Address bus - carries memory addresses from the processor


to other components such as primary storage and input/output
devices. The address bus is unidirectional.

• Identify the source or destination of data e.g. CPU needs to


read an instruction (data) from a given location in memory

• Bus width determines maximum memory capacity of system


e.g. 8080 has 16 bit address bus giving 64k address space
Computer Organization
• Data bus - carries the data between the processor and
other components. The data bus is bidirectional .

• Carries data

• Remember that there is no difference between “data”


and “instruction” at this level

• Width is a key determinant of performance


8, 16, 32, 64 bit
Computer Organization
• Control bus - carries control signals from the processor to other
components. The control bus also carries the clock's pulses. The control
bus is bidirectional. For example to communicate from other devices
to processor that other device is busy or having some issue to get data
from the required address.

• Control and timing information

• Memory read/write signal

• Interrupt request

• Clock signals
Basic Computer Organization

Processor Memory

I/O

34
Basic Computer Organization

Processor Memory Data


Operation

35
Basic Computer Organization

Processor Memory Data


Operation

36
Basic Computer Organization

Address Bus

Data Bus
Processor Memory
Control Bus

37
Big and Yellow?

What do buses look like?


• Parallel lines on circuit boards
• Ribbon cables
• Strip connectors on mother boards
e.g. PCI, Sets of wires

• Peripheral Component Interconnect (PCI) is a


local computer bus for attaching hardware
devices in a computer and is part of
the PCI Local Bus standard.
Physical Realization of Bus Architecture
Timing

• Co-ordination of events on bus


• Synchronous
• Events determined by clock signals
• Control Bus includes clock line
• A single 1-0 is a bus cycle
• All devices can read clock line
• Usually sync on leading edge
• Usually a single cycle for an event
Synchronous Timing Diagram
Asynchronous Timing
– Read Diagram
Asynchronous Timing
– Write Diagram
The Computer Organization – INTEL PC
 Below is a brief description of the development of a INTEL
model which we are going to cover in the course:
1. 8088
 Has 16-bit registers and 8-bit data bus
 Able to address up to 1 MB of internal memory
 Although registers can store up to 16-bits at a time but the
data bus is only able to transfer 8 bit data at one time
2. 8086
 Is similar to 8088 but has a 16-bit data bus and runs faster.
Inside The 8088/8086

Concepts important to the internal operation of


8088/8086

Pipelining
Registers
Inside The 8088/8086…pipelining

Pipelining
Two ways to make CPU process information faster:
Increase the working frequency – technology dependent
Change the internal architecture of the CPU
Pipelining is to allow CPU to fetch and execute at the same time
Inside The 8088/8086…pipelining

Intel implemented the concept of pipelining by splitting


the internal structure of the 8088/8086 into two
sections that works simultaneously:

Execution Unit (EU) – executes instructions previously fetched

Bus Interface Unit (BIU) – accesses memory and peripherals


The Computer Organization – INTEL PC
 In performing its task, the processor (CPU) is partitioned into two
logical units:
1. An Execution Unit (EU)
 EU is responsible for program execution.
 Contains of an Arithmetic Logic Unit (ALU), a Control Unit
(CU) and a number of registers.
2. A Bus Interface Unit (BIU)
 Delivers data and instructions to the EU.

 Manage the bus control unit, segment registers and


instruction queue.
 The BIU controls the buses that transfer the data to the EU,
to memory and to external input/output devices, whereas
the segment registers control memory addressing.
The Computer Organization – INTEL PC
 EU and BIU work in parallel, with the BIU keeping one step ahead.
 The EU will notify the BIU when it needs to data in memory or an
I/O device or obtain instruction from the BIU instruction queue.

 When EU executes an instruction, BIU will fetch the next


instruction from the memory and insert it into instruction queue.
CPU
Architecture of
8086/8088c

50
Registers
Registers:

1. Benefits of Registers.
2. Types of Registers.
3. General Purpose Registers.

52
CPU Architecture of 8086/8088c

8088 and 8086 are functionally identical (16-


bit CPU) except that 8088 uses 8 data lines
in its data bus while 8086 uses 16 data lines
in its data bus.

53
CPU Architecture of 8086/8088c
The 8086/8088 microprocessor consists of four functional units.
1) Execution unit (EU): decodes and executes machine
instructions.
2) Arithmetic and logic unit (ALU): performs math and logical

operations on command by the EU.


3) Internal storage (sometime called registers): is used for internal

data storage.
4) Bus interface unit (BIU): handles all communications with the
54
I/O via system bus and maintains instruction queue.
In the World of Computer,
Registers are no more like childhood notebooks…

In which we used to note our school work.

55
Basic Computer Organization

REGISTERS

In the world of computer, registers are inside


processor.

56
Registers in Assembly Language:

57
Basic Computer Organization

Why registers are compulsory???


We’ll understand this with the help of an example.

58
Houses:
Memory
Buses Allocations in
RAM

59
Main Memory OR RAM
Suppose this is a processor
Basic Computer Organization

Why registers are compulsory???


We’ll understand this with the help of an example.
Example:
Suppose you have to calculate the sum of two
numbers.
After calculation, store result in sum variable.

60
To calculate the sum,
We first declare a variable.
By this, memory for variable is allocated in the memory

After declaration of variables, if we take input from user,


Those
Then declare another inputs or
variable would appear
second in the corresponding memory
variable.
locations.
Memory would be allocated for this variable too.

61
Basic Computer Organization

Now we have to send both the numbers (values of


variables) to processor.

Only then processor can do some operation on those


numbers.

62
Communication via Buses

1. First message would be sent via Control Bus if


we want to read a number.

2. At the same time, processor would send the


address via Address Bus to tell that from this
address of memory, send me the number.

3. Then Memory would place the number in the


Data Bus.
63
Memory has sent
Nowthe num1:would definitely need the second
processor
number too for the addition of two numbers.

64
Memory has sent the first number
The following same procedure would repeat
to get the second number from memory
1. First message would be sent via Control Bus if we want to read a second
number.

2. At the same time, processor would send the address via Address Bus to tell that
from this address of memory, send me the number.

3. Then Memory would place the second number in the Data Bus.

What would happen to the first number which was already present in the Data Bus???
That first number would be wasted. As Data Bus now would have the second number.
So, that was the issue. When Data Bus would get second number, then the first number
would get vanished.
To calculate the sum of two numbers, processor would need two numbers at the same
time.
To solve this problems, registers were developed.
65
Registers

1. Now when RAM had given the first number, we have


stored this first number into the register.

2. Then the processor asks the memory for the second


number, now the second number is in the Data Bus.

3. Now processor would take first number from register


and second number from Data Bus, Add these two
numbers and store the result into new memory
location.
66
That was the benefit of the register!!!
What is Operand?

There are many memory allocations in the RAM.


Means a lot of data in the RAM.

The type of Data on which processor has to do


processing is known as Operand.
e.g. num1 and num2 are two operands.

So, Register is basically a temporary place to store


data on temporary basis. It is very close to CPU. It is
inside the processor, that’s why processing would get
67
Faster.
Why processing is faster in registers?

If processor has to take data from RAM, then how many steps
processor has to perform?

Processor send message via Control Bus, send address via Address
to RAM, and then processor waits for the RAM to send data via
Data Bus.

To take data from registers:


Processor does not need to send message via Control Bus, does not
need to send address via Address Bus, and does not have to wait to
have data on Data Bus.

It is time saving for processor to get data directly from registers. So,
68
processing gets faster because of registers.
Inside The 8088/8086…registers

Types of Registers AX
To store information temporarily 16-bit register
AH AL
8-bit reg. 8-bit reg.
Category Bits Register Names

General 16 AX, BX, CX, DX


Special Purpose Registers

8 AH, AL, BH, BL, CH, CL, DH, DL


Pointer 16 SP (stack pointer), BP (base pointer)
Index 16 SI (source index), DI (destination index)
Segment 16 CS (code segment), DS (data segment)
SS (stack segment), ES (extra segment)
Instruction 16 IP (instruction pointer)
Flag 16 x = size
FR (flag register)
General Purpose registers are also known as Multi Purpose Registers.
Anatomy of a Register

Extended Register
Word Register

Bits 16-31 Bits 8-15 Bits 0-7

High Byte Low Byte


Register Register
General Registers

32 bit Registers 16 bit Registers 8 bit Registers

EAX EBP AX BP AH AL

EBX ESI BX SI BH BL

ECX EDI CX DI CH CL

EDX ESP DX SP DH DL
Bits 16-31 Bits 8-15 Bits 0-7
OR Destination
CPU word size/ CPU width: It means how many no. of bits that can be
processed by CPU.
Size of Accumulator decides the size of CPU word size.

74
Common thing in General Purpose Registers:
All the General Purpose Registers can be used to take
inputs, to display outputs and to store intermediate results.
We store data in General Purpose Registers with the help of
instructions.

75
1. AX: Accumulator Register involves in each operation:

It involves in taking input, output, and even to hold intermediate results.

In other words we can say that Accumulator is used to perform Mathematical,


Arithmetic and Logical operations.

Also if we want to store address of other memory location, for this purpose again
accumulator can be used.

76
2. BX: Base Register:

Suppose you have created an Array “A” in the memory. Then name of the array
i.e. A would represent the starting address of the array. Starting address is also
known as Base Address. Base Address is used to store the starting address of any
Data Structure.

0 1 2 3 4 5

Base address = starting address


77
3. CX: Counter Register:
Suppose a loop in c++ with loop counter variable i. We call the value of i the
counter. It is counting one by one on each iteration of the loop. It compares with
register again and again. On increment, it adds one to the register. So, the value of
counter is stored in CX variable.

78
4. DX: Destination Register:
It is basically used for destinations. We can store the final output of the operations in it.

Answer of num1*num2 is in 32 bits.


Size of Accumulator was 16 bits. So, this answer cannot be stored in Accumulator.
If we would try to save 32 bits answer in Accumulator, only 16 bits would be saved
in Accumulator. What would happen to the remaining 16 bits:
Two options:
Only store 16 bits and discard the remaining 16 bits.
If we don’t want to discard our data, then we can store 16 bits in AX and store the
remaining 16 bits in the DX. So, our data would not get discard.
79

You might also like