DEC

VAX11

 

DEC     DECREMENT

 

Purpose

subtract 1 from an integer

Format

opcode dif.mx

Operation

dif ß dif - 1;

Condition codes

N ß dif LSS 0;

Z ß dif EQL 0;

V ß {integer overflow};

C ß {borrow from most significant bit};

Exceptions

Integer overflow

Opcodes

97        DECB                                      Decrement Byte

B7        DECW                                     Decrement Word

D7       DECL                                      Decrement Long

Description

One is subtracted from the difference operand and the difference operand is replaced by the result.

Notes

1. Integer overflow occurs if the largest negative integer is decremented. On overflow, the difference operand is re placed by the largest positive integer.

2. DECx dif is equivalent to SUBx2 $1, dif, but is shorter.

 

 

Example 1:

 

.text

      .word 0

      movl $7, r0

      decl r0

      pushl r0

      pushal format

      calls $2, .printf

      pushl $0

      calls $1, .exit

format: .asciz "%d\n"

 

 

Example 2

 

Flags example - the following program demonstrate the different values for flags while performing DEC commands: We can say that N and Z are set as always. V is set if 80..0 is decremented to 7F..F.  C is set if 0 is decremented to FF..F.

 

.text

      .word 0

      movl $3, r0

      decl r0

      decl r0

      decl r0     # Z = 1

      decl r0     # N = 1, C = 1

     

      movb $0x81, r0

      decb r0     # N = 1

      decb r0     # N = 0, C = 0, V = 1

      decb r0     # N = 0, C = 0, V = 0

 

      pushl $0

      calls $1, .exit

 

 

Example 3

 

Another flags example

 

.text

main: .word 0

 

      movb $0, r0

      decb r0           # N = 1, C = 1

      movb $0xFF, r0

      decb r0           # N = 1

      movw $0x0000, r0

      decw r0           # N = 1, C = 1

      movl $0x00000000, r0

      decl r0           # N = 1, C = 1

      movl $0x80000000, r0

      decl r0           # V = 1

      movw $0x8000, r0

      decw r0           # V = 1

      movb $0x80, r0

      decb r0           # V = 1

     

      pushl $0

      calls $1, .exit