Section 07 Part 03 – Signed Sets (SGE, SGT, SLE, SLT)

 

 “Peace does not mean an absence of conflict, because opposition, polarity and conflict are natural and universal laws." ~Bryant McGill

 

 

 

Introduction

 

These four S## instructions set/clear the destination operand based on signed results, just like BGE, BGT, BLE and BLT.

 

 

 

The SGE Instruction

 

SGE – Set on Greater than or Equal

 

The N (Negative) and V (oVerflow) flags are tested, if they both match true or false, the destination operand is set (%11111111), if they don't match however, the destination operand is cleared (%00000000).

 

 

 

Examples

 

This instruction uses the N and V flags together to detect if the result is greater than or equal:

 

          cmpi.w    #$0020,d0

          sge.b     d1

 

We’ll pretend d0 contains 00009800, the CMP is word, so the comparison is 0020 & 9800.

 

 

Now let’s pretend d0 contains 00000492.  The comparison is 0020 & 0492.

 

·         0492 is higher than 0020, V and N are both clear.  The SGE instruction will set d1 as 000000FF.

 

 

 

The SGT Instruction

 

SGT – Set on Greater Than

 

The Z (Zero), N (Negative) and V (oVerflow) flags are tested, if the following conditions are met:

 

  1. The Z, N and V flags are all clear
  2. The Z flag is clear, but the N and V flags are both set

 

 

Then the destination operand is set (%11111111).  If none of the conditions are met however, then the destination operand is cleared (%00000000).

 

 

 

Examples

 

This instruction uses the Z, N and V flags together to detect if the result is greater than:

 

          cmpi.w    #$0020,d0

          sgt.b     d1

 

We’ll pretend d0 contains 00000020, the CMP is word, so the comparison is 0020 & 0020.

 

 

Now let’s pretend d0 contains 00000492.  The comparison is 0020 & 0492.

 

 

 

 

The SLE Instruction

 

SLE – Set on Less than or Equal

 

The Z (Zero), N (Negative) and V (oVerflow) flags are tested, if the following conditions are met:

 

  1. The Z flag is clear
  2. The N flag is clear, but the V flag is set
  3. The N flag is set, but the V flag is clear

 

Then the destination operand is set (%11111111).  If none of the conditions are met however, then the destination operand is cleared (%00000000).

 

 

 

Examples

 

This instruction is the polar opposite of SGE:

 

          cmpi.w    #$0020,d0

          sle.b     d1

 

We’ll pretend d0 contains 00009800, the CMP is word, so the comparison is 0020 & 9800.

 

 

Now let’s pretend d0 contains 00000492.  The comparison is 0020 & 0492.

 

·         0492 is higher than 0020, V and N are both clear.  The SLE instruction will set d1 as 00000000.

 

 

 

The SLT Instruction

 

SLT – Branch on Lower Than

 

The N (Negative) and V (oVerflow) flags are tested, if the following conditions are met:

 

  1. The N flag is clear, but the V flag is set
  2. The N flag is set, but the V flag is clear

 

Then the destination operand is set (%11111111).  If none of the conditions are met however, then the destination operand is cleared (%00000000).

 

 

 

Examples

 

This instruction is the polar opposite of SGT:

 

          cmpi.w    #$0020,d0

          slt.b     d1

 

We’ll pretend d0 contains 00000020, the CMP is word, so the comparison is 0020 & 0020.

 

 

Now let’s pretend d0 contains 00008492.  The comparison is 0020 & 8492.

 

 

 

 

Previous Part

Main Page

Next Part