Problems dividing 64 bits in x86 Assembly

后端 未结 2 1320
遇见更好的自我
遇见更好的自我 2021-01-16 16:56

I keep getting \'Program received signal SIGFPE, Arithmetic exception\' when dividing in x86 Assembly. It\'s confusing because the answer should be smaller than a 64 bit ans

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-16 17:19

    You'll need to do this division similar to long hand division by hand. Put the dividend in another pair of registers or memory. Then clear edx and load eax with the high order dividend. Then divide edx:eax by the 32 bit divisor, and store eax (quotient) back into high order dividend. Next load eax with low order dividend (leaving edx alone), and divide by the 32 bit divisor again. Store eax back into low order dividend. After this, high and low order dividend = dividend/divisor (a 64 bit quotient), and edx = dividend % divisor (32 bit remainder).

提交回复
热议问题