Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: c4ooo on March 20, 2017, 11:47:20 pm

Title: Shifting data block down a nibble?
Post by: c4ooo 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.
Title: Re: Shifting data block down a nibble?
Post by: SpiroH 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?
Title: Re: Shifting data block down a nibble?
Post by: harold 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.
Title: Re: Shifting data block down a nibble?
Post by: c4ooo 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.
Title: Re: Shifting data block down a nibble?
Post by: Xeda112358 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.