I have a program that multiplies 3 numbers and i am trying to understand. I have some questions and i am hoping someone can explain whats going on with the program and tell me if i am on the right track. I understand i have more than one question so i am sorry about that.
.data?
num1 dd ?
num2 dd ?
num3 dd ?
.data
sum dd 0
prod dd 0
.code
start:
main proc
mov EAX, sval(input("Enter a number: "))
mov num1, EAX
mov EAX, sval(input("Enter a number: "))
mov num2, EAX
mov EAX, sval(input("Enter a number: "))
mov num3, EAX
mov EAX, num1
mov EBX, num2
mul BL
mov EBX, num3
mul BX
mov prod, EDX
this has me confused…
mov EBX, num3
mul BX
so, we are storing num3 into BL?
but since the result of num1 and num2 is 16 bit and stored into AX
we mul BX? instead of BL? but isnt num3 in BL?
im sorry there isnt one specific question. If my logic is incorrect or close can you explain whats going on piece by piece and why?
Thank you
When you do an 8-bit multiplication like
mul bl, it takesal, multiplies it by the specified input, and puts the result inax.When you do a 16-bit multiplication like
mul bx, it takesax, multiplies it by the specified input, and puts the result indx:ax(i.e., the 16 most significant bits of the result indx, and the 16 least significant bits of the result inax).(Just for completeness): if you do a 32-bit multiplication like
mul ebx, it multiplieseaxbyebx, and puts the result inedx:eax(offhand I don’t remember for sure, but I’d guess 64-bit multiplication works about the same way).As far as
BLvs.BXgoes (orAL/AH/AX, etc.), what you have aren’t really separate registers —ALis really the 8 least significant bits ofAX.AHis the 8 most significant bits of AX. BL is the 8 least significant bits of BX, and BH is the 8 most significant bits of BX (and so on for CL/CH/DL/DH).For example, if you execute code like:
BH will then equal 0 (set to zero by the
xor bx, bx), BL will equal 1 (set by the mov) and bx will also equal 1 (because it now contains the bit pattern 00000000 00000001).