Wednesday, November 17, 2010

multiply with carry generator, in 16-bit intel

based on the prime 65532*65535-1, which has 65535 as a primitive root. period is around 2^32.


13C8:0200 52 PUSH DX
13C8:0201 B80000 MOV AX,0000
13C8:0204 BAFCFF MOV DX,FFFC
13C8:0207 F7E2 MUL DX
13C8:0209 050100 ADD AX,0001
13C8:020C 83D200 ADC DX,+00
13C8:020F 01D0 ADD AX,DX
13C8:0211 7302 JNB 0215
13C8:0213 40 INC AX
13C8:0214 42 INC DX
13C8:0215 2E CS:
13C8:0216 A30202 MOV [0202],AX
13C8:0219 2E CS:
13C8:021A 89160A02 MOV [020A],DX
13C8:021E 5A POP DX
13C8:021F C3 RET


and the complementary version, based on the prime 65518*65535+1:


1444:0200 52 PUSH DX
1444:0201 B80000 MOV AX,0000
1444:0204 BAEEFF MOV DX,FFEE
1444:0207 F7E2 MUL DX
1444:0209 050000 ADD AX,0000
1444:020C 83D200 ADC DX,+00
1444:020F 01D0 ADD AX,DX
1444:0211 7302 JNB 0215
1444:0213 40 INC AX
1444:0214 42 INC DX
1444:0215 F7D0 NOT AX
1444:0217 48 DEC AX
1444:0218 2E CS:
1444:0219 A30202 MOV [0202],AX
1444:021C 2E CS:
1444:021D 89160A02 MOV [020A],DX
1444:0221 5A POP DX
1444:0222 C3 RET

No comments: