8086 build question what does this code do

I got this question on my build course:

what does this procedure do and what should it be called?

push ebp
mov ebp, esp    
push esi

mov esi, [ebp+4]
mov eax, [esi]
sub eax, [esi+4]
add esi, 8
mov [ebp+4], esi

pop esi
pop ebp
ret

it looks like it [ebp+4]is an argument, not a return address, so it should be called using "jmp" rather than "call". I really don’t understand what should be found on [esi+4]and on esi+8(return address) hmm, I'm really confused, hope you can help me
thanks in advance.

+3
source share
3 answers

As you rightfully notice, if this procedure is called using call, then [ebp+4]this is the return address. This does not mean that it is a bad idea.

, call. " ", , , call. x. x 32- , x x + 4. , eax. , x + 8 [ebp+4], , ret x + 8. , , :

call yourroutine
dd   56478634
dd   18943675
mov  ebx, eax  ; an example instruction

call mov, eax 37534959 (, 18943675 56478634).

, eax , ( ). , ( - ).

, jmp. [ebp+4] , . ( y), y y + 4, eax, y + 8 [ebp+4]. , ret , , . , call; , ret . :

    push   foobar
    jmp    yourroutine
    ...  ; unreached code

foobar:
    dd 56478634
    dd 18943675
    mov  ebx, eax  ; an example instruction

eax. . , , , , ( , ).

+2

, (eip ) , [ebp+4] . 2 , , eax, 8, .. add esi,8 mov [ebp+4], esi. ret (, , ....).

, ..

+1

, call - ret .

, , , . , :

eax:
esp:
ebp:
esi:

as well as other appropriate memory (for example, the area around the top of the stack).

This is an ideal way to learn about programming (in any case, for small programs), in which you will learn to analyze and understand them in detail. And I'm afraid that about the same help as I am going to give for homework :-)

+1
source

All Articles