From b42fc64f3c5636318b10cde287a4a187de9b54c1 Mon Sep 17 00:00:00 2001 From: AYIDouble Date: Wed, 12 Sep 2018 11:43:51 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9E=95Add=20callee=20rules=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An example function that follows the callee rules --- Assembler Intel Code/callee_rules.asm | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Assembler Intel Code/callee_rules.asm diff --git a/Assembler Intel Code/callee_rules.asm b/Assembler Intel Code/callee_rules.asm new file mode 100644 index 0000000..4882687 --- /dev/null +++ b/Assembler Intel Code/callee_rules.asm @@ -0,0 +1,31 @@ +.486 +.MODEL FLAT +.CODE +PUBLIC _myFunc + _myFunc PROC + ; Subroutine Prologue + push ebp ; Save the old base pointer value. + mov ebp, esp ; Set the new base pointer value. + sub esp, 4 ; Make room for one 4-byte local variable. + push edi ; Save the values of registers that the function + push esi ; will modify. This function uses EDI and ESI. + ; (no need to save EBX, EBP, or ESP) + + ; Subroutine Body + mov eax, [ebp+8] ; Move value of parameter 1 into EAX + mov esi, [ebp+12] ; Move value of parameter 2 into ESI + mov edi, [ebp+16] ; Move value of parameter 3 into EDI + + mov [ebp-4], edi ; Move EDI into the local variable + add [ebp-4], esi ; Add ESI into the local variable + add eax, [ebp-4] ; Add the contents of the local variable + ; into EAX (final result) + + ; Subroutine Epilogue + pop esi ; Recover register values + pop edi + mov esp, ebp ; Deallocate local variables + pop ebp ; Restore the caller's base pointer value + ret + _myFunc ENDP +END \ No newline at end of file