tags:

views:

49

answers:

2

.intel_syntax noprefix

.include "console.i"


.data
        ask1:   .long  0
        ask2:   .long  0
        ans :   .long  0

.text
        ask:    .asciz "Enter number: "
        ans1:   .asciz "multiplication= "

_entry:

        Prompt ask
        GetInt ask1
        Prompt ask
        GetInt ask2

        mov eax, ask1
        mov edx, ask2
        mul edx
        mov ans,edx

        Prompt ans1
        PutInt ans
        PutEol

 ret

.global _entry

.end



OUTPUT:
      Enter number: 2
      Enter number: 4
      multiplication= 0


In above code it gives output as 0.
why it is showing 0  instead of 8 ?

edit1: added mov ans, edx
A: 

You're using quite a few macros I don't understand, but the basic problem seems to be that you're not doing anything with the results of 'mul edx'.

The result of MUL EDX are in edx:eax and you seem to be throwing that information away without putting it in your variable ans.

Daniel Goldberg
At the time of writing this, the highest bits of the results are put in `ans` by the instruction `mov ans,edx` leading to the result of 0.
Pascal Cuoq
@bunty As Daniel says, the `mul` instruction puts its result in edx:eax (most significant bits in edx, lowest in eax). If you wish to simply ignore overflows, get the result from eax, not edx, after the multiplication.
Pascal Cuoq
+1  A: 

You are multiplying edx to eax, so your result is stored in eax, not edx.

your code :

mul edx
mov ans,edx

you are assigning value of edx to ans. You should store value of eax into ans.

mul edx
mov ans,eax
Searock