I’m having some troubles with the following actions in assembly.
I’m working on assembly IA32. Assume -4(%ebp)=x and -8(%ebp)=y and I get them from user already.
this is the code:
format1: .string "Multiply : %u * %u = %llu\n"
format2: .string "Divide : %u / %u = %u\n"
# operation multiply
movl -4(%ebp), %eax
mull -8(%ebp)
pushl %edx
pushl %eax
pushl -8(%ebp)
pushl -4(%ebp)
pushl $format1
call printf
# operation divide
movl -4(%ebp), %eax
divl -8(%ebp)
pushl %eax
pushl -8(%ebp)
pushl -4(%ebp)
pushl $format2
call printf
The reason the result of the multiply is in %llu is because I want to be able to multiply 2 long numbers and print the result even if it reaches 64 bytes.
And also that in %edx the mull command saves the “other 32 bytes” of the 64 byte result, so I need to push it to the stack as well for the printf.
e.g. I want this output:
Multiply : 4000000000 * 2 = 16000000000
Also, I want the divide operation of 3 with 4 to return X.YZ result. (no more than 2 numbers in the mantissa, and no rounding off)
e.g.
Divide : 3 / 4 = 0.75
for 19 and 1000:
Divide : 19 / 1000 = 0.01
and for 8 and 2:
Divide : 8 / 2 = 4.00
I really tried alot to get the result but no success.
thanks ALOT! 🙂
Yes, of course you can use
scanf, just pass the correct arguments.As you have been told, for floating point result you need to use some floating point divide and a floating point format for printing.
Note that according to calling convention, you should preserve value of
ebxregister. Furthermore, you should keep stack balanced, and preferably aligned.A possible solution:
See the code in operation.