Author Topic: Shifting data block down a nibble?  (Read 4246 times)

0 Members and 1 Guest are viewing this topic.

Offline c4ooo

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 252
  • Rating: +10/-1
  • The impossible chemical compound.
    • View Profile
Shifting data block down a nibble?
« on: March 20, 2017, 11:47:20 pm »
How do I shift a block of data down a nibble? IIRC there was an instruction that swapped nibbles or something that made this easy. The shifted data will never be >256 bytes long.

Posted on omni since it seems that all the monochrome z80 programmers have remained here.
-German Kuznetsov
The impossible chemical compound.

Offline SpiroH

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 729
  • Rating: +153/-23
    • View Profile
Re: Shifting data block down a nibble?
« Reply #1 on: March 22, 2017, 10:02:10 am »
Hi @c4ooo,
Can you be a bit more specific? AFAICT a nibble is just a set of 4 bits glued together; why don't you just shift-right by a constant of multiple of 4, or do you something else on your mind/question?

Offline harold

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 226
  • Rating: +41/-3
    • View Profile
Re: Shifting data block down a nibble?
« Reply #2 on: March 22, 2017, 11:21:54 am »
The relevant instruction is RRD, it's not very fast but it seems like nothing is ever fast on z80..

You can do something like
Code: [Select]
  xor a
_shiftloop:
  rrd
  dec hl
  djnz _shiftloop
Maybe inc hl, depends on the endianness of your buffer.
Blog about bitmath: bitmath.blogspot.nl
Check the haroldbot thread for the supported commands and syntax.
You can use haroldbot from this website.

Offline c4ooo

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 252
  • Rating: +10/-1
  • The impossible chemical compound.
    • View Profile
Re: Shifting data block down a nibble?
« Reply #3 on: March 22, 2017, 07:46:57 pm »
Hi @c4ooo,
Can you be a bit more specific? AFAICT a nibble is just a set of 4 bits glued together; why don't you just shift-right by a constant of multiple of 4, or do you something else on your mind/question?
I need to shift the buffer down/up a nibble (4 bits). So something like 0xABCD -> 0x0ABCD0

The relevant instruction is RRD, it's not very fast but it seems like nothing is ever fast on z80..

You can do something like
Code: [Select]
  xor a
_shiftloop:
  rrd
  dec hl
  djnz _shiftloop
Maybe inc hl, depends on the endianness of your buffer.
Thanks, will investigate later.
-German Kuznetsov
The impossible chemical compound.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Shifting data block down a nibble?
« Reply #4 on: March 25, 2017, 08:18:15 pm »
harold's method is essentially what I did to shift the screen left or right by multiples of 4. It's slow, but faster than shifting by 1 four times.