Bytes, Words and Longs
The idea that makes the 68000 a 16/32-bit machine: a value can be a byte, a word, or a long — 8, 16 or 32 bits — and you choose the size on every move. Carry a colour out of a 32-bit long.
You've been writing move.w and move.l without stopping to ask what the .w and .l mean. They're the thing that makes the 68000 a 16/32-bit machine, so let's meet them.
On an 8-bit chip, a register held one byte and that was the end of it. The 68000's registers are 32 bits wide, and you decide how much of that you're working with each time. There are three sizes, and every instruction takes one as a suffix:
.b— byte — 8 bits, 0 to 255 (the most an 8-bit chip could hold at all).w— word — 16 bits, 0 to 65,535.l— long — 32 bits, over four billion
A colour is twelve bits ($0RGB), so it needs a word — a byte is too small to hold it. That's why every colour move so far has been .w.
What you'll see by the end
An amber screen. The colour started life inside a long — a full 32-bit value — with junk in its top half and the colour in its bottom half. A word-sized move took only the bottom 16 bits, and that's what reached the screen.
Choosing how much to move
;──────────────────────────────────────────────────────────────
; Meet the Machine (Amiga) - Unit 3: Bytes, Words and Longs
;
; A 68000 value can be a byte (8 bits), a word (16), or a long (32). You choose
; the size on every MOVE. Here a 32-bit long holds a colour in its low word and
; junk in its high word; a word-sized move takes only the colour.
;──────────────────────────────────────────────────────────────
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.l #$12340fc0,d0 ; a LONG: $1234 (junk) in the high word,
; $0fc0 (an orange) in the low word
move.w d0,colourval ; a WORD move: takes only the low 16 bits
; ------------------------------------------------- YOUR CODE END
forever:
bra.s forever
copperlist:
dc.w BPLCON0,$0200
dc.w COLOR00
colourval:
dc.w $0000
dc.w $ffff,$fffe
move.l #$12340fc0,d0 ; a LONG: $1234 up top, $0fc0 (a colour) down low
move.w d0,colourval ; a WORD move: only the low 16 bits travel
d0 now holds the whole 32-bit long, $12340fc0 — you can see all of it in the register view. But move.w d0,colourval is a word move, so it carries only the low 16 bits, $0fc0, to the slot. The top half, $1234, doesn't come along. The size you choose decides how much of the register travels.
Assemble, master, and run
make
An amber screen — the low word of the long, picked out by a word-sized move.
Try this: the junk doesn't matter
Change the top half of the long — #$12340fc0 to #$ffff0fc0, or #$00000fc0. Same amber screen every time. Because the move is .w, only the low word ever travels; whatever's in the high word is along for storage, not for the trip.
Try this: a byte is too small
Change move.w d0,colourval to move.b d0,colourval and run. The colour comes out wrong — a byte move carries only 8 of the colour's 12 bits, so half the colour is missing. This is the whole reason a colour is a word: eight bits can't hold it. Put .w back.
If it doesn't work
vasmerrors on the size. The suffix is.b,.wor.l, lowercase, right after the instruction:move.w, notmove .w.- The colour is wrong or partial. You probably moved the wrong size —
.btruncates a colour, and.lto a word-sized destination would overrun it. A colour wants.w. - The screen is black. Check the colour is in the low word of the long (
$....0fc0), since that's the half a word move takes.
What you've learnt
A 68000 value comes in three sizes — byte (8), word (16), long (32) — and you choose one on every instruction with .b / .w / .l. A move carries exactly that many bits; the rest of the register stays put. A colour is twelve bits, so it travels as a word.
What's next
We've leaned on d0 and d3 as if there were plenty of registers to go round — and there are. Next — A Register for Every Job — we meet the 68000's full register file: eight data registers and eight address registers, and the division of labour between them.