You are not logged in.

#1 2019-11-10 22:54:08

SourceEngine
Member
Registered: 2019-02-18
Posts: 14

Need help understanding this assembly code

Function phase_2 takes an array of 6 integers separated by spaces. The code is executed in a 32bit environment using cdecl.

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?

Last edited by SourceEngine (2019-11-10 22:55:38)

Offline

#2 2019-11-11 01:09:28

SourceEngine
Member
Registered: 2019-02-18
Posts: 14

Re: Need help understanding this assembly code

nvm the key is inside read_six_numbers, which I failed to take notice at first...

Offline

#3 2019-11-28 18:20:44

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 237

Re: Need help understanding this assembly code

I guess read_six_numbers() converts char * to array of 32-bit integers. Element with index 0 has address %esp+0x18, element with index 1 has address %esp+0x18+4 = %esp+0x1C.

Offline

Board footer

Powered by FluxBB