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

Chapter 3

The document discusses CPU architecture details including: 1. The 8086 microprocessor contains 8 general purpose registers - AX, BX, CX, DX, SP, BP, SI, DI that are used for temporary data storage and addressing. 2. The flags register contains status flags like zero, sign, carry, overflow that indicate results of operations. 3. The stack is accessed using the SP and SS registers and instructions like PUSH and POP are used to add and remove data from the stack.
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)
59 views

Chapter 3

The document discusses CPU architecture details including: 1. The 8086 microprocessor contains 8 general purpose registers - AX, BX, CX, DX, SP, BP, SI, DI that are used for temporary data storage and addressing. 2. The flags register contains status flags like zero, sign, carry, overflow that indicate results of operations. 3. The stack is accessed using the SP and SS registers and instructions like PUSH and POP are used to add and remove data from the stack.
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/ 31

Chapter 3:

CPU ARCHITECTURE DETAILS


2 Contents
1. Processor registers
• accumulators
• address registers
• stack pointer (SP) and index registers
• condition code register
2. Flag bits
• Zero, Sign, Carry, Overflow
3. Stack operation in 8086 microprocessor
4. Programmer’s model and introduction to assembly programming.
3
Processor Registers
General-purpose registers are used to store temporary data within the
microprocessor. There are 8 general-purpose registers in the 8086 microprocessor.
1. AX: This is the accumulator. It is of 16 bits and is divided into two 8-bit registers
AH and AL to also perform 8-bit instructions. It is generally used for arithmetical
and logical instructions but in 8086 microprocessor it is not mandatory to have an
accumulator as the destination operand.
Example:
ADD AX, AX (AX = AX + AX)
4
2. BX: This is the base register. It is of 16 bits and is divided into two 8-bit registers
BH and BL to also perform 8-bit instructions. It is used to store the value of the
offset.
Example:
MOV BL, [500] (BL = 500H)
3. CX: This is the counter register. It is of 16 bits and is divided into two 8-bit
registers CH and CL to also perform 8-bit instructions. It is used in looping and
rotation. Example:
MOV CX, 0005
LOOP
5

4. DX: This is the data register. It is of 16 bits and is divided into two 8-bit registers
DH and DL to also perform 8-bit instructions. It is used in the multiplication and
input/output port addressing.
Example:
MUL BX (DX, AX = AX * BX)

5. SP: This is the stack pointer. It is of 16 bits. It points to the topmost item of the
stack. If the stack is empty the stack pointer will be (FFFE)H. Its offset address is
relative to the stack segment.
6

• 6. BP – This is the base pointer. It is of 16 bits. It is primarily used in accessing


parameters passed by the stack. Its offset address is relative to the stack segment.

• 7. SI – This is the source index register. It is of 16 bits. It is used in the pointer


addressing of data and as a source in some string-related operations. Its offset is
relative to the data segment.

• 8. DI – This is the destination index register. It is of 16 bits. It is used in the


pointer addressing of data and as a destination in some string-related
operations. Its offset is relative to the extra segment.
7
Accumulator
•  It is 16-bit registers, but it is divided into two 8-bit registers. These registers are
AH and AL. AX generally used for arithmetic or logical instructions, but it is not
mandatory in 8086.
• Accumulator register is a register that holds temporary values. 
• It is used in arithmetic, logic and data transfer instructions in 8086
microprocessors. In manipulation and division, one of the numbers involved
must be in AX or AL.
8
Address Register
• The 8086 has a total of fourteen 16-bit registers including a 16 bit register called the
status register, with 9 of bits implemented for status and control flags. Most of the
registers contain data/instruction offsets within 64 KB memory segment.
9
Stack Pointer and Index Registers
The index registers are:
• SP (stack pointer)
• BP (base pointer)
• SI (source index)
• DI (destination index
• IP (Instruction Pointer)
10

SP (stack pointer):
• Contains an assumed offset value of the top of the stack
• Combined with the SS register form the complete logical address of the top of the
stack
• The stack is maintained as a LIFO with its bottom at the start of the stack segment
(specified by the SS segment register)
• The top of the stack (the location of the last data in the stack) is specified by the
offset stored in the SP register
11

• BP (base pointer):
• As it is with the stack pointer, this register can hold an offset from the SS register
• It is usually used by subroutines to locate variables that were passed on the stack
by a calling program
• Unlike the SP register, the BP can be used to specify the offset of other program
segments
12

• SI (source index):
• Used in conjunction with the DS register to point to data locations in the data
segment.
• Used with string movement instructions. It would point to the source string.

• DI (destination index):
• Similar function to the SI
• Used in conjunction with the ES register in string operations. In string movement
instructions it points to the destination string
13

• IP (Instruction Pointer):
• This is the register used for accessing instructions
• While the CS register contains the segment number of the next instruction, the IP
contains the offset of that instruction in the code segment
• As was shown in the section on the fetch-execute cycle in the first unit, the IP
register gets updated by the control unit every time an instruction is executed
such that it will always point to the next instruction
• Unlike other registers, the IP can not be manipulated by instructions (i.e. it
cannot appear as an operand in any instruction)
14
Condition Code Registers
• A status register, flag register, or condition code register is a collection of status
flag bits for a processor. An example is the FLAGS register of the x86
architecture. The flags might be part of a larger register, such as a program
status word register.
• Condition codes are extra bits kept by a processor that summarize the results
of an operation and that affect the execution of later instructions. These bits
are often collected together in a single condition or indicator register (CR/IR) or
grouped with other status bits into a status register (PSW/PSR).
15
Flags are discussed in previous Chapter
• To revisit flags here is a short description.
1. Zero Flag (ZF): is set to 1 when result is zero. For non-zero result this flag is set
to 0.
2. Sign Flag (SF): Sign Flag is set to 1 when result is negative. When result is
positive it is set to 0. This flag takes the value of the most significant bit.
3. Carry Flag (CF): Carry Flag is set to 1 when there is an unsigned overflow. For
example when you add bytes 255 + 1 (result is not in range 0…255). When
there is no overflow this flag is set to 0.
16

4. Overflow Flag (OF): Overflow Flag is set to 1 when there is a signed overflow.
For example, when you add bytes 100 + 50 (result is not in range -128…127).
5. Parity Flag (PF): Parity Flag is set to 1 when there is even number of one bits in
result, and to 0 when there is odd number of one bits.
6. Auxiliary Flag (AF): Auxiliary Flag is set to 1 when there is an unsigned
overflow for low nibble (4 bits).
17
Stack operation in 8086 microprocessor
The stack is a block of memory that may be used for temporarily storing the
contents of registers inside CPU.
• Stack is accessed by using SP and SS.
• Stack is a Top Down Data Structure whose elements are accessed by using a
pointer (SP,SS).
• The stack is required when CALL instruction is used.
• Push
• Pop
• Top of stack
• Stack pointer
18
Cont..
The Stack pointer keeps track of the position of the last item placed on the stack
(i.e. the Top of Stack)
The Stack is organized in words, (i.e. two bytes at a time). Thus the stack pointer is
incremented or decremented by 2.
The Stack Pointer points to the last occupied locations on the stack
19
Cont..
20
Stack instructions

Flags: Only affected by the popf instruction Addressing mode: src and dst
should be words and cannot be immediate. dst cannot be the IP or CS
register
21
PUSH & POP
• • The two set of instructions which explicitly modify the stack are the PUSH
(which places items on the stack) and the POP (which retrieves items from the
stack).
• • In both cases, the stack pointer is adjusted accordingly to point always to the
top of stack.
• • Thus PUSH AX means SP=SP-2 and AX -> [SP]
• • POP AX means [SP] -> AX and SP=SP+2.
22 Cont..
23 Example:
• Using the stack, swap the values of the ax and bx registers, so that ax now contains what
bx contained and bx contains what ax contained. (This is not the most efficient way to
exchange the contents of two variables). To carry out this operation, we need at least one
temporary variable:
push ax ; Store ax on stack push
bx ; Store bx on stack
pop ax ; Copy last value on stack to ax
pop bx ; Copy first value to bx
Push ax
Mov ax, bx
Pop bx
24
Introduction to Assembly Language programming
• It teaches you about the way the computer's hardware and operating system work
together and how, the application programs communicate with the operating
system. Assembly language, unlike high level languages, is machine dependent.
Each microprocessor has its own set of instructions, that it can support.
You must learn assembly language for various reasons:
• 1. It helps you understand the computer architecture and operating system.
• 2. Certain programs, requiring close interaction with computer hardware, are
sometimes difficult or impossible to do in high level languages.
25
Assembly Language Syntax
An assembly language program consists of statements. The syntax of an assembly
language program statement obeys the following rules:
- Only one statement is written per line.
- Each statement is either an instruction or an assembler directive.
- Each instruction has an opcode and possibly one or more operands.
- An opcode is known as a mnemonic.
- Each mnemonic represents a single machine instruction.
- Operands provide the data to work with.
26
Assembler Directives
• Pseudo instructions or assembler directives are instructions that are directed to the
assembler. Assembler directives affect the generated machine code, but are not translated
directly into machine code. Directives can be used to declare variables, constants,
segments, macros, and procedures as well as supporting conditional assembly.
• Segment directives Segments are declared using directives.
The following directives are used to specify the following segments:
.stack
.data
.code
27
Instructions
• An instruction in assembly language is a symbolic representation of a single
machine instruction. In its simplest form, an instruction consists of a mnemonic
and a list of operands.
• A mnemonic is a short alphabetic code that assists the CPU in remembering an
instruction. This mnemonic can be followed by a list of operands. Each
instruction in assembly language is coded into one or more bytes.
28 Instruction Semantics:

The following rules have to be strictly followed in order to write correct code.
1. Both operands have to be of the same size:
Instruction Correct Reason
MOV AX, BL No Operands of different sizes
MOV AL, BL Yes Operands of same sizes
MOV AH, BL Yes Operands of same sizes
MOV BL, CX No Operands of different sizes
29

2 - Both operands cannot be memory operands simultaneously:


Instruction Correct Reason
MOV i , j No Both operands are memory variables
MOV AL, i Yes Move memory variable to register
MOV j, CL Yes Move register to memory variable
30

3 - First operand, or destination, cannot be an immediate value:

Instruction Correct Reason


ADD 2, AX No Move register to constant
ADD AX, 2 yes Move constant to register
31
How to write an assembly language program?
• These are the steps that should be followed for writing an assembly language program:
1- Define the problem.
2- Write the algorithm.
3- Translate into assembly mnemonics.
4- Test and Debug the program in case of errors.
The translation phase consists of the following steps:
- Define type of data the program will deal with.
- Write appropriate instructions to implement the algorithm.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy