Starting from the simplest Win32 Assembler, helloworld

Source: Internet
Author: User
Starting from the simplest Win32 Assembler, helloworld

Write by nine days Yan Ling (jtianling) -- blog.csdn.net/vagrxie

Discuss newsgroups and documents

Since I started to get plug-ins, my personal goal has been very clear. I took this opportunity to re-learn Win32 compilation. I bought a book and started to learn about it because of the urgency of C ++ learning, I gave up... This is almost the same as the learning process of python in the past ..... Haha, life is really dramatic. After work, I learned Lua because of work needs, and then I regained my interest in the scripting language, the Learning urgency for C ++ is not that strong (after all, I can cope with my work completely. I have not been stuck in my work because of the C ++ syntax problem, the rest of the learning is the idea.) So I started to stick to "Python core programming", and recently I used python in my work, it's really dramatic ..... Now I want to disassemble it. Take the opportunity to learn how to compile it .... I found that I am more interested in the underlying things .... I don't know why, maybe it's because I learned hardware ...... Underlying things are close to hardware .... But how can I explain how to learn Lua and python? So there is still no way to explain the results .........

The example in the book is very simple. The source code is as follows:

. 486; Create 32 bit code
. ModelFlat,Stdcall; 32 bit Memory Model
OptionCasemap: none; case sensitive

IncludeWindows. inc
IncludeMasm32.inc
IncludeUser32.inc
IncludeKernel32.inc

IncludelibMasm32.lib
IncludelibUser32.lib
IncludelibKernel32.lib

. Data
SzcaptionDB"A MessageBox! ", 0
SztextDB"Hello, world! ", 0

. Code

Start:
InvokeMessageBox, null,OffsetSztext ,/
OffsetSzcaption, mb_ OK
InvokeExitprocess, null

EndStart

 

Then compile a makefile:

By the way, it is recommended to download all the nmake and vs files from Microsoft, but I don't know if it is fully compatible with GNU make. I only learned GNU make, and it doesn't seem like learning Microsoft's nmake syntax (it seems similar at first glance), so I used GNU make for Windows. Fortunately, I really have this stuff :)

Makefile:

1 basename = helloworld
2 EXE = helloworld.exe
3 OBJ = helloworld. OBJ
4 files = helloworld. ASM
5 $ (exe): $ (OBJ)
6 link/subsystem: Windows/map: $ (Basename). MAP/out: $ (exe) $ (OBJ)
7 $ (OBJ): $ (files)
8 ml/C/COFF/Zi $ (files)

 

This makefile is a bit complicated to write -_-! The example is simple .....

Then compile with the make command ..... This is because I use Vim... So everything is much simpler. In fact, if we use UE and editplus, it will not be bad. The more languages we come into contact, the more you want to have a omnipotent editor .... Of course, the omnipotent IDE is the best.

There is no problem in compiling and running. However, some people get into the water because I don't have to push myself to pass the parameters, and I am used to using Microsoft in C ++, I always don't feel practical. I want to see if Microsoft is doing something behind me in this program ...... (C-language programmers do not like C ++. One of the major reasons is that they think the compiler has done too much with them. They are not steadfast. In fact, let's look at it. Then we need to disassemble the C ++ program several times. It seems that it is not too difficult to understand what the C ++ compiler has done ...... But at least more than C language... After talking about a lot of useless words, I found that the useful information in my text is getting fewer and fewer, and it's all about us ...)

Back to the topic, I first looked at the generated EXE file and found that there were no more reasons. RDATA segment, although I didn't use it, so the program reaches 4 K (it seems that it is the minimum executable program size when the PE file is not modified normally ), disassemble the generated EXE file (can it be called Disassembly -_-!)

00401000>/$ 6a 00 push 0;/style = mb_ OK | mb_applmodal

00401002 |. 68 00304000 push 00403000; | Title = "A MessageBox! "

00401007 |. 68 0f304000 push 0040300f; | text = "Hello, world! "

0040100c |. 6a 00 push 0; | howner = NULL

0040100e |. E8 07000000 call <_ messageboxa F USER32: user32.dll>;/messageboxa

00401013 |. 6a 00 push 0;/exitcode = 0

00401015/. E8 06000000 call <_ exitprocess F Kernel32: kernel32.dll>;/exitprocess

0040101a> $-ff25 08204000 jmp dword ptr []; _ messageboxa @ 16 0040101a F USER32: user32.dll

00401020>.-ff25 00204000 jmp dword ptr []; _ exitprocess @ 4 00401020 F Kernel32: kernel32.dll

 

I can only say that there is nothing behind our program, and everything is just like our source code. This is what we need ..... It is better to compile this statement (this sentence can be ignored by users of other advanced languages)

 

 

 

 

Write by nine days Yan Ling (jtianling) -- blog.csdn.net/vagrxie

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.