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

  • Home
  • SEARCH
  • 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 8020543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:43:18+00:00 2026-06-04T21:43:18+00:00

I would like to write simple programs (console input/output) for Windows using x86 assembly,

  • 0

I would like to write simple programs (console input/output) for Windows using x86 assembly, mainly because I am just curious. It would be great if anybody could point me in the right direction. I already have a fairly good understanding of some of the more simple x86 instructions, the functions of the registers, etc. but it remains a mystery to me how programs interface with the operating system and use standard input and output. I know that these things have to do with libraries such as advapi32.dll and kernel32.dll, and that there are associated static library .lib files which enable compilers to use these dynamically linked libraries, but other than that I have little idea how this happens. I’m even fuzzy on how header files in languages like C use .lib files.

  • 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-04T21:43:20+00:00Added an answer on June 4, 2026 at 9:43 pm

    Perhaps it’s easiest to give directions for building some simple programs, and let you extrapolate from there. First you need some source code:

    .386
    .MODEL flat, stdcall
    
    ; This is what would come from a header -- a declaration of a the Windows function:
    MessageBoxA PROTO near32 stdcall, window:dword, text:near32,
            windowtitle:near32, style:dword
    
    .stack 8192
    
    .data
    message db "Hello World!", 0
    windowtitle   db "Win32 Hello World.", 0
    
    .code
    main proc
            invoke MessageBoxA, 0, near32 ptr message, near32 ptr windowtitle, 0
            ret
    main endp
            end main
    

    To build that, we’d invoke masm like:

    ml hello32.asm -link -subsystem:windows user32.lib
    

    That’s telling it the file to assemble, and when it links, telling it to link it as being for the Windows subsystem (the primary alternative would be -subsystem:console) and to link with user32.lib. The latter provides the definition of MessageBoxA for us.

    A similar program that writes to the console is (oddly enough) a tiny bit more complex:

    .386
    .MODEL flat, stdcall
    
    getstdout = -11
    
    WriteFile PROTO NEAR32 stdcall, \
            handle:dword,           \
            buffer:ptr byte,        \
            bytes:dword,            \
            written: ptr dword,     \
            overlapped: ptr byte
    
    GetStdHandle PROTO NEAR32, device:dword
    
    ExitProcess PROTO NEAR32, exitcode:dword
    
    .data
    message db "Hello World!", 13, 10
    msg_size dd $ - offset message
    
    .data?
    written  dd ?
    
    .code
    main proc   
        invoke GetStdHandle, getstdout
    
        invoke WriteFile,                   \
               eax,                         \
               offset message,              \
               msg_size,                    \
               offset written,              \
               0
    
        invoke ExitProcess, 0
    main endp
            end main
    

    Building is pretty much the same, except that this uses the console, so we specify the console subsystem, and the functions we’re using are defined in the kernel:

    ml hello_console.asm -link -subsystem:console kernel32.lib
    

    A header would include the equivalent of the declarations I’ve given above for MessageBoxA, GetStdHandle, WriteFile, etc. Each header would normally have a lot more of them though — for example, all the functions in kernel32 might be in a single header.

    As far as libraries go, the mechanism involved is somewhat involved, but mostly irrelevant. To get the job done, you look at (for example) MSDN, and see what library says to link, and add that on your command line.

    The more complex explanation is that at least when you link against a static library, it simply finds any functions you’ve called, and puts a copy of each into your executable/DLL. If (like above) you’re using code that’s in a DLL, it basically just puts a record into the executable that tells what function in what DLL it depends upon. Then, when you load/run the program, the loader looks for all the DLLs your program depends upon, and loads them (recursively loading anything they depend upon as well, of course). Then the loader fixes up those references, so the reference to the function in the DLL gets filled in with whatever address has been assigned to that function in that DLL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to write some simple Mario-like game from scratch using language C.
I would like to write a hql query using a dynamic instantiation with a
I would like to write a simple C++ program for Linux (Ubuntu) to control
I'm trying to write a simple high-low program that will output like this: $
I would like to write nested query with Doctrine; Sample SQL is like below:
I would like to write the radian units of the axes as proportional to
I would like to write the a startup script in bash to make an
I would like to write inside that code (pretty-config.xml): <pretty-config xmlns=http://ocpsoft.com/prettyfaces/3.3.2 xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://ocpsoft.com/prettyfaces/3.3.2 http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.3.2.xsd>
I would like to write a cross-platform function in C++ that contains system calls.
I would like to write an if statement that will do something base on

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.