0

For homework I need to answer a few of these questions but I can't seem to find the answer to this problem, and I don't fully understand. I know you aren't supposed to just give me the answer, but can anyone explain how I should solve this?

What will be the content of register eax (in hexadecimals) after this block of code? (I know it isn't a functioning piece of code btw)

I already know that:

  • EBX: ?? ?? ?? ??
  • ECX: ?? ?? ?? ??
  • EDX: 00 00 00 00
I: dd 4 
...
mov eax, 0 
mov edx, 1 
idiv dword [I]
Peter Cordes
  • 286,368
  • 41
  • 520
  • 731
  • Try using a debugger to figure out wat eax's value will be – Casper Kuethe Jan 08 '22 at 22:14
  • I tried using an online debugger but it won't seem to work (part of the problem is that in school we use commands that are "written" by our teachers, so I probably don't fully know assembly, and the code won't run). Problem nr. 2: if I would have to do this on the exam I can't use a debugger, I should be able to calculate (?) what's inside eax. Any other ideas on how to do this? Thanks already! – Ube Van Grimbergen Jan 08 '22 at 22:24
  • Well, you apparently know it's doing `0/4` ... what do you think the result of that is? It's obviously 0. – Jester Jan 08 '22 at 22:24
  • yeah that was my first thought as well, but it is wrong for some reason... – Ube Van Grimbergen Jan 08 '22 at 22:25
  • 4
    @Jester: They *think* it's doing `0/4`, but the title forgot to mention that EDX=1 before division!!! So it's doing `(1<<32) / 4`. – Peter Cordes Jan 08 '22 at 22:27
  • Oops ... good catch! – Jester Jan 08 '22 at 22:28
  • Peter, can you explain further, I don't fully understand what you are saying and what the result of that would be? – Ube Van Grimbergen Jan 08 '22 at 22:33
  • `idiv` takes as its inputs the 64-bit number formed as `edx:eax` and the divisor specified as the explicit 32-bit operand. The high doubleword in `edx` is nonzero in this case. – ecm Jan 08 '22 at 22:43
  • someone else told me the answer to the question is 40 00 00 00 but even after reading all your answers and links to other posts, I still can't really figure out anything, how do they come to this answer? – Ube Van Grimbergen Jan 08 '22 at 22:52
  • 3
    Since `edx` is `1`, and that is the top 32 bits of the dividend, you are doing `0x0000000100000000 / 4` which is `0x40000000`. – Jester Jan 08 '22 at 22:59

0 Answers0