Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / Source Help

'frame off' + 'push\pop' + 'using'

A community discussion post from the original code:zIRON forum.

0CodErr member
Posts
201
Threads
37
Location
Unknown

'frame off' + 'push\pop' + 'using'

This function

#set frame off;
function test(dword x) {
  eax = x;
  using eax{eax = x}
  push eax
  mov eax, x
  pop eax
}

translates to

        mov    eax, [esp + 4]
        push   eax
        mov    eax, [esp + 8]
        pop    eax
        push   eax
        mov    eax, [esp + 8]
        pop    eax
        ret    4

As we can see the offset of 'x' after 'push' is calculated correctly. Can you explain how it works and in which case it may not work?

Replies

Colin admin
Posts
928
Threads
49
Location
Bulgaria

The method I have wrote to track the stack works quite well, but it does have flaws, I can't say exactly what they are since I have not tested 100% everything, but if you find any bugs, just let me know :)

0CodErr member
Posts
201
Threads
37
Location
Unknown

Some code is added in function:

#set frame off;
function test(dword x) {
  eax = x;
  using eax{eax = x}  
  push eax
  mov eax, x
  pop eax
  
  using ax{eax = x}
  push ax
  mov eax, x
  pop ax
  
  esp--;
  mov eax, x
  esp++;
}

Result:

        mov    eax, [esp + 4]
        push   eax
        mov    eax, [esp + 8]
        pop    eax
        push   eax
        mov    eax, [esp + 8]
        pop    eax
        push   eax
        mov    eax, [esp + 6]
        pop    eax
        push   eax
        mov    eax, [esp + 6]
        pop    eax
        dec    esp
        mov    eax, [esp + 4]
        inc    esp
        ret    4

If esp changed directly then result incorrect. After [olor=#0011ff]using ax[/color] offset correct but push eax used instead of push ax.