From C64-Wiki
Jump to navigationJump to search
Mnemonic: DEX
2. Schreibweise: {{{2. Schreibweise}}}
Opcode: $CA
Byte count: 1
Command type: Arithmetic- and logic command
Address mode: Implied
register flags:
Negative Flag
Zero Flag
Cycles: 2

DEX (short for "DEcrease X") is the mnemonic for a machine language instruction which decrements the numerical value of X index register, by one, and "wraps over" if the value goes below the numerical limits of a byte.

  • If the X index register is taken as an unsigned integer, DEX "counts down" from 255 thru 0/$FF thru $0. If the index register already contains the minimum value of 0/$0 as it is decremented, it "wraps over" to the value 255/$FF.
  • If the X index register is taken as a signed integer, DEX will "count down" from +127 thru −128, or +$7F thru −$80. If the register already contains the value −128/−$80 when it is decremented, it "wraps over" to the value +127/$7F.

Function flow

Ass befehl ca.gif

Explanation of the mnemonic shortcut

DEX DEcrement X register
Decrement X register


; This program clears the datasette I/O buffer (192 bytes)
; Start program with SYS 49152

*=$c000   ; Start address


 lda #0               ; fill up character
 ldx #COUNT           ; how many characters
 sta BUFFER-1,x       ; clear location, address offset by one, because X counted only to 1
 dex                  ; memory index and counter
 bne clear_byte       ; exit if count is zero
 rts                  ; back to BASIC

Momory content:

.c000	 a9 00		lda #$00
.c002	 a2 c0		ldx #$c0
.c004	 9d 3b 03	sta $033b,x
.c007	 ca		dex
.c008	 d0 fa		beq $c004
.c00a	 60		rts

Comparison with Basic command

10 X=X-1