Results 1 to 1 of 1
  1. #1
    Shark23's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Location
    Kansas
    Posts
    424
    Reputation
    10
    Thanks
    55
    My Mood
    Cool

    32 Bit In-depth Hello World with Jumps

    Well some people say that using the invoke function and other macros are not ASM enough so lets make a hello world without them. We'll just use pushing instead.

    This is the first time we've had to use the push function. In assembly there is a memory stack. We will push information onto the stack to be read. Later we can pop the information back off the memory stack but we don't need to worry about popping quite yet. For this tutorial we're only going to push.

    If this is your first experience with assembly, please visit this tutorial for very in-depth explaining of the program beginning.

    Let's start out with our standard program.

    Code:
    .386
    .model flat, stdcall
    option casemap :none
    include \masm32\include\kernel32.inc 
    includelib \masm32\lib\kernel32.lib
    include \masm32\include\user32.inc 
    includelib \masm32\lib\user32.lib
    Now that we have that taken care of we're going to need to set up some values for the messagebox style, the handle window, the text, and the title.

    Code:
    mb_ok equ 0
    hWnd equ 0   
    .data
    MyTitle db "Jumps are Fun!",0
    MyText db "I hope you're learning!",0
    mb_ok equ 0 will give our messagebox the style 0 which is a standard messagebox having only an OK button.

    hWnd equ 0 will set the handle window. We don't have a window that loads the messagebox. Since we don't have a window we give it the value 0.

    You already know what is happening in the data section from my last tutorial.


    Now that we have that taken care of, we need to get to the actual program.

    Code:
    .code
    start:
    push mb_ok
    push offset MyTitle
    push offset MyText
    push hWnd
    call MessageBoxA
    call ExitProcess
    end start
    Well that's a pretty big chunk to wade through. Lets take it a step at a time now.

    We start out pushing mb_ok but before we get into that we need to understand the data stack.

    The data stack operates on a last on first off principle. This means that the last thing pushed onto the stack is the first thing popped off the stack. Think of it as a stack of plates. The last one you put onto the stack of plates is the first one you take off the stack. The memory stack works the same way.

    If you remember, our messagebox function goes like this:

    MessageBoxA(Handle Window, Text, Title, Style)

    Since we are pushing on the stack we have to work backwords so we will push in the opposite order:

    Style, Title, Text, Handle Window

    So first we need to push mb_ok which is the messagebox style onto the memory stack.

    After that we push the text. We have to use the offset command to push the text's position in memory. We can't push a whole string onto the stack.

    After we have the style and the text we push the offset or address of the title and finally the handle window which is none.

    Now that we have everything for our messagebox on the stack, we need to call the messagebox method. That's what we do with our call MessageBoxA command.

    Finally we call our ExitProcess method to end the program execution.

    Our final code is

    Code:
    .386
    .model flat, stdcall
    option casemap :none
    include \masm32\include\kernel32.inc 
    includelib \masm32\lib\kernel32.lib
    include \masm32\include\user32.inc 
    includelib \masm32\lib\user32.lib
    mb_ok equ 0
    hWnd equ 0   
    .data
    MyTitle db "Jumps are Fun!",0
    MyText db "I hope you're learning!",0
    .code
    start:
    push mb_ok
    push offset MyTitle
    push offset MyText
    push hWnd
    call MessageBoxA
    call ExitProcess
    end start

    Well, that's it for this tutorial. Hopefully you've learned something new or understood something old in a better way.

    Keep practicing and have fun!
    Assembly Programmer

  2. The Following 2 Users Say Thank You to Shark23 For This Useful Post:

    -Raz0r- (11-12-2010),shaiming (04-16-2012)

Similar Threads

  1. [Tutorial] Hello World with source
    By KiraSietta in forum C++/C Programming
    Replies: 9
    Last Post: 07-15-2011, 04:38 AM
  2. In-depth Hello World Tutorial
    By Shark23 in forum Assembly
    Replies: 4
    Last Post: 11-11-2010, 02:40 PM
  3. Hello World Anyone?
    By B1ackAnge1 in forum Assembly
    Replies: 11
    Last Post: 11-09-2009, 01:14 PM
  4. A closer look at Hello World App.
    By headsup in forum Java
    Replies: 5
    Last Post: 10-24-2009, 12:25 AM
  5. [C++]Hello World; Your first C++ Program
    By Mr. Bond in forum Programming Tutorials
    Replies: 3
    Last Post: 02-09-2009, 08:53 AM