News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_AMSDOS

Using SRA (HL) or SRL (HL)

Started by AMSDOS, 10:11, 03 May 16

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AMSDOS

Quote from: Docent on 21:54, 05 May 16
It wont work - you did 3 rotation for lsb and 1 rotation for msb in h and did not mask unnecessary bits.
The main idea for TFMs code is to rotate bits in a byte instead of shifting. In case of shifting you do sla and rl 5 times to get the result like in the example I gave earlier.
In case of rotation, you rotate the content by 3 bits in the opposite direction. Madrams example code does 8bit multiplication by 32 with 16bit result. 
If you are looking for 16bit*32 multiplication with rotation, the code would probably look as follows:

ld a, (ix)
rrca
rrca
rrca
ld h,a
and 0xe0
ld l,a
xor h
ld h,a

ld a,(ix+1)
rrca
rrca
rrca
and 0xe0
or h
ld h,a

It takes 90 tstates which is similar to rld;sla code for 16bit values I posted earlier and consumes x2 more memory...


Oh well, that's a bit slower than the add hl,hl.


Was just trying something based on ones comments, but missed the masking components. But as you can probably tell, I've had little to do with rotation.  ;D


Incidentally I was poking around on CPCRULEZ and forgot about Math Programming they had there. This page looks interesting, was just wondering if "Doc n°3" could be useful? It uses RRA, ADD HL,DE SLA E RL D and a couple of loops in play.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

AMSDOS

Quote from: Docent on 14:19, 05 May 16
Try this:

xor a
ld hl, var

rld
sla (hl)
inc hl
rld
rl (hl)


var: dw 0

If you have your variable in ix,  replace ld hl, var with push ix; pop hl


Sorry I only just noticed this. Hmm, well the code I'll be putting into my game, which is being written in Hisoft Pascal. I managed to get it to work with the ADD HL,HL routine earlier, so in HP a function is defined:


FUNCTION row(xpos : integer) : integer;


that Function name and Variables defined are accessible from Index Registers like this:



ld l,(ix+02)
ld h,(ix+03)



for xpos, and the value can be put back into row like this:



ld (ix+04),l
ld (ix+05),h



But am interested if another way is possible, but will probably get confused!  ???
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Docent

Quote from: AMSDOS on 10:47, 06 May 16

Oh well, that's a bit slower than the add hl,hl.


Was just trying something based on ones comments, but missed the masking components. But as you can probably tell, I've had little to do with rotation.  ;D


Incidentally I was poking around on CPCRULEZ and forgot about Math Programming they had there. This page looks interesting, was just wondering if "Doc n°3" could be useful? It uses RRA, ADD HL,DE SLA E RL D and a couple of loops in play.

I had a quick look at the page you linked - and the code there is incorrect. It claims to multiply DE by A, but it does only partial calculation - look at  ld ,b 6 - it should be ld,b 8. Here's the correct one:

   ld hl,#0000
   ld b,#08
mul8loop:
   rrca
   jr nc,mul8skip
   add hl,de
mul8skip:
   sla e
   rl d
   djnz mul8loop

This does generic 16bit*8bit multiplication, but it will be much slower than the dedicated solution for *32 provided earlier, because the code needs to iterate through all 8 bits of the multiplier. Only the mandatory part (rrca, sla e, rl d, djnz) will take more than 250 tstates, so in your case, if you don't need the generic multiplication,  it is better to stick to add hl,hl trick.

AMSDOS

Quote from: Docent on 20:06, 06 May 16
I had a quick look at the page you linked - and the code there is incorrect. It claims to multiply DE by A, but it does only partial calculation - look at  ld ,b 6 - it should be ld,b 8. Here's the correct one:

   ld hl,#0000
   ld b,#08
mul8loop:
   rrca
   jr nc,mul8skip
   add hl,de
mul8skip:
   sla e
   rl d
   djnz mul8loop

This does generic 16bit*8bit multiplication, but it will be much slower than the dedicated solution for *32 provided earlier, because the code needs to iterate through all 8 bits of the multiplier. Only the mandatory part (rrca, sla e, rl d, djnz) will take more than 250 tstates, so in your case, if you don't need the generic multiplication,  it is better to stick to add hl,hl trick.


Thanks for explaining that. I'm unsure if the code on CPCRULEZ has come from a magazine, normally they give the magazine source in those cases.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Powered by SMFPacks Menu Editor Mod