Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty

    Hello World Disassembly

    Assembly Code:
    Code:
    .386
    .model flat, stdcall
    option casemap:none
    include \masm32\include\windows.inc
    include \masm32\include\kernel32.inc
    include \masm32\include\user32.inc
    includelib \masm32\lib\kernel32.lib
    includelib \masm32\lib\user32.lib
    .data
    HelloWorld db "Hello World!", 0
    .code
    start:
    invoke MessageBoxA, NULL, addr HelloWorld, addr HelloWorld, MB_OK
    invoke ExitProcess, 0
    end start
    .386 is the processor model. Which I think is for 32 bit processors. There's also this .486 one, but that's for 16 bit I think.

    I'm not sure what casemap does. I don't think I need to worry about it yet.

    What's interesting is in MessageBox I pass it the address of the string Hello World rather then then the actual string.

    end must have the label that serves as the entry point for the code.


    Disassembly:
    Code:
    00401000 >/$ 6A 00          PUSH 0                                   ; /Style = MB_OK|MB_APPLMODAL
    00401002  |. 68 00304000    PUSH hello.00403000                      ; |Title = "Hello World!"
    00401007  |. 68 00304000    PUSH hello.00403000                      ; |Text = "Hello World!"
    0040100C  |. 6A 00          PUSH 0                                   ; |hOwner = NULL
    0040100E  |. E8 0D000000    CALL <JMP.&user32.MessageBoxA>           ; \MessageBoxA
    00401013  |. 6A 00          PUSH 0                                   ; /ExitCode = 0
    00401015  \. E8 00000000    CALL <JMP.&kernel32.ExitProcess>         ; \ExitProcess
    0040101A   .-FF25 00204000  JMP DWORD PTR DS:[<&kernel32.ExitProcess>;  kernel32.ExitProcess
    00401020   $-FF25 08204000  JMP DWORD PTR DS:[<&user32.MessageBoxA>] ;  user32.MessageBoxA
    I think this PUSH hello.00403000 is the address of the string. It's pushed on the stack. which to be honest I don't get completely then messagebox is called.

    Not sure about the last two lines, but I'll find out in a bit.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  2. #2
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    Code:
    invoke MessageBoxA, NULL, addr HelloWorld, addr HelloWorld, MB_OK
    invoke ExitProcess, 0
    Code:
    00401000 >/$ 6A 00          PUSH 0                                   ; /Style = MB_OK|MB_APPLMODAL
    00401002  |. 68 00304000    PUSH hello.00403000                      ; |Title = "Hello World!"
    00401007  |. 68 00304000    PUSH hello.00403000                      ; |Text = "Hello World!"
    0040100C  |. 6A 00          PUSH 0                                   ; |hOwner = NULL
    0040100E  |. E8 0D000000    CALL <JMP.&user32.MessageBoxA>           ; \MessageBoxA
    00401013  |. 6A 00          PUSH 0                                   ; /ExitCode = 0
    00401015  \. E8 00000000    CALL <JMP.&kernel32.ExitProcess>         ; \ExitProcess
    0040101A   .-FF25 00204000  JMP DWORD PTR DS:[<&kernel32.ExitProcess>];  kernel32.ExitProcess
    00401020   $-FF25 08204000  JMP DWORD PTR DS:[<&user32.MessageBoxA>] ;  user32.MessageBoxA
    CALL <JMP.&kernel32.ExitProcess> = CALL JMP DWORD PTR DS:[<&kernel32.ExitProcess>]
    basicly you push the params onto the stack(reversed order), then call a jump to kernel32.ExitProcess

    Comprende?
    Ah we-a blaze the fyah, make it bun dem!

  3. The Following 3 Users Say Thank You to Hell_Demon For This Useful Post:

    B1ackAnge1 (01-18-2010),Void (01-18-2010),why06 (01-18-2010)

  4. #3
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Quote Originally Posted by Hell_Demon View Post
    basicly you push the params onto the stack(reversed order), then call a jump to kernel32.ExitProcess

    Comprende?
    Si, Muy Comprehende!

    The colors helped a lot too. especially since the function params are symmetrical it would be impossible to tell.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  5. #4
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    No habla espagnol!
    and make sure to ask BA if I was correct, been a long time ago since I used asm
    Ah we-a blaze the fyah, make it bun dem!

  6. #5
    B1ackAnge1's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Posts
    455
    Reputation
    74
    Thanks
    344
    My Mood
    Cynical
    Spot on HD Nice coloring.

    .386 means it's using the 386 instruction set, you could do 486 or 586 etc, which basically would limit you to running your app on those newer CPUs. Unless you're some hardcore ASM freak and KNOW those specific instructions .386 usually works for 99.999999% of projects

    Assuming you know about the flat memory model (basically how windows manages memory, and stdcall is the calling convection (which you just discovered how that passes stuff in 'reverse' order )

    casemap : none means your labels are basically case sensitive so Hello != hello etc

  7. The Following 3 Users Say Thank You to B1ackAnge1 For This Useful Post:

    Hell_Demon (01-19-2010),Void (01-18-2010),why06 (01-18-2010)

  8. #6
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Quote Originally Posted by B1ackAnge1 View Post
    Spot on HD Nice coloring.

    .386 means it's using the 386 instruction set, you could do 486 or 586 etc, which basically would limit you to running your app on those newer CPUs. Unless you're some hardcore ASM freak and KNOW those specific instructions .386 usually works for 99.999999% of projects

    Assuming you know about the flat memory model (basically how windows manages memory, and stdcall is the calling convection (which you just discovered how that passes stuff in 'reverse' order )

    casemap : none means your labels are basically case sensitive so Hello != hello etc


    Hey Thankyou. It's good to see you BA!

    Actually I found this out a lil while ago using Izechelions (think that's how its spelled) Masm32 tutorials. What I would really like to know is how call the Message box function without invoke, but by actually PUSHing parameters.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  9. #7
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    The parameters go in reverse order.

    Code:
    caption db "Caption",0
    text db "Text",0
    
    push MB_OK
    push offset caption
    push offset text
    push 0
    call MessageBox
    I think.

  10. #8
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    I'll try it now.
    If it works I'll thank you.
    If it doesn't work I'll thank you for trying.
    If it deletes my C: drive I'll have to hunt you down.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  11. #9
    Obama's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Location
    The Black house
    Posts
    22,195
    Reputation
    870
    Thanks
    6,076
    My Mood
    Cool
    I love this, great jobs guys , so beautiful everyone learning

  12. #10
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Hey it worked.

    Guess your off the hook David.

    Code:
    .386
    .model flat, stdcall
    option casemap:none
    include \masm32\include\windows.inc
    include \masm32\include\kernel32.inc
    include \masm32\include\user32.inc
    includelib \masm32\lib\kernel32.lib
    includelib \masm32\lib\user32.lib
    .data
    HelloWorld db "Hello World!", 0
    .code
    start:
    
    ;MessageBoxA
    push 0                  ;The button
    push offset HelloWorld    ;the Title
    push offset HelloWorld    ;text
    push 0                  ;hWnd passed NULL
    call MessageBoxA
    invoke ExitProcess, 0   ;simple invoke
    end start

    Quote Originally Posted by Obama View Post
    I love this, great jobs guys , so beautiful everyone learning
    Awww... Obama can't wait for us too make him a personal VIP. xD

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  13. #11
    B1ackAnge1's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Posts
    455
    Reputation
    74
    Thanks
    344
    My Mood
    Cynical
    pretty simple eh why?
    remember this thread? https://www.mpgh.net/forum/34-assembl...ld-anyone.html

  14. #12
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Quote Originally Posted by B1ackAnge1 View Post
    pretty simple eh why?
    remember this thread? https://www.mpgh.net/forum/34-assembl...ld-anyone.html
    Are you kidding me? That's the first thing I read. When I decided to learn MASM. I copied ur program. It really helped a lot btw. Anyway haven't seen you in a while. Anyway don't be a stranger, or I'm gonna have to hunt you down. D:

    Especially starting masm I need your old wisdom. :P

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

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

    Hell_Demon (01-19-2010),Void (01-18-2010)

  16. #13
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    oi BA:

    Quote Originally Posted by B1ackAnge1
    (ok hint : you'd see something more like this but without the nice readable variable names)
    Code:
    ...
    push MB_OK
    push offset HelloWorld
    push offset HelloWorld
    push NULL
    call MessageBoxA
    ...
    shouldn't push NULL and push MB_OK be swapped around? since its stdcall not cdecl?
    note: I don't use Masm or whatever, __asm is all I've used so far

    Code:
    .386
    .model flat, stdcall
    option casemap:none
    include \masm32\include\windows.inc
    include \masm32\include\kernel32.inc
    include \masm32\include\user32.inc
    includelib \masm32\lib\kernel32.lib
    includelib \masm32\lib\user32.lib
    .data
    HelloWorld db "Hello World!", 0
    .code
    start:
    invoke MessageBoxA, NULL, addr HelloWorld, addr HelloWorld, MB_OK
    invoke ExitProcess, 0
    end start
    would translate into(roughly)
    Code:
    push MB_OK
    push hello.00403000
    push hello.00403000
    push NULL
    call MessageBoxA
    and
    Code:
    .386
    .model flat, cdecl
    option casemap:none
    include \masm32\include\windows.inc
    include \masm32\include\kernel32.inc
    include \masm32\include\user32.inc
    includelib \masm32\lib\kernel32.lib
    includelib \masm32\lib\user32.lib
    .data
    HelloWorld db "Hello World!", 0
    .code
    start:
    invoke MessageBoxA, NULL, addr HelloWorld, addr HelloWorld, MB_OK
    invoke ExitProcess, 0
    end start
    would rougly translate into
    Code:
    push NULL
    push hello.00403000
    push hello.00403000
    push MB_OK
    call MessageBoxA

    cdecl adds them onto stack in the order you passed them in(so A(b,c) would be push b, push c, call A) while stdcall reverses them(so A(b,c) would be push c, push b, call A)
    Right?
    or is cdecl automaticly turned into stdcall(or the other way around) at compile time? how would decompilers know if it is cdecl or stdcall?

    Because when decompiling stuff with IDA Pro it says 'asuming cdecl by default', what if the function was stdcall? what effect would that have on the decompiler? o__O
    Ah we-a blaze the fyah, make it bun dem!

  17. #14
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Quote Originally Posted by Hell_Demon View Post
    oi BA:



    shouldn't push NULL and push MB_OK be swapped around? since its stdcall not cdecl?
    note: I don't use Masm or whatever, __asm is all I've used so far

    cdecl adds them onto stack in the order you passed them in(so A(b,c) would be push b, push c, call A) while stdcall reverses them(so A(b,c) would be push c, push b, call A)
    Right?
    or is cdecl automaticly turned into stdcall(or the other way around) at compile time? how would decompilers know if it is cdecl or stdcall?

    Because when decompiling stuff with IDA Pro it says 'asuming cdecl by default', what if the function was stdcall? what effect would that have on the decompiler? o__O
    I thought stdcall and cdecl were the same. anyway... what does it matter. It's symmetrical anyway... D:

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  18. #15
    B1ackAnge1's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Posts
    455
    Reputation
    74
    Thanks
    344
    My Mood
    Cynical
    For this sample it indeed doesn't matter because you have basicallyu
    0, string, string , 0

    But when coding in asm I always tend to use Stdcall
    so Function(A,B,C) would be
    push C
    Push B
    push A
    Call Function.

    The function itself would know in which order to pop from the stack, hence why a lot of times when dealing with DLLs etc in C++ you'd see 'Extern C' which is basically saying: the functions in the dll are expecting their data to be passes using stdcall

    stdcall != cdecl but that's too much typing righ tnow

  19. The Following User Says Thank You to B1ackAnge1 For This Useful Post:

    Void (01-20-2010)

Page 1 of 2 12 LastLast

Similar Threads

  1. [C++] Tutorial 2: Hello World
    By Schyler in forum C++/C Programming
    Replies: 12
    Last Post: 03-28-2010, 10:53 PM
  2. New o C++? Simple Hello world (Added a little extra)
    By headsup in forum C++/C Programming
    Replies: 10
    Last Post: 11-09-2009, 06:00 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