How is LDIR affecting memory?

Posts about Z80 programming that do not relate to a particular computer
Post Reply
Stroopwafel
Posts: 1
Joined: Tue Sep 15, 2020 8:48 am

How is LDIR affecting memory?

Post by Stroopwafel » Thu Sep 17, 2020 6:40 am

Hi,

I'm new here, thank you for giving me access to this forum. I'm following your lessons here (and watching the videos) but I'm already stuck at lesson two. Here LDIR is used to loop over memory addresses to set them to 0 to clear the screen. In the cheat sheet LDIR is explained as

Code: Select all

Load HL, DE
Until b=0:
  inc HL
  inc DE
  dec BC
HL and DE are pointed to two memory locations. So when they are both increased as long as BC has room to decrease, they are just pointing to the next memory location. How is this affecting that memory?

User avatar
akuyou
Posts: 430
Joined: Mon Apr 22, 2019 3:19 am
Contact:

Re: How is LDIR affecting memory?

Post by akuyou » Sun Sep 20, 2020 7:22 am

Hey there! thanks for the question!

I think you've slightly misread the cheatsheet (unless there's a misprint version out there)

The first line should be:
LD (DE),(HL)

Notice the brackets ()?

HL means the value in HL
(HL) means the byte at address HL
so "LD (DE),(HL)" copies one byte from address HL to address DE

Note there's no such command as LD (DE),(HL) - it's just explaining what the command does... but the principal is the same as the real commands:
LD A,(HL)
LD (DE),A
Chibi Akuma(s) Comedy-Horror 8-bit Bullet Hell shooter! // 「チビ悪魔」可笑しいゴシックSTG ! // Work in Progress: ChibiAliens

Interested in CPU's :Z80,6502,68000,6809,ARM,8086,RISC-V
Learning: 65816,ARM,8086,6809

Post Reply

Return to “General Z80 Programming”