0

I've got this mind boggling project which has been messing with me. I need to write a program to get 2 numbers from input, add them together or multiply them. this program should be able to get double words as well.

I know how to get numbers from input, how to add or multiply them if their size is at max a word, but I can't solve this double word thing.

Does anyone have the code?

thanks in advance.....

2 Answers2

2

I'm going to assume that the assignment goal is for you to work with numbers double the size of the registers, such as 32 bit numbers in 16 bit mode, or 64 bit numbers in 32 bit mode. Multiplies can be done similar to long hand multiplication. I assume you can use a multiply instruction where the product is double the size of the multiplicand or multiplier. This example shows a space between the "words" of numbers:

            aaaa bbbb        ;multiplicand
x           cccc dddd        ;multiplier
---------------------
            eeee eeee        ;bbbb x dddd
       ffff ffff             ;aaaa x dddd
       gggg gggg             ;bbbb x cccc
+ hhhh hhhh                  ;aaaa x cccc
---------------------
  pppp pppp pppp pppp        ;product
rcgldr
  • 27,407
  • 3
  • 36
  • 61
1

In x86:

MOV EBX,OP1
MOV EAX,OP2
IMUL EBX

The result is in EDX:EAX (32 bit registers) high order 32 bits is stored in the EDX register and low order 32-bits is stored in the EAX register.

This link should help if you need more explanation: https://www.tutorialspoint.com/assembly_programming/assembly_arithmetic_instructions.htm

Community
  • 1
  • 1
abraxascarab
  • 661
  • 1
  • 6
  • 13
  • Widening multiplies are the building-block you would use to create a 64-bit * 64-bit multiply on 32-bit x86, but you need 3 of them to get the 64-bit result. (And 4 of them to get the full 128b result). I think the OP is asking about working with operands that are twice as large as a register, not just how to multiply a DWORD in x86. – Peter Cordes Dec 15 '16 at 21:33