Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[NASM][Help] Simple printf. ALINK can't resolve the import

Featured Replies

Posted

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.

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..

 

 

 

  • Author
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 ?

I use masm32, with WinAsm to make it easier to put it all together.. :)

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.