Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8644969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:25:47+00:00 2026-06-12T12:25:47+00:00

With online help, I was able to write nasm code in Mac OS X

  • 0

With online help, I was able to write nasm code in Mac OS X resulting in an executable that prints its own filename, argv[0] in equivalent C code. When I use the same code in Windows, I want it to print the programs name:

C:\> nasm -f win32 -o scriptname.obj scriptname.asm
C:\> golink /fo scriptname.exe scriptname.obj /console kernel32.dll Msvcrt.dll

GoLink.Exe Version 0.27.0.0 - Copyright Jeremy Gordon 2002/12 - JG@JGnet.co.uk
Output file: scriptname.exe
Format: win32 size: 2,048 bytes
C:\> scriptname.exe
Program: scriptname.exe

But what it actually prints is emptiness:

C:\> scriptname.exe
Program: 

Specs:

  • golink 0.27.0.0
  • nasm 2.10.05
  • Windows 7 Professional x64
  • MacBook Pro 2009
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:25:48+00:00Added an answer on June 12, 2026 at 12:25 pm

    You call GetStdHandle and save the returned value to ecx, ecx is a volatile register, the value will not be saved across calls unless you push/pop it. Your first call to WriteConsoleA uses it and clobbers it so the next call, ecx is not what you expect.

    * EDIT *
    I was bored so here is working code:

    [bits 32]
    
    section .data
    
    program db "Program: ", 0
    programlen equ $-program
    
    nl db "", 13, 10, 0
    nllen equ $-nl
    
    section .bss
    
    buf resd 1
    argc resd 1
    argv resb 255
    
    section .text
    
    global Start
    extern GetStdHandle
    extern __getmainargs
    extern WriteConsoleA
    extern ExitProcess
    
    strlen:             ; eax: a string ending in 0
    push eax            ; cache eax
    
    .strloop:
    
    mov bl, byte [eax]
    cmp bl, 0
    je .strret          ; return len if bl == 0
    inc eax             ; else eax++
    jmp .strloop
    
    .strret:
    
    pop ebx             ; ebx = cached eax
    sub eax, ebx        ; eax -= ebx
    ret                 ; eax = len
    
    Start:
    
    push 0
    push buf
    push argv
    push argc
    call __getmainargs
    add esp, 16         ; clear stack (4 * 4 arguments)
    
    push -11            ; get stdout
    call GetStdHandle
    mov esi, eax
    add esp, 4          ; clear stack (4 * 1 argument)
    
    push 0              ; null
    push buf            ; [chars written]
    push programlen
    push program
    push esi            ; stdout
    call WriteConsoleA
    add esp, 20         ; clear stack (4 * 5 arguments)
    
    mov edx, [argv]
    mov eax, [edx]   ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    call strlen
    push 0              ; null
    push buf            ; [chars written]
    push eax            ; len argv[0]
    push dword [edx]    ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<       ; argv[0]
    push esi            ; stdout
    call WriteConsoleA
    add esp, 20         ; clear stack (4 * 5 arguments)
    
    push 0              ; null
    push buf            ; [chars written]
    push nllen
    push nl
    push esi            ; stdout
    call WriteConsoleA
    add esp, 20         ; clear stack (4 * 5 arguments)
    
    push 0
    call ExitProcess
    
    
    D:\NASM Projects\ReadArgs>ReadArgs.exe
    Program:  ReadArgs.exe
    
    D:\NASM Projects\ReadArgs>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm hoping you'll be able to help me. The site is currently online and
I try to write some code on Python2.7 , which will able to implement
We currently have a java/jsp online web service that includes it's own custom calendar.
I'm trying to build a program that will be able to read and write
I need to implement Online Help in my Java Web Project. For Example User
In our application, we would like to make a link to an online help
I was expecting the below scenario common, but couldn't find much help online. I
I need help rewriting online.php to -> /users/online and profile.php?id=3426 to -> /users/3426 and
In the online manual of Vim, :help DiffOrig will show the recommended command sequence
After searching online and reading the Oracle documentation for this, I need some help

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.