multiplication

Should I use “mul” or “imul” when multiplying a signed number to an unsigned number?

爷,独闯天下 提交于 2021-01-01 04:19:30
问题 I have found out that both mul and imul can be used to multiply a signed number to an unsigned number. For example: global _start section .data byteVariable DB -5 section .text _start: mov al, 2 imul BYTE [byteVariable] You can replace imul with mul , and the result would still be the same ( -10 ). Are mul and imul exactly the same when multiplying a signed number to an unsigned number, or is there a difference between them? 回答1: The upper half is different, as mentioned in the comments. If

How many 64-bit multiplications are needed to calculate the low 128-bits of a 64-bit by 128-bit product?

感情迁移 提交于 2020-11-24 16:39:00
问题 Consider that you want to calculate the low 128-bits of the result of multiplying a 64-bit and 128-bit unsigned number, and that the largest multiplication you have available is the C-like 64-bit multiplication which takes two 64-bit unsigned inputs and returns the low 64-bits of the result. How many multiplications are needed? Certainly you can do it with eight: break all the inputs up into 32-bit chunks and use your 64-bit multiplication to do the 4 * 2 = 8 required full-width 32*32->64

How many 64-bit multiplications are needed to calculate the low 128-bits of a 64-bit by 128-bit product?

老子叫甜甜 提交于 2020-11-24 16:38:26
问题 Consider that you want to calculate the low 128-bits of the result of multiplying a 64-bit and 128-bit unsigned number, and that the largest multiplication you have available is the C-like 64-bit multiplication which takes two 64-bit unsigned inputs and returns the low 64-bits of the result. How many multiplications are needed? Certainly you can do it with eight: break all the inputs up into 32-bit chunks and use your 64-bit multiplication to do the 4 * 2 = 8 required full-width 32*32->64