Skip to content
MPGHThe Dark Arts
/
RegisterLog in
Forum
Community
What's NewLatest posts across the boardTrendingHottest threads right nowSubscribedThreads you follow
Discussion
GeneralIntroductionsEntertainmentDebate FortFlaming & Rage
Board
News & AnnouncementsMPGH TimesSuggestions & HelpGiveaways
More Sections
Art & Graphic DesignProgrammingHackingCryptocurrency
Hacks & Cheats
Games
ValorantCS2 / CS:GOCall of Duty / WarzoneFortniteApex LegendsEscape From Tarkov
+14 moreLeague of LegendsGTA VMinecraftRustROTMGBattlefieldTroveBattleOnCombat ArmsCrossFireBlackshotRuneScapeDayZDead by Daylight
Resources
Game Hacking TutorialsReverse EngineeringGeneral Game HackingAnti-CheatConsole Game Hacking
Tools
Game Hacking ToolsTrainers & CheatsHack/Release NewsNew
Submit a release →Share your cheat, tool, or config with the community.
AINEW
AI Tools
General & DiscussionPrompt EngineeringLLM JailbreaksHotAI Agents & AutomationLocal / Open Models
AI × Gaming
AI Aimbots & VisionML Anti-CheatGame Bots & Automation
Create
AI Coding / Vibe CodingAI Art & MediaAI Voice & TTS
The AI frontier →Where game hacking meets modern machine learning. Jump in.
Marketplace
Buy & Sell
SellingBuyingTradingUser Services
Trust & Safety
Middleman LoungeMarketplace TalkVouch Copy Profiles
Money
Cryptocurrency TalkCurrency ExchangeWork & Job Offers
Start selling →List accounts, services, and goods. Use the middleman to trade safe.
MPGH The Dark Arts

A community for offensive security research, reverse engineering, and AI.

Community

ForumMarketplaceSearch

Account

RegisterLog in

Legal

Privacy PolicyForum RulesHelp & FAQ
© 2026 MPGH · All rights reserved.Built by the community, for the community. For educational purposes onlyContent is shared for security research and education — we don't condone illegal use. You're responsible for complying with applicable laws. Use at your own risk.
Home › Forum › Programming › Other Programming › Assembly › User defined functions?

User defined functions?

Posts 1–3 of 3 · Page 1 of 1
Void
Void
User defined functions?
Hey, I'm back with a few more questions on assembly

Anyways, I've been trying to make my own function that adds 2 numbers but I ran into a couple of problems. Hopefully you guys can help me out a little.

Code:
.386
.model flat,stdcall
option casemap:none

include\masm32\include\windows.inc

.code

main:
	
	Addition proc x:DWORD, y:DWORD
	
	mov eax,[ebp+8]
	add eax,y
	Ret
Addition EndP

	push 10
	push 5
	call Addition
	
end main
Okay, so I have a question about what happens after you call the function. For some reason after I do "call Addition" all code after that is completely ignored and the program just closes. No idea why that's happening.

Second question, I sort of understand how to use the base pointer register. Inside the function I can do [ebp+8],[ebp+12]..etc for the parameters to the function but... what happens to the base pointer right after the function is called? Will [ebp+8] still give me the first parameter?

Err.. Third question. What the hell does RET do. It's killing me... I have absolutely no idea why it's there. As soon as I typed "Addition proc" into WinAsm studio it automatically puts it there for me so I'm guessing it's important.

Last question. I've seen people do "esp+12" sometimes. And I believe it's because there are 3 4 byte addresses pushed onto the stack and I guess it "removes" them.. Not sure about that and that's why i'm asking this question. ALSO... why would you ever do "esp+12", if you don't clear the stack will it affect the next time I call a function?

Alright I'm done.. Sorry for all the questions. Thanks to anyone who takes their time to even look at this.

~David
#1 · 16y ago
B1ackAnge1
B1ackAnge1
If this is your actual listing, then there is no code after you call the function so the program just exits.
Your store your result in EAX so if you wanted to do something with the answer you can write some more code
that deals with that after the 'call Addition' line.

Ret is like 'return' in C++, and just is there so the program knows to return to the line after which the call
was made (as you probably read somewhere: ebp = old ebp value, ebp+4 = return address, ebp+8=1st argument etc, so basically
'ret' says 'jmp to ebp+4' and ebp should be restored to the old ebp value
Say you push 2 32bit values before a function call. If you see 'ret 8' in the function it means it's cleaning up the stack those 8 bytes for you (updating where esp points). Depending on the caling convention the caller may need to do the cleanup instead, and that's when you see:
Code:
push eax
push ebx 
call someFunction  
add esp, 8			;This cleans up the stack pointer to 'get rid' of the 2 arguments we pushed earlier
Depending on how a function call is setup, ESP can point to 'local variables' in the function. Wikipedia had this interesting example:
Code:
As an example, the following C code:

void MyFunction3(int x, int y, int z)
{
  int a, int b, int c;
  ...
  return;
}

Will create the following assembly code:

push ebp
mov ebp, esp
sub esp, 12 ; sizeof(a) + sizeof(b) + sizeof(c)
;x = [ebp + 8], y = [ebp + 12], z = [ebp + 16]
;a = [ebp - 12] = [esp], b = [ebp - 8] = [esp + 4], c = [ebp - 4] = [esp + 8]
mov esp, ebp
pop ebp
ret 12 ; sizeof(x) + sizeof(y) + sizeof(z)

Hope that clears things up a bit
#2 · 16y ago
Void
Void
Thanks, I'm starting to understand the EBP and ESP registers alot more now. And as for the code I posted, I tryed opening a Message box after calling just to test it and nothing happened, it just closed.
#3 · 16y ago
Posts 1–3 of 3 · Page 1 of 1

Post a Reply

Similar Threads

  • [HELP] User-Definable Function StringsBy ilovepie21 in Visual Basic Programming
    1Last post 18y ago
  • How do u define function in VB6By ilovepie21 in WarRock - International Hacks
    5Last post 18y ago
  • Re-defining Super Users =OBy arunforce in General
    55Last post 17y ago
  • User barsBy mostwanted in Spammers Corner
    4Last post 17y ago
  • blah blah userBy l0s3rg0d in Art & Graphic Design
    19Last post 20y ago

Tags for this Thread

None