0

Basically I want to know how does the code know what you have multiplying by what and where is it going?!?

This is hard to explain so heres an example of a style of coding I don't understand how to do:

data
lower_sum DWORD 0

higher_sum DWORD 0
a DWORD 1001
b DWORD 999

.code
main PROC

mov eax, a
mul b ; RIGHT HERE! How does the code know what you have multiplying by what and where is it going?!? it's missing a memory location/register surely?

;... code continues
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Ed G-A
  • 1
  • 1
  • "The Code" knows because the processor specification tells it from and to where. – tkausl Nov 22 '21 at 06:00
  • Yup, x86 has a few instructions with implicit operands, many the accumulator or EDX:EAX as a 32 or 64-bit integer. Check the manual, https://www.felixcloutier.com/x86/mul, and see the linked duplicates (top of the page), and [What kind of address instruction does the x86 cpu have?](https://stackoverflow.com/q/53325275). If you're wondering how MASM magically infers the operand-size from `b`, that's a MASM thing that happens at assemble-time, treating `b DWORD 999` as a "variable" that implies DWORD operand size. – Peter Cordes Nov 22 '21 at 06:08

0 Answers0