Assembly Language and Structures of Microcomputer | Chap-1

18
Nafis’s Classroom Organization of Computer System and Assembly Language Primer [email protected] Chapter - 1

description

The first chapter of Assembly Language Programming explains the memory, cpu, i/o devices, how instructions are executed. It starts off by discussing bytes, words, organization of memory and how are buses used as communication lines that works as the artery of the computer system. It also dives into explaining how the Execution Unit and Bus Interface Unit simultaneously work to execute instructions in a CPU, taking the example of Intel 8086 microprocessor. Then, the chapter explains are circuit timing works using a simple Voltage against Time graph. It closes with an example of a simple program written in both Assembly Language and in Machine Language.

Transcript of Assembly Language and Structures of Microcomputer | Chap-1

Page 1: Assembly Language and Structures of Microcomputer | Chap-1

Nafis’s Classroom

Organization of Computer System and Assembly Language Primer

[email protected]

Chapter - 1

Page 2: Assembly Language and Structures of Microcomputer | Chap-1

Overview : Organization of Computer System

• A computer system consists of system unit, I/O (input and output) devices like keyboard, display screen and disk drives

• IC (integrated-circuits) chips contain thousands of transistors that are used to construct computer circuits

• IC circuits are also known as digital circuits

• Digital circuits/IC circuits have voltage signal levels

• High voltage = 1 & Low voltage = 0

• 1 and 0 are binary digits or bits

• A string of 1s and 0s is called a bit string

• CPU consists of the system board/motherboard that contains memory circuits and microprocessor

• Motherboard has additional expansion slots for connecting extra circuit boards/add-in boards/add-in cards

Page 3: Assembly Language and Structures of Microcomputer | Chap-1

TIME FOR SOME BASICS!

RAM & ROM, Bus, CPU Architecture, Memory operations, I/O Devices, Discussion on Programming Languages, A Glance at Assembly Language

Page 4: Assembly Language and Structures of Microcomputer | Chap-1

Memory: Address, Contents, Bits

• Information in our computer are stored in memory and a memory circuit can store 1 bit of data

• Memory circuits are grouped to store a string of 8 bits of data

• A string of 8 bits = 1 byte of data/information

• Each memory byte/memory circuit byte has a distinctive numeric address, like street addresses. – Address counting starts from zero/0

– Data stored inside a memory byte is called Content

0 1 1 0 1 0 1 1

0 1 1 0 0 0 1 0

0 1 0 0 1 0 0 0

0 0 0 0 1 0 1 1

0

1

2

3

Contents

Address

• Number of bits in addresses depends on microprocessor architecture

• Addresses are fixed

• Contents can change • Memory byte will always have

8 bits of data

Page 5: Assembly Language and Structures of Microcomputer | Chap-1

Memory: Word, Bit Positioning

• 2 bytes form a Word/Memory Word in a memory

• Numbering for bit positions starts from right like Arabic writing

• 0-7 forms the low-byte in a word

15 13 12 11 10 9 8 7 6 5 4 3 2 1 0

7 6 5 4 3 2 1 0

Byte bit position

Word bit position

8 bytes

2 bytes = Word

Low-byte High-byte

• 8-15 forms the high-byte in a word

2 bytes for a Word

Page 6: Assembly Language and Structures of Microcomputer | Chap-1

Memory Operations & RAM, ROM

Memory Operations

• A processor can perform two types of memory operations on the memory • Read/Fetch – The original contents

are unchanged and the processor can only copy the data

• Write/Store – The original contents are replaced by new contents

RAM • Random Access Memory/RAM

memory can be read and written • RAM cannot retain/store the

information after the computer is turned off. – RAM stores data temporarily – Program instructions are loaded into

RAM

ROM

• Read Only Memory/ROM memory can be used to only read data only

• ROM are used to store system programs which are known as firmware

• Also used for self-testing purpose

Page 7: Assembly Language and Structures of Microcomputer | Chap-1

Buses

• Buses are communication lines in between the CPU, Memory and I/O devices which send signals through wires

• There are 3 types of buses:

– Address Bus: Addresses of the memory locations/memory byte is placed inside this by the CPU

– Data Bus: The memory sends back the contents of the address as requested by the CPU through this bus

– Control Bus: The CPU, for example, places the read operation command on the control bus that will be sent to the memory

CPU Memory I/O

Data Bus

Address Bus

Control Bus

Page 8: Assembly Language and Structures of Microcomputer | Chap-1

Overview of CPU

• CPU = Central Processing Unit

• CPU is the brain of the computer and executes program stored inside the memory

• CPU is divided into two main units: – EU = Execution Unit

– BIU = Bus Interface Unit

• A CPU executes programs in the form of instructions that are essentially bit strings (for instance, Intel 8086 instructions are 1 to 6 bytes long) – This instructions are group into Instruction Sets and they are written in Machine

Language

Page 9: Assembly Language and Structures of Microcomputer | Chap-1

AX

BX

CX

DX

SP

BP

SI

DI

CS

DS

SS

ES

IP

Internal Bus

Temporary Registers

Bus Control

Logic

ALU

Flags

Execution queue

General Registers

External Bus

Bus Interface Unit (BIU)

Execution Unit (EU)

Intel 8086 Architecture

Page 10: Assembly Language and Structures of Microcomputer | Chap-1

Execution Unit (EU)

• Execution Unit executes instructions that is sent by the BIU

• The parts of the EU are: – Arithmetic & Logic Unit (ALU): Performs

basic arithmetic operations like (+,-,/,*) and logic operations (OR, NOT,AND)

– General Registers: Are circuits that are memories for storing data for operations. These memories are called by their names as, for example, AX, but not using their numeric addresses. There are 8 General Registers.

– Temporary Registers: Are memories that store operands for ALU

– FLAGS Registers: Are memories used for storing results in bits after a certain calculation is complete

AX

BX

CX

DX

SP

BP

SI

DI

ALU

Flags

Execution Unit (EU)

Temporary Registers

Internal Bus

Page 11: Assembly Language and Structures of Microcomputer | Chap-1

Bus Interface Unit (BIU)

• BIU works as the secretary for the EU

• BIU and EU works simultaneously – While the EU execute instructions, the BIU

fetches/reads 6 bytes of data and places them in the Execution queue and this is called Instruction Prefetch

– When the EU directly needs to communicate with the memory or I/O devices, the BIU suspend its operation

• BIU assists in the communication between the EU and the memory or I/O devices

• It transmits address, data and control signals on the external and internal buses

• Holds 5 registers that store addresses for memory locations – IP/Instruction Pointer : Contains the address of

the next instruction that will be sent to the EU for execution

CS

DS

SS

ES

IP

Bus Control

Logic

Execution queue

External Bus

Bus Interface Unit (BIU)

Page 12: Assembly Language and Structures of Microcomputer | Chap-1

How Instructions Are Executed

• An instruction goes through the process of fetch-execute cycle inside the CPU – Fetch:

• Fetch the instruction from the memory

• Decode the received instruction to obtain the operation

• Fetch/Reread data from memory if required

– Execute: • Perfrom the required operation on the data

• Store or replace the old data in the memory with the new data if necessary

• A machine instruction, written in 0s & 1s, have two parts: – Opcode: It specifies the type of operation that will be executed

– Operand: They are given memory addresses of data that will be operated on

Page 13: Assembly Language and Structures of Microcomputer | Chap-1

Explaining Fetch-Execute Cycle 1

• This analogy will use the instruction execution in Intel 8086 microprocessor – The instruction will be fetched from the memory that resides at the address 0 and

ADDED with the data stored in the AX Register by the ALU and then address 0 will be updated with the new data0

• Fetch : The cycle is initiated by the BIU. The BIU places a read request/command on the control bus and the numeric address of 0, that it requires, on the address bus. It receives the requested data on the data bus. The contents will look something like 00110010 ….. . The BIU receives up to 4 bytes of information but the EU can only handle 2 bytes or a word at a time, hence the next 2 bytes are stored in the IP

• Decode : A decoding circuit inside the EU determines by decoding the information that an ADD operation must be carried out on the contents from the memory with the data on AX Register

Page 14: Assembly Language and Structures of Microcomputer | Chap-1

Explaining Instruction Execution 2

• Fetch/Reread Contents from memory : In the previous fetch operation the CPU requested for operation instruction, i.e, what sort of operation shall the EU execute on the contents with the data on the AX Register. In this fetch operation, this time it receives the actual contents from the memory and the contents are stored in the Temporary Register for execution

• Perform : The data from the AX Register and the Temporary register are added together in the ALU and the sum is stored inside it.

• Update memory : The computational results are forwarded to the BIU. The BIU places the address on the address bus, a write request on control bus and the newly calculated data on the data bus.

Page 15: Assembly Language and Structures of Microcomputer | Chap-1

Timing & Clock Pulses • A clock circuit controls the

processor by a train of clock pulses – The time between two pulses is

known as the clock period

– The number of pulses per second is known as clock rate/clock speed

– Clock speed is measured in gigahertz (1billion cycles per second)

• Computer circuits are activated by clock pulses – Instruction fetching and execution

requires one or more clock periods

• Ex: A multiplication operation takes more than 70 clock periods in x86 Intel architecture

– If a clock circuit is made faster, then the processor operates faster

Voltage

Time

1 period

Page 16: Assembly Language and Structures of Microcomputer | Chap-1

I/O Devices & Ports

• I/O devices are connected to the computer with the I/O circuits – Each I/O circuit contains several registers known as I/O Ports

• Some of the I/O Ports are used for data and others are used for storing commands

• I/O Ports have their own addresses called I/O Addresses, which are connected to system buses

• I/O addresses can only hold contents that are typically input and output instructions

– Data to be inputted are sent to the I/O Ports by the I/O so that the CPU can fetch them

– Data is written on the I/O Ports which is transmitted as signals to the I/O devices

• Serial Ports: Data transfer between the I/O ports and the I/O devices can occur 1 bit at a time. Serial Ports are used by slower devices like keyboard

• Parallel Ports: Data transfer between the I/O ports and the I/O devices can occur 8/16 bit at a time. Parallel Ports are used by faster devices like disk drives.

Page 17: Assembly Language and Structures of Microcomputer | Chap-1

Assembly & Machine Language

Machine Language

1. 10100001 00000000 00000000

2. 00000101 00000100 00000000

3. 10100011 00000000 00000000

Assembly Language

1. MOV AX, A

2. ADD AX, 4

3. MOV A, AX

1. Fetch/read contents from address A (assembly language uses symbols to represent memory addresses, hence 0 is A) and place it in register AX

2. Add 4 to AX 3. Update the address A with the new contents replacing the old

contents

Compiler: Compilers are programs that translate High-level languages, like C++, Java, Actionscript, to Machine language

Assembler: Assemblers are programs that translate Assembly language to Machine instructions

Page 18: Assembly Language and Structures of Microcomputer | Chap-1

Happy Coding &

Salam