Search code examples
assemblyx86masmmasm32

x86 assembly Which registers are involved in multiplication and division


Here is my code:

.data
        ans1 db 0
        ans2 db 0
.data? 
        in1 db 100 dup(?) ; first input value
        in2 db 100 dup(?) ; second input value
.code
start:
        ; here I have code for input 
        ; I get 2 nums, and I want to multiply and divide them
        ; here is what I already have to mul/div them:
        lea eax, in1
        lea edx, in2
        imul eax ; multiply in1 and in2
        mov ans1, eax ; move result to ans1
        xor eax, eax ; clear register
        xor edx, edx ; " "
        lea eax, in1
        lea edx, in2
        idiv eax ; divide in1 by in2
        mov ans2, eax ; move result to ans2
        lea eax, ans1
        push eax
        call StdOut ; print ans1 (I have include instructions at the start)
        lea ebx, ans2
        push ebx  
        call StdOut ; print ans2 ("")

My question: 1. Exactly which register do I put in1 and in2 to multiply them? 2. " " to divide them? 3. Where is the remainder stored in a division?

And don't worry about a general statement, could you just tell me which registers will definitely (as close as possible) work in multiplication and division.

NOTE: Some may say that this post is a repetition of x86 assembly - masm32: absolute breakdown of multiplication and division , but (correct me if I am wrong) it is more respectful of the forum community to make a new post, rather than add comments to the old one and make it off topic.


Solution

  • If you're writing assembly, you should never be too far away from the reference spec:

    Unsigned multiply (AX ← AL ∗ r/m8).
    

    Tells you everything you need to know. The result will be placed in AX. The sources are AL and any 8 bit register or memory location.

    EDIT

    Your question isn't/wasn't formatted correctly, your questions were on the same line.

    Division is DIV:

    Unsigned divide AX by r/m8, with result stored in AL ← Quotient, AH ← Remainder
    

    Seriously: read the manual.