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I@	R4,R2
	MOVR	R3,R3
	BNZE	CHK
	CMPI	' ',R2
	BEQ	GET
	INCR	R3
CHK:	SUBI	48,R2

	SDBD
	MVII	100,R3

	SDBD
	NOP
	XORI	123,R0

	BITS	10
	MVII	1023,R0
	MVII	1024,R1
	MVII	65535,R2

	BITS	11
	ADDI	2047,R0
	ADDI	2048,R1
	ADDI	4096,R2

	; Map PACKING to PAK/UPAK

PAK	macro
	packing	on
	endm

UPAK	macro
	packing	off
	endm

CR:	EQU	X'0D'
LF:	EQU	X'0A'

	BYTE	127
	WORD	127

	; packing is on by default for CP1600

	TEXT	"Hello", CR, LF, 0

	; turn packing off -> one word per character

	UPAK
	TEXT	"Hello", CR, LF, 0

	; turn packing on again

	PAK
	TEXT	"Hello", CR, LF, 0

	END
