1 Replies - 473 Views - Last Post: 11 November 2019 - 01:17 AM

#1 Portal   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-November 19

Need help understanding this assembly code

Posted 10 November 2019 - 05:15 PM

Dump of assembler code for function phase_2:
   0x08048b74 <+0>:	push   %esi
   0x08048b75 <+1>:	push   %ebx
   0x08048b76 <+2>:	sub    $0x34,%esp
   0x08048b79 <+5>:	lea    0x18(%esp),%eax
   0x08048b7d <+9>:	mov    %eax,0x4(%esp)
   0x08048b81 <+13>:	mov    0x40(%esp),%eax
   0x08048b85 <+17>:	mov    %eax,(%esp)
   0x08048b88 <+20>:	call   0x804931c <read_six_numbers>
   0x08048b8d <+25>:	cmpl   $0x0,0x18(%esp)
   0x08048b92 <+30>:	jne    0x8048b9b <phase_2+39>
   0x08048b94 <+32>:	cmpl   $0x1,0x1c(%esp)

0x08048b94 <+32>: cmpl $0x1,0x1c(%esp) is supposed to check whether the first element of an array is 1. I have no idea, however, where the compiler is getting 0x1c from... Why is 0x1c(%esp) referring to the first element of the array...? Does little endianess play a role here?

Is This A Good Question/Topic? 0
  • +

Replies To: Need help understanding this assembly code

#2 Ornstein   User is offline

  • D.I.C Head

Reputation: 32
  • View blog
  • Posts: 64
  • Joined: 13-May 15

Re: Need help understanding this assembly code

Posted 11 November 2019 - 01:17 AM

I assume this is the (dis)assembly for some C code? It would be easier to explain/illustrate exactly what the compiler is doing if you posted the original code, but as a general rule:

When you create local variables or function parameters in C, these are usually allocated on the stack. So I'd guess your array is somewhere on the stack, but not necessarily at or near the beginning (which means you probably have other parameters and local variables than the array and/or the compiler is using some of the stack for its own purposes) - or because the compiler has been modifying ESP (possibly for the read_six_numbers call), 0x1C is just the offset to the first element of the array from whatever address happens to be in ESP at the time.

Does this make sense / sound right to you?

This post has been edited by Ornstein: 11 November 2019 - 01:17 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1