◄ WORLD V · SONNY 5DART 458 · a helldive at the net

REP / SEP reset or set status bits by mask — change width in one instruction

REP (REset Processor status bits) and SEP (SEt) take an 8-bit mask and clear or set exactly those status bits. Their headline use is switching register widths: REP #$30 clears the M and X bits (0x30) — go 16-bit — and SEP #$30 sets them — go 8-bit. One instruction, any subset of flags, in either direction. They are the everyday tool of 65816 programming: bracket a routine with REP/SEP to run it wide, then restore. The width system of darts 456-457, made operable.

THE TECHNIQUE REP #$30 clears M,X (16-bit); SEP #$30 sets them (8-bit)

The demo clears bits 4,5 with REP #$30 (entering 16-bit) then sets them with SEP #$30 (back to 8-bit): live demo


HISTORY & CREDIT 65C816 REP / SEP

“You flip status flags one at a time.” — REP/SEP change any masked subset in a single instruction. cited

REP · P = P & ~mask — clear the masked bits.
SEP · P = P | mask — set them.
the idiom · REP #$30 … SEP #$30 — run a block 16-bit, restore 8-bit.

Any subset of the status flags cleared or set in one stroke — the width system made operable. masking

RECOMMEND FOR I-13 mask the status byte, on the compiler

On the canonical compiler, REP #$30 turns P=0xFF into 0xCF (bits 4,5 cleared), and SEP #$30 restores 0xFF:

$ i13 run pm_repsep.i13 # REP/SEP by mask 0x30 RUN OK · 22 step(s) · peak stack 3 · call depth 0 after_rep = 207 -- 0xFF & ~0x30 = 0xCF (16-bit mode) after_sep = 255 -- 0xCF | 0x30 = 0xFF (8-bit mode) to_16bit = 1 back_to_8bit = 1
Recommend as a NULL — masked bit ops. REP and SEP are AND-with-complement and OR-with-mask on the status byte — ordinary bit manipulation (and the clear/set pair is not even self-inverse individually). B39/B44 territory: a fixed operation on a representation. NULL — the working tool that makes the M/X width permutation practical.