Created
September 16, 2011 23:33
-
-
Save keiya/1223404 to your computer and use it in GitHub Desktop.
128bit bignum multiplying in Assembly
This file contains hidden or 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
| .data | |
| .align 4 | |
| x: .long 0x00124011,0x3130FFFF | |
| y: .long 0x07001245,0x12f01348 | |
| ans: .long 0,0,0,0 | |
| .text | |
| .globl main | |
| main: | |
| #; initialize | |
| mov $0,%ecx | |
| mov $0,%ebp | |
| #; 1. multiply mp L.O * mc L.O. | |
| #; eax: mp; multiplier L.O. | |
| #; edi: mc; multiplicand L.O. | |
| #; ecx: this.answer H.O. | |
| #; ans[0]: this.answer L.O. | |
| mov $0,%esi | |
| mov x(,%esi,4),%eax | |
| mov y(,%esi,4),%edi | |
| mul %edi | |
| mov %eax,ans(,%esi,4) | |
| mov %edx,%ecx | |
| #; 2. multiply mp H.O. * mc L.O | |
| #; eax: mp; multiplier H.O. | |
| #; edi: mc; multiplicand L.O. | |
| #; ecx: (1).answer + this.answer L.O. | |
| #; ebp: this.answer H.O. | |
| mov $1,%esi | |
| mov x(,%esi,4),%eax | |
| mov $0,%esi | |
| mov y(,%esi,4),%edi | |
| mul %edi | |
| add %eax,%ecx | |
| adc $0,%ebp | |
| mov %edx,%ebp | |
| #; 3. multiply mp L.O. * mc H.O. | |
| #; eax: mp; multiplier L.O. | |
| #; edi: mc; multiplicand H.O. | |
| #; ecx: (1).answer + (2.answer) + this.answer L.O. | |
| #; ebp: (2).answer + this.answer H.O. | |
| mov $0,%esi | |
| mov x(,%esi,4),%eax | |
| mov $1,%esi | |
| mov y(,%esi,4),%edi | |
| mul %edi | |
| add %eax,%ecx | |
| adc $0,%ebp | |
| add %edx,%ebp | |
| #; 4. multiply mp H.O. * mc H.O. | |
| #; eax: mp; multiplier H.O. | |
| #; edi: mc; multiplicand H.O. | |
| #; edx: this.answer. H.O | |
| #; ebp: (2).answer + (3).answer + this.answer L.O. | |
| mov $1,%esi | |
| mov x(,%esi,4),%eax | |
| mov y(,%esi,4),%edi | |
| mul %edi | |
| add %eax,%ebp | |
| adc $0,%edx | |
| mov %edx,ans(,%esi,4) | |
| #; answer | |
| mov $0,%esi | |
| mov ans(,%esi,4),%eax | |
| mov %ecx,%ebx | |
| mov %ebp,%ecx | |
| mov $1,%esi | |
| mov ans(,%esi,4),%edx | |
| call stop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment