Created
June 24, 2021 13:44
-
-
Save iconjack/800da80044f7a8c65f5470489a9e1fb8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Inputs: A and B are bit-strings of length N, | |
; right-justified in EAX and EBX respectively; | |
; N ≤ 30 is in ECX, and A ≠ B. | |
; | |
; Output: ESI/EDI (a fraction) is the probability | |
; that bit-string A beats bit-string B. | |
Magic: | |
PUSH EAX | |
PUSH EBX | |
MOV EBX, EAX | |
CALL InnerMagic | |
MOV ESI, EDX | |
POP EBX | |
CALL InnerMagic | |
SUB ESI, EDX | |
MOV EAX,EBX | |
CALL InnerMagic | |
MOV EDI, EDX | |
POP EBX | |
CALL InnerMagic | |
SUB EDI, EDX | |
ADD EDI, ESI | |
RET | |
InnerMagic: | |
PUSHAD | |
NEG ECX | |
SHL EBX, CL | |
MOV EDI, 1 | |
MOV ESI,80000000H | |
XOR EBP,EBP | |
next: ROR EAX, 1 | |
MOV EDX, EAX | |
XOR EDX, EBX | |
AND EDX, ESI | |
JNZ skip | |
ADD EBP, EDI | |
skip: SAR ESI, 1 | |
SHL EDI, 1 | |
INC ECX | |
JNZ next | |
MOV 20[ESP], EBP | |
POPAD | |
RET |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment