none
The Hello World program in assembly language

    Question

  • Now that I have downloaded Visual Studio C++ Express, I have discovered that there is the ml utility which identifies itself as Microsoft (R) Macro Assembler.

    I am interested in developing assembly language programs using Visual Studio C++ Express compiler, linker or assembler.

    On the great Internet I got hold of this small program but it doesn't assemble correctly in ml. It doesn't work. How do I modify the assembly language below to make it comply with the current version of ml? I just want it to output Hello World at the VS 2008 Command Prompt:

    .MODEL SMALL
    .STACK 256

    .DATA
    outstring DB 'Hello World',13,10,'$'

    .CODE
    _start:
     mov ax,@data
     mov ds,ax
     
     mov ax,OFFSET outstring
     mov ah,9
     int 21h
     
     mov ah,4ch
     int 21h
     
    END _start   

    Can you point me in the right direction regarding interfacing assembly language programs to the Win32 platform? I need some resources on the Internet that teach how to make an Windows Forms App in assembly.

    Why I use assembly language is just a matter of taste. It is a challenge and I have all the time in the world because this is an activity performed in my spare time.

    Wednesday, October 01, 2008 8:56 PM

Answers

  • S. Verma said:

    Gunnar Vestergaard said:

    . . . how to make an Windows Forms App in assembly . . .


    I don't think this is possible.  Assembly is very low level.  Windows Forms is an architecture of the .NET Framework on top of the Common Language Runtime on top of Win32.



    I think he meant Win32 GUI, not Windows Forms.  Win32 GUI is definitely possible with assembler, but you can get almost as small and just as efficient using C or C++ and not using anything from the C runtime library.
    • Marked as answer by Yan-Fei Wei Tuesday, October 07, 2008 9:39 AM
    Thursday, October 02, 2008 7:20 PM
  • Gunnar Vestergaard said:

    Now that I have downloaded Visual Studio C++ Express, I have discovered that there is the ml utility which identifies itself as Microsoft (R) Macro Assembler.

    I am interested in developing assembly language programs using Visual Studio C++ Express compiler, linker or assembler.

    On the great Internet I got hold of this small program but it doesn't assemble correctly in ml. It doesn't work. How do I modify the assembly language below to make it comply with the current version of ml? I just want it to output Hello World at the VS 2008 Command Prompt:

    .MODEL SMALL
    .STACK 256

    .DATA
    outstring DB 'Hello World',13,10,'$'

    .CODE
    _start:
     mov ax,@data
     mov ds,ax
     
     mov ax,OFFSET outstring
     mov ah,9
     int 21h
     
     mov ah,4ch
     int 21h
     
    END _start   

    Can you point me in the right direction regarding interfacing assembly language programs to the Win32 platform? I need some resources on the Internet that teach how to make an Windows Forms App in assembly.

    Why I use assembly language is just a matter of taste. It is a challenge and I have all the time in the world because this is an activity performed in my spare time.



    That code uses DOS system calls (int 21h).  In Windows, if you want to output ASCII text, you should use GetStdHandle and WriteFileA.
    • Marked as answer by Yan-Fei Wei Tuesday, October 07, 2008 9:36 AM
    Thursday, October 02, 2008 7:23 PM
  • That's ancient DOS era 16-bit assembly.  If ml.exe can actually still assembly that, link.exe would definitely be the show stopper.  You'll need to raid a museum to get the tools to get that going.  It's bound to be available somewhere.  But not in this forum.


    Hans Passant.
    Thursday, October 02, 2008 1:55 AM
    Moderator
  • Gunnar Vestergaard said:

    ... how to make an Windows Forms App in assembly. 

    ... I have all the time in the world because this is an activity performed in my spare time.



    Good thing. I think you will need all the time in the world. I wish you luck.
    • Edited by Brian Muth Thursday, October 02, 2008 1:59 AM shorten quote
    • Marked as answer by Yan-Fei Wei Tuesday, October 07, 2008 9:39 AM
    Thursday, October 02, 2008 1:58 AM

All replies

  • Gunnar Vestergaard said:

    . . . how to make an Windows Forms App in assembly . . .


    I don't think this is possible.  Assembly is very low level.  Windows Forms is an architecture of the .NET Framework on top of the Common Language Runtime on top of Win32.
    Wednesday, October 01, 2008 9:29 PM
  • That's ancient DOS era 16-bit assembly.  If ml.exe can actually still assembly that, link.exe would definitely be the show stopper.  You'll need to raid a museum to get the tools to get that going.  It's bound to be available somewhere.  But not in this forum.


    Hans Passant.
    Thursday, October 02, 2008 1:55 AM
    Moderator
  • Gunnar Vestergaard said:

    ... how to make an Windows Forms App in assembly. 

    ... I have all the time in the world because this is an activity performed in my spare time.



    Good thing. I think you will need all the time in the world. I wish you luck.
    • Edited by Brian Muth Thursday, October 02, 2008 1:59 AM shorten quote
    • Marked as answer by Yan-Fei Wei Tuesday, October 07, 2008 9:39 AM
    Thursday, October 02, 2008 1:58 AM
  • S. Verma said:

    Gunnar Vestergaard said:

    . . . how to make an Windows Forms App in assembly . . .


    I don't think this is possible.  Assembly is very low level.  Windows Forms is an architecture of the .NET Framework on top of the Common Language Runtime on top of Win32.



    I think he meant Win32 GUI, not Windows Forms.  Win32 GUI is definitely possible with assembler, but you can get almost as small and just as efficient using C or C++ and not using anything from the C runtime library.
    • Marked as answer by Yan-Fei Wei Tuesday, October 07, 2008 9:39 AM
    Thursday, October 02, 2008 7:20 PM
  • Gunnar Vestergaard said:

    Now that I have downloaded Visual Studio C++ Express, I have discovered that there is the ml utility which identifies itself as Microsoft (R) Macro Assembler.

    I am interested in developing assembly language programs using Visual Studio C++ Express compiler, linker or assembler.

    On the great Internet I got hold of this small program but it doesn't assemble correctly in ml. It doesn't work. How do I modify the assembly language below to make it comply with the current version of ml? I just want it to output Hello World at the VS 2008 Command Prompt:

    .MODEL SMALL
    .STACK 256

    .DATA
    outstring DB 'Hello World',13,10,'$'

    .CODE
    _start:
     mov ax,@data
     mov ds,ax
     
     mov ax,OFFSET outstring
     mov ah,9
     int 21h
     
     mov ah,4ch
     int 21h
     
    END _start   

    Can you point me in the right direction regarding interfacing assembly language programs to the Win32 platform? I need some resources on the Internet that teach how to make an Windows Forms App in assembly.

    Why I use assembly language is just a matter of taste. It is a challenge and I have all the time in the world because this is an activity performed in my spare time.



    That code uses DOS system calls (int 21h).  In Windows, if you want to output ASCII text, you should use GetStdHandle and WriteFileA.
    • Marked as answer by Yan-Fei Wei Tuesday, October 07, 2008 9:36 AM
    Thursday, October 02, 2008 7:23 PM
  • In the old days, when you were responding to a good message you quoted the entire message in your reply, so others would know to what you were responding:

    Now that I have downloaded Visual Studio C++ Express, I have discovered that there is the ml utility which identifies itself as Microsoft (R) Macro Assembler. 

    I am interested in developing assembly language programs using Visual Studio C++ Express compiler, linker or assembler.

    On the great Internet I got hold of this small program but it doesn't assemble correctly in ml. It doesn't work. How do I modify the assembly language below to make it comply with the current version of ml? I just want it to output Hello World at the VS 2008 Command Prompt:

    but instead, I will explain this code

    .MODEL SMALL

    tells the compiler how much memory to set aside for the code section of the program

    .STACK 256

    this line is for the program to set aside memory space.  This would have been all of the memory on an xp style computer.  For today's monsters, it is like 256/8192 or about 3% of the available memory.  This was before the processor worked for windows in a way to dynamically set aside as much memory as you could imagine via the harddrive.  This small amount of memory is now placed on the cpu cache.  This line would be ignored as the file tables use this much all the time.

    .DATA
    outstring 
    DB 'Hello World',13,10,'$'

    this is the data section.  the 13,10 is the ascii control character to make the line go down one and over all the way to the left.  the dollar sign is wrong it should be a zero to tell the processor it has reached the end of the data.  I am hoping that some programmer with their massive code section looks here.  As part of todays multithreaded enviroments, this section is often left to the os.  Bad move.  All of the data for all of the programs is stored in the same place ds.  That is short for data segment.  This is where your variables go.  By not managing this area you leave the option for windows to manage your data.  All of the data at some time or another is actually placed into memory (see ddr, ddr2, ddr3).  If you do not move the data from memory to hard drive and back from hard drive to memory, the os does it.


    .CODE

    This line tells the assembler what to do next.  For this program the first line of code is a label.  Old assembly used to have a start and end label.  This type of label is now standard with windows.  It is not necessary to have a start label.  You can have an ending label, but it is better to return a code (int64 - 64 bit; int32- 32 bit; int16- 16 bit .. int8 - 1 byte) so that you can run another program that gets initiallized from another program.  Error code 0 is best to exit with.

    _start:

    Procedure start label.  This tells the processor where to begin loading code from. This actual code would place the procedure on the stack and wait.

     mov ax,@data
     mov ds,ax

    This code places data segment into ax.  This is done to streamline the megolith of processing.  Making the data go on the screen is a process that many have tried to make better.  Look at it this way.  The screen is like 750X1020 pixels.  Each pixel has 2^64 different colors.  All of this is sent via wire.  This wire has a different voltage for each of the different combinations.  If you were drawing over and over and over again this would take along time.  There comes about the need for plasma and lcd screens.

    It would really be better to push ax, now as you are not usually just going to send DB 'Hello World',13,10,'$'; so few data to the screen.  

    mov ax,OFFSET outstring

    mov ah,9

    int 21h

    The above three codes: 1.) Place the data into the multipurpose register (reax,eax,ax,ah&al); 2.) Call dos procedure 9h -9 for short; 3.) Call the interrupt.  The interrupts is a fancy way of saying that all of the data is right, the correct procedural call is loaded (9), and we are ready for what is next.  The int 21h is a call the processor.  The actual code is on layers of very thin very small silicon-germanium transistors.  When this code is loaded into the processor it directs the data from the datasegment into the output buffer that is located in dos code # 9.

    After the call to place the data into an output, 


     mov ah,4ch
     int 21h
     This was the fancy way of saying that you are done with the data, the processor can get back to doing what it was doing.

    [Old version - mov, bx,0; cli; mov ax, bx; sto]

    END _start    

    Can you point me in the right direction regarding interfacing assembly language programs to the Win32 platform? I need some resources on the Internet that teach how to make an Windows Forms App in assembly. 

    Why I use assembly language is just a matter of taste. It is a challenge and I have all the time in the world because this is an activity performed in my spare time.

    Wednesday, October 01, 2008 8:56 PM

    On the great Internet I got hold of this small program but it doesn't assemble correctly in ml. It doesn't work. How do I modify the assembly language below to make it comply with the current version of ml? I just want it to output Hello World at the VS 2008 Command Prompt:

    This is a different question.  Question 1: how do I fix this code.  Question 2: How do I write an assembly program for today's windows.

    Hope fully my response to the first question will help you understand my response to the second question.

    If you understand what I said in the first question, then all you need to do is write code in whatever language you were using before assembly and just add features.

    If not, then read my short little lecture.  When you are writing windows programs, there are some penalties for using code that came from reverse engineering.  1.) code may be not as good as your own 2.) you can cause problems for yourself that a high level language could alleviate. 3.) using someone's code as your own is plagiarism and often results in monetary penalties.

    That being said, I will tell you how I write asm programs.  First I write all the code in c.  Then I step through with the debugger.  I look at how the code compiles and the result assembler file.  Windows, actually prefers this method and has for many years.

    Here is why.  Windows does all of the work for you.  They send out an sdk with every new version.  The old sdks, are essentially the old one with a new wrapper, time stamp, and hash-code.  This is essential.  To write a program for windows, you need to know about the window class.  Every version of window has this class.  When your computer boots, the last program call is to explorer.exe.  Explorer.exe checks a few things before it takes control of the cpu.  The basic window class, takes a pointer.  This pointer points to the windows directory.  Then it loads the first file it finds.  This is a dll.  The dll that it loads has all of the input and output methods that are available.

    You access these methods via a class instantiation.  To the computer this is saying put the data segment pointer to point to the data (the dll)  Then load the data as above.  Next, you push the function, with all the variables that it needs onto the stack.  Finally, the interrupt.  The only ones that I think I know are 4h and 5h.  The first 0 and 1 are the values it check.  


    Friday, September 01, 2017 7:58 PM