Register Addressing Modes

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
PeterJ
Site Admin
Posts: 6853
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Register Addressing Modes

Post by PeterJ »

Hello,

I'm typing up a 'crib' sheet for my adventures with machine code. I'm just making sure I have my head around register addressing modes.

Is this a complete list of the more common load instructions (excluding the stack pointer & Index register instructions)? Also have I put everything in the right groups?

Thanks

Immediate Addressing
LD (HL),n
LD A,n
LD B,n
LD C,n
LD D,n
LD E,n
LD H,n
LD L,n

Register Addressing
LD r,r

Register Indirect Addressing
LD (ADDR),A
LD (BC),A
LD (DE),A
LD (HL),A
LD (HL),B
LD (HL),C
LD (HL),D
LD (HL),E
LD (HL),H
LD (HL),L
LD A,(ADDR)
LD A,(BC)
LD A,(DE)
LD A,(HL)
LD B,(HL)
LD C,(HL)
LD D,(HL)
LD E,(HL)
LD H,(HL)
LD L,(HL)

Extended Addressing
LD BC,(ADDR)
LD DE,(ADDR)
LD HL,(ADDR)
LD (ADDR),BC
LD (ADDR),DE
LD (ADDR),HE
LD BC,nn
LD DE,nn
LD HL,nn
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Register Addressing Modes

Post by Ast A. Moore »

PeterJ wrote: Sun Nov 26, 2017 4:16 pm Immediate Addressing
LD (HL),n
No, that’s Indirect addressing, I believe.
PeterJ wrote: Sun Nov 26, 2017 4:16 pm Extended Addressing
LD BC,nn
LD DE,nn
LD HL,nn
These three definitely belong to the Immediate Addressing group. The width of an instruction is irrelevant here. You’re still loading registers with values specified in the operand immediately.

LD (HL),n could possibly refer to Mixed Mode Addressing, though. The distinction is not very clear cut. In general, the Zilog documentation and, say, Rodnay Zaks don’t always agree on these definitions.
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
User avatar
1024MAK
Bugaboo
Posts: 3104
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: Register Addressing Modes

Post by 1024MAK »

To be fair, 6502 programming books make a big deal about addressing MODEs, but Z80 books, not so much. I think partly due to the different mnemonics that are used.

In summary, as with most things, there are as many "standards" as there are CPUs!
Have a read of the Wikipedia page!

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
User avatar
Einar Saukas
Bugaboo
Posts: 3070
Joined: Wed Nov 15, 2017 2:48 pm

Re: Register Addressing Modes

Post by Einar Saukas »

You may find this useful:

https://www.ime.usp.br/~einar/z80table/
Ralf
Rick Dangerous
Posts: 2279
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Register Addressing Modes

Post by Ralf »

I don't quite understand why you are doing it ;) There are so many existing lists of Z80 instructions on Internet.

But if you want your list complete don't forget about undocumented instructions on halves of IX and IY aregisters.

LD IXH,N
LD IYL,N and so on
User avatar
PeterJ
Site Admin
Posts: 6853
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Register Addressing Modes

Post by PeterJ »

Ralf wrote: Mon Nov 27, 2017 8:13 pm I don't quite understand why you are doing it ;) There are so many existing lists of Z80 instructions on Internet.

But if you want your list complete don't forget about undocumented instructions on halves of IX and IY aregisters.

LD IXH,N
LD IYL,N and so on
Hi Ralf. I was just trying to get my head around addressing modes, and making sure everything was in the right section. Its just the way I learn stuff!
User avatar
utz
Microbot
Posts: 113
Joined: Wed Nov 15, 2017 9:04 am
Contact:

Re: Register Addressing Modes

Post by utz »

LD (ADDR),A/LD A,(ADDR) should be in "Extended Addressing" according to this nomenclature. I'd say the term "Memory Indirect" is more descriptive, though.
AndyC
Dynamite Dan
Posts: 1387
Joined: Mon Nov 13, 2017 5:12 am

Re: Register Addressing Modes

Post by AndyC »

Memory Indirect would suggest a level of double indirection, in the same way that Register Indirect does. So if ADDR was 4000h and the value stored at 4000h was 8000h, the a memory indirect load would fetch the byte from 8000h. That's not something the Z80 supports. LD A, (ADDR) is just plain old indirect addressing (with the indirection stored immediately as part of the instruction).
User avatar
utz
Microbot
Posts: 113
Joined: Wed Nov 15, 2017 9:04 am
Contact:

Re: Register Addressing Modes

Post by utz »

Ah yes, you're right of course. Please disregard my statement above.
Post Reply