INC

VAX11

 

INC      INCREMENT

 

Purpose

add 1 to an integer

Format

opcode sum.mx

Operation

sum ß sum +1;

Condition codes

N ß sum LSS 0;

Z ß sum EQL 0;

V ß {integer overflow};

C ß {carry from most significant bit};

Exceptions

Integer overflow

Opcodes

96        Increment Byte

66        Increment Word

D6       Increment Long

Description

One is added to the sum operand and the sum operand is replaced by the result.

Notes

1. Arithmetic overflow occurs if the largest positive integer is incremented. On overflow, the sum operand is replaced by the largest negative integer.

2. INCx sum is equivalent to ADDx2 $1, sum, but is shorter.

 

 

Example 1

 

Simple use of INCL opcode:

 

.text

main: .word 0

 

movl $5, r1

pushl r1

pushal format

calls $3, .printf       # R1 is 5

incl r1

pushl r1

pushal format

calls $3, .printf       # R1 is 6

 

pushl $0

calls $1, .exit

 

.data

format: .asciz "R1 is %d\n"

 

Example 2

 

The following example shows the different flags rise while using INC opcodes:

 

 

.text

 

main: .word 0

 

movb $0, r0

incb r0           # r0 contains 1, all flags are 0

 

movb $0xFF, r0

incb r0           # r0 contains 0, C = 1, V = 0, Z = 1

 

movw $0xFFFF, r0

incw r0           # r0 contains 0, C = 1, V = 0, Z = 1

 

movl $0xFFFFFFFF, r0

incl r0           # r0 contains 0, C = 1, V = 0, Z = 1

 

movl $0x7FFFFFFF, r0

incl r0           # r0 contains 0x80000000, C = 0, V = 1, N = 1

 

movw $0x7FFF, r0

incw r0           # r0 contains 0x8000, C = 0, V = 1, N = 1

 

movb $0x7F, r0

incb r0           # r0 contains 0x80, C = 0, V = 1, N = 1

 

halt