Registers

z80 » Beginner

All processors have small memory banks located on the processor itself. These are for high speed data transfer. The processor loads a value from the RAM onto the high speed data location, manipulates it, and then puts it back in it's place in the RAM.

These small, high speed data locations are called registers. They have letter names to distinguish them. Right now we will learn a few of the most commonly used registers: a, b, c, d, e, h, and l.

a b c d e h l

On the z80 they are 1 byte long (8 bits, 8 1's and 0's); however, they can be put into pairs (bc, de, and hl) so that then they can hold two bytes, or a word. These registers are called Register Pairs because it is two registers put together. The can only be grouped into bc, de, or hl. Bh and da don't exist.

a f b c d e h l

The a register is called the Accumulator because it is used the most, just as hl is called the Address Register Pair because it is used for referencing memory addresses mostly.

Putting parenthesis around a registered pair signifies that you are talking about the byte at the address held by the register pair.

	ld hl,$fc00	;store $fc00 in hl
			;(this is the address of
			; the first byte in
			; the video memory)
	ld (hl),$11	;store $11 in
			; the byte at hl
			;the value that hl holds
			; is considered the
			; address of the byte
			; we are talking about

Before you can every manipulate data, it must pass through a register. You cannot add the contents of one memory address to the contents of another memory address. You have to store the bytes at both memory addresses into registers and then you can add those registers.

	ld a,($fc00)	;get byte at address $fc00
	ld b,a		;put that in b
	ld a,($fc01)	;get byte at address $fc01
	add a,b		;add the two
			;these 4 lines are valid

	;CANNOT do the following line
	add ($fc01),($fc00)	;invalid instruction
	;you'll get all kinds of errors
You can't add straight values either.
	ld a,2
	ld b,3
	add a,b		;you can do this
			;2+3=5 stored in a

	add 2,3		;CANNOT do this!!
			;won't work


More from z80 » Beginner
Aliases // Convert from decimal to hexadecimal or binary // Flags and Conditions // Format and Compiling // Instructions // Math // Number Bases // Oh, No! It Crashed! // Registers // TI-BASIC to Asm Comparisons // TI86 Specifications // Two's Compliment // z80 Processor