Started by AMSDOS, 12:11, 03 May 16
0 Members and 1 Guest are viewing this topic.
Quote from: Docent on 23:54, 05 May 16It 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)rrcarrcarrcald h,aand 0xe0ld l,axor hld h,ald a,(ix+1)rrcarrcarrcaand 0xe0or hld h,aIt takes 90 tstates which is similar to rld;sla code for 16bit values I posted earlier and consumes x2 more memory...
Quote from: Docent on 16:19, 05 May 16Try this:xor ald hl, varrldsla (hl)inc hlrldrl (hl)var: dw 0If you have your variable in ix, replace ld hl, var with push ix; pop hl
ld l,(ix+02)ld h,(ix+03)
ld (ix+04),lld (ix+05),h
Quote from: AMSDOS on 12:47, 06 May 16Oh 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. 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.
Quote from: Docent on 22:06, 06 May 16I 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,#08mul8loop: rrca jr nc,mul8skip add hl,demul8skip: sla e rl d djnz mul8loopThis 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.
Page created in 0.057 seconds with 31 queries.