bunty
bunty

Reputation: 2785

in following code showing output 0 instead of 8

.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

Upvotes: 1

Views: 153

Answers (2)

Searock
Searock

Reputation: 6468

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

Upvotes: 1

Daniel Goldberg
Daniel Goldberg

Reputation: 20518

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.

Upvotes: 0

Related Questions