meljun cortes flag control and jump instructions

21
* Property of STI Page 1 of 21 Flag Control and Jump Instructions Computer Organization and Assembly Language Flag Control Instructions The 8086/8088 provides a group of instructions that directly affects the state of the flags. v LAHF Instruction v SAHF Instruction v CLC Instruction v STC Instruction v CMC Instruction v PUSHF Instruction v POPF Instruction

Upload: meljun-cortes

Post on 24-Jan-2017

36 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: MELJUN CORTES Flag control and jump instructions

* Property of STIPage 1 of 21

Flag Control and Jump Instructions

Computer Organization and Assembly Language

Flag Control Instructions

Ø The 8086/8088 provides a group of instructions that directly affects the state of the flags.

v LAHF Instruction v SAHF Instructionv CLC Instructionv STC Instruction v CMC Instructionv PUSHF Instructionv POPF Instruction

Page 2: MELJUN CORTES Flag control and jump instructions

* Property of STIPage 2 of 21

Flag Control and Jump Instructions

Computer Organization and Assembly Language

The LAHF Instruction

Ø The LAHF (Load AH from flags) instruction copies the SF, ZF, AF, PF, and CF into bits b7, b6, b4, b2, and b0 respectively of register AH.

Ø Format: LAHFØ Action:

AH SF ZF x AF x PF x CF

Page 3: MELJUN CORTES Flag control and jump instructions

* Property of STIPage 3 of 21

Flag Control and Jump Instructions

Computer Organization and Assembly Language

The SAHF Instruction

Ø The SAHF (Store AH into flags) instruction transfers bits b7, b6, b4, b2, and b0 from register AH into SF, ZF, AF, PF, and CF, respectively.

Ø Format: SAHFØ Action:

SF ZF x AF x PF x CF AH

Page 4: MELJUN CORTES Flag control and jump instructions

* Property of STIPage 4 of 21

Flag Control and Jump Instructions

Computer Organization and Assembly Language

The CLC Instruction

Ø The CLC (Clear Carry Flag) instruction clears the carry flag.

Ø Format: CLCØ Action: CF 0

Page 5: MELJUN CORTES Flag control and jump instructions

* Property of STIPage 5 of 21

Flag Control and Jump Instructions

Computer Organization and Assembly Language

The STC Instruction

Ø The STC (Set Carry Flag) instruction sets the carry flag to 1.

Ø Format: STCØ Action: CF 1

Page 6: MELJUN CORTES Flag control and jump instructions

* Property of STIPage 6 of 21

Flag Control and Jump Instructions

Computer Organization and Assembly Language

The CMC Instruction

Ø The CMC (Complement Carry Flag) instruction complements the carry flag.

Ø Format: CMCØ Action: CF [CF]

Page 7: MELJUN CORTES Flag control and jump instructions

* Property of STIPage 7 of 21

Flag Control and Jump Instructions

Computer Organization and Assembly Language

The PUSHF Instruction

Ø The PUSHF (Push Status Register onto Stack) instruction pushes the status register onto the stack. PUSHF decrements SP by 2 and then moves the status register to the top of the stack.

Ø Format: PUSHFØ Action: SP SP - 2

SP [status register]

Page 8: MELJUN CORTES Flag control and jump instructions

* Property of STIPage 8 of 21

Flag Control and Jump Instructions

Computer Organization and Assembly Language

The POPF Instruction

Ø The POPF (Pop Flags off the Stack) instruction transfers the word pointed to by SP to the status register, thereby altering the value of the flags.

Ø Format: POPFØ Action:

status register [SP]SP SP + 2

Page 9: MELJUN CORTES Flag control and jump instructions

* Property of STIPage 9 of 21

Flag Control and Jump Instructions

Computer Organization and Assembly Language

The CLI Instruction

Ø The CLI (Clear Interrupt Flag) instruction clears the interrupt flag, thereby disabling interrupt request. The 8086/8088 will therefore not recognize any external interrupt request with the exception of the non-maskable interrupt.

Ø Format: CLIØ Action: IF 0

Page 10: MELJUN CORTES Flag control and jump instructions

* Property of STIPage 10 of 21

Flag Control and Jump Instructions

Computer Organization and Assembly Language

The STI Instruction

Ø The STI (Set Interrupt Flag) instruction sets the interrupt flag to 1, thereby enabling the 8086/8088 to recognize any interrupt request.

Ø Format: STIØ Action: IF 1

Page 11: MELJUN CORTES Flag control and jump instructions

* Property of STIPage 11 of 21

Flag Control and Jump Instructions

Computer Organization and Assembly Language

The CLD Instruction

Ø The CLD (Clear Direction Flag) instruction clears the direction flag, thereby causing the string instruction to auto-increment the index registers (SI or DI).

Ø Format: CLDØ Action: DF 0

Page 12: MELJUN CORTES Flag control and jump instructions

* Property of STIPage 12 of 21

Flag Control and Jump Instructions

Computer Organization and Assembly Language

The STD Instruction

Ø The STD (Set Direction Flag) instruction sets the direction flag to 1, thereby causing the string instruction to auto-decrement the index registers (SI or DI).

Ø Format: STDØ Action: DF 1

Page 13: MELJUN CORTES Flag control and jump instructions

* Property of STIPage 13 of 21

Flag Control and Jump Instructions

Computer Organization and Assembly Language

Control Transfer Instructions

Ø The code segment and IP keep track of the next instruction to be executed. This means that programs are executed sequentially.

Ø The instructions that can alter the flow of a program are iteration control instructions, conditional transfers, unconditional transfers, and subroutines.

Page 14: MELJUN CORTES Flag control and jump instructions

* Property of STIPage 14 of 21

Flag Control and Jump Instructions

Computer Organization and Assembly Language

The JMP Instruction

Ø The JMP (Unconditional Jump) instruction unconditionally transfers control to the target location.

Ø Format: JMP operandØ Action: Jump is initiated to the

address specified by the operand.

JMP far [BX]Memptr32

JMP [BX]Memptr16

JMP DXRegptr16

JMP far L1Far-label

JMP L1Near-label

JMP short L1Short-label

ExampleOperand

Page 15: MELJUN CORTES Flag control and jump instructions

* Property of STIPage 15 of 21

Flag Control and Jump Instructions

Computer Organization and Assembly Language

Example – JMP Instruction

1. Short-label

MOV AX, 0001HJMP short L1MOV BX, 0002H

L1: MOV BX, 0001H

Page 16: MELJUN CORTES Flag control and jump instructions

* Property of STIPage 16 of 21

Flag Control and Jump Instructions

Computer Organization and Assembly Language

Example – JMP Instruction

2. Far-LabelMOV AX, 0001HJMP far L1MOV BX, 0002HMOV BX, 0001H

.

.

.L1: MOV BX, 0003H

Page 17: MELJUN CORTES Flag control and jump instructions

* Property of STIPage 17 of 21

Flag Control and Jump Instructions

Computer Organization and Assembly Language

Example – JMP Instruction

3. RegPtr16

MOV BX, 0000HJMP BX

4. MemPtr16

MOV BX, 0000HJMP [BX]

01H

00HDS:0000H

DS:0001H

Page 18: MELJUN CORTES Flag control and jump instructions

* Property of STIPage 18 of 21

Flag Control and Jump Instructions

Computer Organization and Assembly Language

Example – JMP Instruction

5. MemPtr32

MOV BX, 0000HJMP far [BX]

02H

00HDS:0000H

DS:0001H

01H

00HDS:0002H

DS:0003H

Page 19: MELJUN CORTES Flag control and jump instructions

* Property of STIPage 19 of 21

Flag Control and Jump Instructions

Computer Organization and Assembly Language

The CALL Instruction

Ø The CALL (Subroutine Call) instruction transfers control to a subroutine.

Ø Format: CALL operandØ Action: Execution continues

from the address of the subroutine specified by the operand.

CALL far [BX]Memptr32

CALL [BX]Memptr16

CALL DXRegptr16

CALL far L1Far-proc

CALL L1Near-proc

ExampleOperand

Page 20: MELJUN CORTES Flag control and jump instructions

* Property of STIPage 20 of 21

Flag Control and Jump Instructions

Computer Organization and Assembly Language

The RET Instruction

Ø The RET (Return) instruction transfers control from a subroutine back to the instruction following the CALL instruction.

Ø Format: RET operand RET

Ø Action: Transfer control from a subroutine back to the instruction following the CALL instruction.

RET 2Disp16

RETNone

ExampleOperand

Page 21: MELJUN CORTES Flag control and jump instructions

* Property of STIPage 21 of 21

Flag Control and Jump Instructions

Computer Organization and Assembly Language

Program Tracing Exercise

MOV AX, 0000HL1: INC AX

CMP AX, 0098HJZ L2JMP short L1

L2: SUB AL, BL

1. How many times will the CMP AL, BL instruction be executed?

2. What will be the final contents of AL and BL after the program has finished executing?