Good evening everyone, I faced the problem of creating a procedure in assembler .. Language is difficult for me to understand. Please explain to me how to work with procedures .. For example, is the verification procedure the sum of two numbers more than the third number? Does she need any parameters to pass .. I would be very grateful for the help.

  • Most often, parameters are needed and often you need a return value. In your case, it is expected that the procedure should receive 3 numbers by parameters, two of which add up, and the third one to compare and in some form return the result of the comparison (in principle, you can restrict the final comparison instruction to the specified flags) - Mike
  • Be kind, can you somehow vivid example? - Delka
  • load in some registers that decide to use as parameters, make a call, add / check in a procedure, leave a result in some register or just return the result in flags - Mike

1 answer 1

There are 2 ways to pass parameters - push them to the stack or push them into registers, and the result output is usually written to the rax / eax register

option 1

proc func1 add eax, ebx cmp eax, ecx jg label1 jl label2 mov eax, 0 retn label1: mov eax, 1 retn label2: mov eax, -1 retn 

option 2:

 proc func2 pop ecx pop ebx pop eax call func1 retn 

With the syntax I can make a little mess up, but I hope you understand the meaning

PS I found a couple of links http://devotes.narod.ru/Books/3/ch05_02a.htm

  • one
    Well, they don’t do that to the stack, at the moment you call the return address on the top of the stack, which put the call there, it means pop ecx will load this address into ecx (or part of it, depending on what the call was) and there will be no address on the stack retn at the end will not know where to jump. If you have a Pascal call format (the stack releases the callee), you must first save the return address somewhere, then pick up the arguments and then return the return address to the place. If the C-call is used, then simply remove the parameters from the stack, not pop, but mov with offsets relative to the current SP - Mike
  • yes, really, my cant - Zhihar