A Register for Every Job
Meet the 68000's register file: eight data registers for values and maths, eight address registers for pointers — sixteen in all, far more elbow room than an 8-bit chip's two or three.
You've used d0, d3, and a0, a5 as if registers were plentiful. On the 68000 they are — and they come in two kinds, with a clear division of labour.
- Eight data registers,
d0–d7. For values: numbers you're holding, comparing, doing maths on. Any of the eight is as good as any other; pick whichever is free. - Eight address registers,
a0–a7. For addresses: where something lives in memory. You've already used them this way —a5held the custom-chip base,a0held the address of the Copper list.
Sixteen registers in total. An 8-bit chip gave you two or three and made you juggle; the 68000 gives you room to keep several things in hand at once. (a7 has a second job — it's the stack pointer — which we meet in Unit 12. The other fifteen are yours to use freely.)
What you'll see by the end
A magenta screen. The colour passed from one data register to another before it reached the slot — not because it had to, but to show the registers are there for the taking.
Passing a value between registers
;──────────────────────────────────────────────────────────────
; Meet the Machine (Amiga) - Unit 4: A Register for Every Job
;
; The 68000 has sixteen registers: eight DATA registers (d0-d7) for values and
; maths, and eight ADDRESS registers (a0-a7) for addresses. Far more room than
; an 8-bit chip's two or three. Here a colour rides from one data register to
; another before it reaches the screen.
;──────────────────────────────────────────────────────────────
CUSTOM equ $dff000
DMACON equ $096
INTENA equ $09a
INTREQ equ $09c
COP1LC equ $080
COPJMP1 equ $088
BPLCON0 equ $100
COLOR00 equ $180
section code,code_c
start:
lea CUSTOM,a5
move.w #$7fff,INTENA(a5)
move.w #$7fff,INTREQ(a5)
move.w #$7fff,DMACON(a5)
lea copperlist,a0
move.l a0,COP1LC(a5)
move.w d0,COPJMP1(a5)
move.w #$8280,DMACON(a5)
; ----------------------------------------------- YOUR CODE START
move.w #$0a0f,d0 ; a magenta into data register d0
move.w d0,d3 ; d0 -> d3 (any data register will do)
move.w d3,colourval ; d3 -> the Copper's colour slot
; ------------------------------------------------- YOUR CODE END
forever:
bra.s forever
copperlist:
dc.w BPLCON0,$0200
dc.w COLOR00
colourval:
dc.w $0000
dc.w $ffff,$fffe
move.w #$0a0f,d0 ; a magenta into data register d0
move.w d0,d3 ; d0 -> d3 (any data register will do)
move.w d3,colourval ; d3 -> the Copper's colour slot
The value lands in d0, hops to d3, then heads for the screen — all with the same MOVE you already know, now carrying values between registers. Open the register view and you'll see d0 and d3 both holding $0a0f. We used two registers where one would do, just to show the bench is roomy: d3 was free, so we used it.
Assemble, master, and run
make
A magenta screen — passed hand to hand through the data registers.
Try this: the scenic route
Send the colour through more registers before it arrives:
move.w #$0a0f,d0
move.w d0,d3
move.w d3,d6
move.w d6,d1
move.w d1,colourval
Same magenta. Five registers touched, all interchangeable for holding a value. On an 8-bit chip you'd have run out of registers and had to park values in memory; here you've barely made a dent.
Try this: data vs address
Try move.w #$0a0f,a3 instead of d0. The assembler may let it through, but address registers are meant for addresses, not colours — and they behave differently in ways that will bite later (they don't set the flags you'll meet in Unit 8, and word moves into them sign-extend to all 32 bits). Keep values in d registers, addresses in a registers. The split is a habit worth forming now.
If it doesn't work
vasmerrors on a register name. Data registers ared0–d7, address registersa0–a7. There's nod8ora8.- The screen is black. Follow the chain — each
MOVE's destination should be the next one's source, ending atcolourval. A broken link and the colour never arrives. - Odd behaviour with an address register. That's the data/address split biting — keep the colour in a
dregister.
What you've learnt
The 68000 has sixteen registers: eight data registers (d0–d7) for values, eight address registers (a0–a7) for addresses. They're plentiful and, within each kind, interchangeable — room enough to keep several things in hand without parking them in memory.
What's next
Those address registers exist to point into memory — and memory is exactly where we head next. Next — A Vast Street of Memory — we meet the 68000's enormous address space and store and read a value out in it. (Using an address register as a movable pointer is an idea we save for Unit 10.)