1 Replies - 1146 Views - Last Post: 13 September 2012 - 08:00 AM

#1 krosty4782  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 12-June 11

Printing hello world in console with nasm win alink

Posted 13 September 2012 - 06:58 AM

Hello im trying to print hello in the console.
The program compile and links fine, but when i open it, it doesn't show anything in cmd.

[extern ExitProcess]
[extern GetStdHandle]
[extern WriteFile]
[segment .data]
[global main]
main:
push dword -11
call GetStdHandle ; Get stdout, it leaves the handle in EAX
mov [stdout_handle], eax ; Save the handle
push dword 0
push dword octets_written ; This will be written to
push dword msg_len ; How many characters to write
push dword msg ; The Message
push dword stdout_handle ; Finally the handle
call WriteFile ; Write message
call ExitProcess

[segment .data]
; This will be filled with the handle to stdout
stdout_handle: dd 0 
octets_written: dd 0 ; This gets filled with up by a function
msg: db "Hello", 0 ; This is the Message String
msg_len: equ 5 ; The length of the message


To compile i do:
nasm -fwin32 hello.exe
alink -oPE -subsys console hello.obj win32.lib -entry main

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Printing hello world in console with nasm win alink

#2 krosty4782  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 12-June 11

Re: Printing hello world in console with nasm win alink

Posted 13 September 2012 - 08:00 AM

I have debugged the code, and the problem was here:
mov [stdout_handle], eax
stdout_handle never gets the value of eax, so i've changed it for this:
lea stdout_handle, eax and now works fine.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1