Vous êtes sur la page 1sur 11

Flag Registers

Flag register contains information reflecting the current status of microprocessor. It


also contains information which controls the operation of the microprocessor.
Test for Sign Flags , OV Flag for the following syntax:
mov al, ff , mov ax, ff, mov ax, ffff <- does this modifies any flags ?
mov al, 7f : mov bl, 7f, add al, bl <- which flags is modified ?

1. Flag Control Instruction


Flag Control Instruction : Bit Positions

ex: LAHF and SAHF


-read or change flags.
-data transfer must be between AH register and the flag
register
- Other instruction to clear or reset Carry and interrupt flags.

Example

Example:
Write an instruction sequence to save the current contents of the 8088’s flags in the
memory location at offset MEM1 of the current data segment and then reload the
flags with the contents of the storage location at offset MEM2.

Solution:
LAHF ; Read from Flag to AH
MOV [MEM1], AH ; Copy to Memory 1
MOV AH, [MEM2] ; Copy from MEM1 to AH
SAHF ; Set the flags from AH

Compare Instructions
TO DETERMINE THE RELATIONSHIP BETWEEN TWO NUMBERS

:- equal, larger or smaller


•Subtraction operation
•The result is not saved
•Based on the result, appropriate flag are set or reset.
•Examples:
•Given a sequence of number, find a minumum number

MOV AL, 7
CMP AL, 5
MOV AL, 99H; -103
CMP AL, 1BH; +27

Compares the destination operand to the source operand. Destination operand is


not changes

CMP D,S

Example 1:
MOV AL,5
CMP AL,5 ;Zero flag is set

Example 2:
MOV AL,4
CMP AL,5 ;Carry flag is set

Example:
Describe what happens to the status flags as the sequence of instructions
that follows is executed.All flags initially reset.
MOV AX,1234H
MOV BX.ABCDH
CMP AX,BX
CONTROL FLOW AND THE JUMP INSTRUCTIONS

•Control flow relates to altering the execution path of instructions in a


program.
•It may cause a sequence of instructions to be repeated or a group of
instructions to not be executed at all.
•For a change in the control flow, we have to change the contents of the
code segment register and instruction pointer.
•So, to control the flow of a program, we use jump instruction
• A jump may be conditional or unconditional
• Common conditional jumps are related to the conditions of flags such as
CARRY, OVERFLOW, SIGN OR ZERO.
•When a jump is executed the program is sent to a new location by loading the
program counter (CS:IP) with a new value .
•If the branch address is in the same CS memory then the jump is called as an
Intrasegment jump.
• If the branch address is in different CS memory then the jump is called an
Intersegment jump.
As the instruction is executed, the jump always take place to change the
execution sequence.
- No status requirement for the jump to occur

Jump Instructions
UNCONDITIONAL JUMP

— It moves microprocessor to execute another part of the program


— Target can be represented by a label, immediate data, registers, or
memory locations
— It does not affect flags
—Assembly language couldn’t exist without unconditional jumps.
Intrasegment transfer v.s. Intersegment transfer

— Intrasegment transfer: the microprocessor jumps to an address within


the same segment
— we can provide only new IP value in JMP instructions.

For Example: JMP 1000H


— Intersegment transfer: the microprocessor jumps to an address in a
difference segment
—we need to provide both new CS and IP values in JMP instructions

For Example: JMP 2000H : 1000H

Direct Jump v.s. Indirect Jump

— Direct Jump: the target address is directly given in the instruction


— Indirect Jump: the target address is contained in a register or memory
location

Loop instruction

LOOP= when a group of instructions may need to be executed over and


over again until a condition is met
The loop program structure is to implement
- REPEAT-UNTIL and WHILE-DO

Vous aimerez peut-être aussi