Professional Documents
Culture Documents
- The BIU must interact with memory and input/output devices to retrieve instructions and data required
by the UE.
- The EU is responsible for carrying out the program instructions and the required processing.
AX register (Accumulator or working register): All data transfer operations with input-output, as well as
string processing, are performed in this register. Arithmetic and logical operations also use this register. BCD
conversions of the result of arithmetic operations (addition, subtraction, multiplication, and division) are
carried out in this register.
BX register (Base register): It is used for data addressing, typically containing an offset address relative to a
reference address (data segment DS). It can also be used for code conversion.
CX register (Counter): When executing a loop, a loop counter is often used to count the number of iterations,
and the CX register is designed to serve as a counter during loop instructions.
DX register: It is used for multiplication and division operations, but primarily to hold the number of an
input/output port for addressing I/O interfaces.
AF (Auxiliary Carry Flag): This bit is set to 1 if there is a carry from the low-order quarter (4 bits) to the high-
order quarter.
ZF (Zero Flag): This indicator is set to 1 when the result of an operation is equal to zero. When a subtraction
(or comparison) has just been performed, ZF = 1 indicates that the two operands were equal. Otherwise, ZF
is set to 0.
SF (Sign Flag): This indicator is set to 1 if the last operation produced a negative result, and it's set to 0 if the
result is positive or zero. SF is useful when working with signed integers because the most significant bit
indicates the sign of the result.
OF (Overflow Flag): If there is an arithmetic overflow, this bit is set to 1, meaning the result of an operation
exceeds the capacity of the operand (register or memory location); otherwise, it's set to 0.
DF (Direction Flag): Used by string processing instructions to auto-increment or auto-decrement the SI and
DI registers.
IF (Interrupt Flag): To mask external interrupts, this bit is set to 0. Otherwise (IF = 1), the microprocessor
recognizes external interrupts.
TF (Trap Flag): Used to execute the program step by step, causing the microprocessor to execute instructions
one at a time.
Notes:
The IF, DF, and TF bits are control indicators that allow the modification of the microprocessor's behavior
and are set by the programmer.
Figure 2.6. Diagram of the two stack manipulation instructions: PUSH and POP.
Operation: In normal use, the stack can be accessed through two instructions, which are PUSH and POP as
depicted in the figure above.
SP (stack pointer) is the register that points to the top of the stack, i.e., the last occupied word of the stack.
The PUSH instruction saves (puts) an element (16 bits) at the top of the stack, and it works as follows:
1) SP ← SP - 2
2) SS:[SP] ← operand (16 bits)
SS:[SP]: Address of the top of the stack
SReg : to designate a segment register, namely CS, DS, ES, and SS.
L’instruction POP fournie (transfère) le mot mémoire du sommet de la pile à l’opérande de destination, elle
fonctionne comme suit :
1) Operand (16 bits) ← SS:[SP]
2) SP ← SP + 2
"SReg: To designate a segment register, namely CS, DS, ES, and SS.
The POP instruction provided (transfers) the memory word from the top of the stack to the destination
operand, and it operates as follows:
1) Operand (16 bits) ← SS:[SP]
2) SP ← SP + 2
Instruction Operand (16 bits) Instruction description Flags
Reg
Get 16 bits operand from the stack Segment. This instruction retrieves Does not affect the
POP SReg
a 16-bit value from the stack and stores it in the operand. flags
Mem
Example :
PUSH AX ; Push the AX register onto the stack segment
PUSH BX ; Push the BX register onto the stack segment
PUSH [1100H] ; Push the value from memory location 1100H-1101H onto the stack
POP [1100H] ; Pop in reverse order of pushing into memory
POP BX
POP AX
Note: The value of SP must be initialized by the main program before the stack can be used.
Table 2.1 Instructions for saving and restoring registers in the stack segment.
Instruction
Instruction description Flags
(no operand)
[SP] ← Status register
PUSHF Store flags register in the stack Segment.
SP ← SP - 2
Status register ← [SP]
POPF Get flags register from the stack.
SP ← SP +2
PUSH AX
PUSH CX
PUSH DX
PUSH BX
PUSHA Push all general purpose registers AX, CX, DX, BX, SP, BP, SI, DI in the stack.
PUSH SP
PUSH BP
PUSH SI
PUSH DI
POP DI
POP SI
POP BP
POP xx (Ignored SP
POPA Pop all general purpose registers DI, SI, BP, SP, BX, DX, CX, AX from the stack. value)
POP BX
POP DX
POP CX
POP AX
Example :
70-77
7 Instruction Encoding
Instructions and their operands (parameters) are stored in main memory. The total size of an instruction
depends on the type of instruction and the type of operand. An instruction consists of two fields:
- Operation code (Opcode) tells the processor which instruction to execute.
- Operand field contains the data or a reference to data in memory (its address).
Each instruction begins with the opcode that determines the nature of the instruction, followed by the
operand field indicating the type of operands, their location, or an immediate value (literal).
Exemple :
Instructions Opcode Operand field Size (bytes) Code machine
MOV AX, BX 8B H C3 H 2 1000 1011 1100 0011
MOV DS, AX 8E H D8 H 2 1000 1110 1101 1000
MOV AX, 5H 8B H 0500 H 3 1000 1011 0000 0101 0000 0000
MOV AL, temper A0 H 0E01 H 3 1010 0000 0000 1110 0000 0001
Machine language, or machine code, is the sequence of bits interpreted by the computer's microprocessor
when executing a computer program. It is the only language that the processor can process.
for executing an instruction. Another solution is to employ a microprocessor architecture that reduces the
number of cycles per instruction.
Classic Model:
Pipeline Model :
Figure 2.8. Comparison between the classic execution model and the pipeline execution model
9 Tutorial exercises No 2
Exercise 01:
1. What type of architecture does the 8086 have? (CISC or RISC).
2. In which year was the 8086 manufactured?
3. How many pins does the 8086 have?
4. What is the total number of registers in the 8086?
5. Name the segment registers, and where are they located in the microprocessor?
6. Name the index registers, and where are they located in the microprocessor?
7. What is the size of the microprocessor 8086's queue, and where is it located within the microprocessor?
8. What is the size in bytes of the memory addressable by the 8086?
9. An instruction consists of two fields, name them.
10. Which unit of the microprocessor is responsible for loading the physical address (20 bits) onto the address
bus?
Exercise 02:
1. Answer the following statements with (true) or (false):
2. A segment is a memory area of 64 KB.
3. The bits that make up the status register are independent of each other.
4. The segment registers CS, DS, ES, and SS are responsible for selecting different memory segments by
pointing to the beginning of each one.
5. The EU (Execution Unit) has no connection to the buses (address, data, and control).
6. The BIU (Bus Interface Unit) is responsible for filling the queue with fetched instructions.
7. The IP register contains the address of the memory location where the next instruction to be executed
is located.
8. The parity flag PF is set to 1 if the result of an operation is even.
9. The BIU fetches instructions to be executed from memory and stores them in the 8086's queue.
10. The BIU calculates physical addresses in 16 bits.
11. Machine language is the only language that the processor can process.
12. The stack segment is organized in bytes (8 bits).
13. The PUSH instruction increments the address contained in the SP register by 2.
14. The Instruction Register (IR) can be manipulated by the programmer.
Exercise 03:
1. If the code segment register CS contains the value 2300H, determine the physical address of the start and
end of the code segment.
2. If the data segment register DS contains the value 0100H, determine the physical address of the start and
end of the data segment.
3. After the execution of the instructions below, provide the state of the flags (CF, ZF, SF, and PF) in the
status register (flag register).
c) mov AX, 70D b) mov AX, 22H d) mov AX, 22H
mov BX, 200D mov BX, 52H mov BX, AX
add AX, BX sub AX, BX sub AX, BX
4. Consider the following assembly program segment
Mov cx, 55h ; The SP register contains the value 2244H.
Push ax
Push bx
Push cx
Pop ax
Determine the contents of the SP and AX registers after the program execution.
Exercise 04 :
Choose the correct answer
1. The primary role of 'cache memory' is
a) to increase the storage capacity of main memory.
b) to compensate for slow speed and speed up access to main memory.
c) to improve the microprocessor's clock.
2. The execution time of an instruction depends on:
a) the complexity of the instruction and addressing mode.
b) the microprocessor's architecture.
c) the size of main memory.
3. The opcode of an instruction allows to:
a) determine its nature
b) locate the operand in memory.
c) indicate the type of operands.
Exercise 05 :
After executing the program below, determine the contents of registers AX, BX, and CX.
Determine the contents of register SP at the specified positions. Knowing that initially, SP contains FFFEH.
MOV AX, 1122H
MOV BX, 3344H
MOV CX, 5566H
PUSH AX
PUSH BX ;Determine the content of the SP register after the execution of the current instruction SP = … ?
PUSH CX
POP BX
POP AX ;Determine the content of the SP register after the execution of the current instruction SP = … ?
POP CX