opc0d3 Posted July 25, 2017 Share Posted July 25, 2017 Hi guys! Me again.. I was trying to write a simple nasm printf program.. I did it.. it looks ok, but the printf is going to someplace in the middle of the binary that is nothing to do with the printf. I would like to ask, if anyone have ti, for some papers about nasm. I know the nasm documentation, but a more pratical (with examples) would be better. Thanks! My code:https://pastebin.com/PYwadQiW Compilation steps: nasm -fobj ./main.asm alink -oPE -entry _start ./main.asm Thanks! Regards. Link to comment
kao Posted July 25, 2017 Share Posted July 25, 2017 You're missing square brackets around printf. http://forum.codecall.net/topic/65224-intro-to-win32-assembly-using-nasm-part-3/ Once you fix that, your program will crash. That's because you're f*ing up the stack. "add esp, 8" will fix that. Once you fix that, your program will appear to do nothing. That's because alink.exe creates Windows GUI program by default. "-subsys con" will fix that. Or you can just use some other assembler which has proper documentation, examples and help. masm32 and fasm comes to mind.. 3 Link to comment
Nemo Posted July 25, 2017 Share Posted July 25, 2017 Actually nice to see someone who wants to learn machine code.. here's a nice place for some masm32 learning.. https://win32assembly.programminghorizon.com/tutorials.html 1 Link to comment
opc0d3 Posted July 26, 2017 Author Share Posted July 26, 2017 19 hours ago, kao said: You're missing square brackets around printf. http://forum.codecall.net/topic/65224-intro-to-win32-assembly-using-nasm-part-3/ Once you fix that, your program will crash. That's because you're f*ing up the stack. "add esp, 8" will fix that. Once you fix that, your program will appear to do nothing. That's because alink.exe creates Windows GUI program by default. "-subsys con" will fix that. Or you can just use some other assembler which has proper documentation, examples and help. masm32 and fasm comes to mind.. Hey Kao! Thank you so much for your help. Indeed, printf is cdecl convention, then i have to clean the stack. Sorry about that. I didn't know that the alink compiles by default GUI. What is strange is that the string printed is vanished at the exit of the program, after RtlExitUserThread. There is anyway to get around this ? I tried ExitProcess, but still vanishing my printed string. Only way i could get around this is adding 8 to stack, moving the values onto it, call the printf, then call exit process. When I execute the compiled .exe on console the string printed remains. But i don't know if is it correct. 17 hours ago, Nemo said: Actually nice to see someone who wants to learn machine code.. here's a nice place for some masm32 learning.. https://win32assembly.programminghorizon.com/tutorials.html Hey, Nemo! Thanks for the site have a lot of content, very useful for what i'm studying now! Do you uses masm ? Have you tried nasm ? Which dou you prefer ? Link to comment
Nemo Posted July 26, 2017 Share Posted July 26, 2017 I use masm32, with WinAsm to make it easier to put it all together.. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now