Instructions That May Be Used for Assignment 1 - PowerPoint PPT Presentation

1 / 7
About This Presentation
Title:

Instructions That May Be Used for Assignment 1

Description:

Compare destination operand to source operand ... CMP op1, op2. JE True. JMP EndIf. True: EndIf. CMP op1, op2. JNE False. False: ... – PowerPoint PPT presentation

Number of Views:37
Avg rating:3.0/5.0
Slides: 8
Provided by: kipir
Category:

less

Transcript and Presenter's Notes

Title: Instructions That May Be Used for Assignment 1


1
Instructions That May Be Used for Assignment 1
  • Department of Computer Science
  • National Tsing Hua University

2
CMP Instruction (1/2)
  • Compare destination operand to source operand
  • Nondestructive subtraction of source from
    destination (destination operand is not changed)
  • Syntax CMP destination, source
  • Example destination lt source
  • Example destination gt source

mov al,4 cmp al,5 Carry flag set
mov al,6 cmp al,5 ZF 0, CF 0
(both the Zero and Carry flags are clear)
3
CMP Instruction (2/2)
  • The comparisons shown here are performed with
    signed integers.
  • Example destination gt source
  • Example destination lt source

mov al,5 cmp al,-2 Sign flag Overflow flag
mov al,-1 cmp al,5 Sign flag ! Overflow flag
4
CMP and Jcond Instruction
  • The IF statement in C and PASCAL is converted
    into CMP and Jcond instructions in x86 Assembly

CMP X, op1 JNG EndIf ltgt EndIf
If (X gt op1) Then ltgt End If
5
Jcond Instruction
  • A conditional jump instruction branches to a
    label when specific register or flag conditions
    are met
  • Examples
  • JB, JC jump to a label if the Carry flag is set
  • JE, JZ jump to a label if the Zero flag is set
  • JS jumps to a label if the Sign flag is set
  • JNE, JNZ jump to a label if the Zero flag is
    clear
  • JECXZ jumps to a label if ECX equals 0

6
More Frequently Used Jcond
  • JE (Equal)
  • JNE (Not Equal)
  • JG or JGE (Greater Than or Equal)
  • JL or JLE (Less Than or Equal)
  • Note JGJNLE, JGEJNL, etc.

7
Simple IF
  • If (op1op2) then ltgt end if
  • Two different approaches

CMP op1, op2 JE True JMP EndIf True ltgt End
If
CMP op1, op2 JNE False ltgt False
Write a Comment
User Comments (0)
About PowerShow.com