Vous êtes sur la page 1sur 22

The Radasm IDE. Radasm is an Editor for MASM32, TASM, FASM, HLA,NASM and GOASM assembler syntax.

Update 29.01.2005: MASM32 version2 has been released. Ketil O. released Radasm 2.1.0.7. Since i wrote the tutorial his IDE became quite professionell. Full source-code for Radasm version 1.0 is now released for download. You can get it from here. Update 06.03.2003: Radasm is written by Ketil O. You can get the complete files from
his website. Links are on the left side. To use his Radasm Editor with MASM32 (like in this tutorial) you still need the Microsoft Macro Assembler for windows32 MASM32. You can get this from hutch`s page. Since microsoft stoped support he took care of it and brought us a basic editor and lots of tools and a complete library ready to use. Since i assume you prefer writing windows applications with a resource RADASM is the perfect choice. In the comming tutorials i ll try to get you started from the very basics.

The good news is RADASM is almost as good as the VB IDE. Radasm by Ketil O. lets you create your first windows application in 30 seconds, the bad news is you have to deal with the complete windows API and of course step by step assembler itself but i can promise you with the RADASM IDE its quite fun. I assume you already own a FREE copy of Radasm Ketil O. and have it unzipped somewhere on your harddrive. Installation is not required. If you (like me ) having MASM32 not installed on drive c:\ then you have to edit the MASM.ini File where [Paths] you enter the correct path. (in my case i had to change c:\ to d:\ ) To open Radasm project files with RADASM you have to right click a *.rap file and select open with Radasm (be sure to check always open with) . Once again: Radasm is not a compiler/linker, it s an editor for various assembler syntax` You need a FREE copy of the MASM32 package.. When installing be sure to have your antivirus turned off cause some parts might alarm it. See following link for more information December 2003 Hutch released Service Pak 1 for Masm v8. For some samples on this side you need this service pak. (Not for the tutorials) You can get this service pak and information about it at the Masm32 Forum.

While i am writing this Tutorial the current version of Radasm is 2.0.4.1. Please be sure to always grab the latest version cause Ketil O. is really hard working on it and improving it alot. He is still not finished and while you are reading this there is a new version out. I assume you already have some ideas about the windows API and/or the assembly language.If not its not that bad cause we are starting right from the beginning. There is also a helpfile available for the RADASM IDE that helps you understand Radasm`s settings and its tons of addins. This file is available at the Radasm Website. When you start your Radasm IDE the first time you might find some colors very weird compared to Your VB IDE. The first thing i did (as a VB programmer ) I changed the color scheme. NOTE: All Screenshots are taken from my NT4.0 System. Radasm meanwhiles supports XP Style so if you are using XP your IDE will look different.

From the Radasm IDE menu click &Options then click &Colors and Keywords. You see this Dialog:

This &Option menu where you changed some colors you can change editor font, helpmenus and almost everything you need. You can also change the gridsize in your dialog editor, so it looks as the VB Dialog editor. See &Dialog Editor Options. None of all those changes are needed, we can start right away with our 1st application written in pure assembler and you should be finished in 30 seconds: FIRST STEP First click &File and then &New Project or just hit SHIFT+Ctrl+N.

You will see this dialog:

Leave the radio buttons and the combobox alone right now. All you have to do is enter a program title (first textbox), then add a description for your application (second textbox). The path where Radasm will save the wizard created files and folders (third textbox). As our template our choice will be DialogApp.tpl (fourth textbox)

Click next, next and finish. Radasm created some (actually alot) of files for you and even two folders (the \res and the \bak folder) The main files you can see now in your project window. Under this project window you have the property window.

Your Radasm project window should now look like this:

Now it s time to take a look at your Radasm toolbar. You should find a button called "go" (tooltip)

Click it to link your creation. If you did everything correct, you should see then your first window popping up. In pure assembler, without writing one line of code. Thats really RAD (rapid application developement).

Now we have one empty ugly window. Without going to look at assembler code or windows API itself you can already do lots of modifications to this window thanks to this great Radasm editor. Go ahead and open the dialog editor. It s just like in VB. Except for some lill differences, but you will find them out soon, they dont matter anyway. To open it simple double click the Window.dlg in your project window. You can place buttons, textboxes, shapes on your form and as soon you hit Go! again your changed window will appear with your controls on it. Of course they dont have any functions yet, and they are not even initilized (like in VB) We do this in our second tutorial. Note: If you place some CommonControls (example Richedit or DateTimePicker) to your dialog, your program might wont appear anymore if you Hit Go! Even if Radasm doesnt give you any errors while linking. We will deal with this later (Tutorial #5), dont worry, everything is o.k. You can change the dialogs caption and style, try to make it topmost You do all this in the property dialog of your window. Experiment a lill with the changes you can do. It s quite alot.

SECOND STEP Our first task will be putting a pretty icon to our window. Look for an icon and copy it to your project \ res folder. (Remember: Radasm created a \res folder for you.) Radasm is doing lots of work again for us so just sit back and relax. First click &Project and then &Resource from the Radasm menu. You see a dialog like this appear:

Click Add buttton to add a new resource (our icon) to our Project. We call this Icon IDC_ICON and give it the ID 500. Now click the path button and look for the icon you copied into Your \res folder. Choose this icon and click &open. You should have a result like this. You can click OK to exit the resource dialog.

Now we have to insert some code. But dont worry it s not much. In your project browser you see the files Windows.asm and Windows.inc We need to add a few lines to the first one and 1 single line to the second. First the Windows.inc file. Double click it to open it. You should see something like this

We have to add a memory reservation for our icon, we call this variable hIcon, it s stored at the unintialised datasection called .data ? so go ahead and type: hIcon dd ? ;dd means declare dword, the question mark is cause we cant tell it s size. Now your Windows.inc looks like this:

Now double-click your Windows.asm file

Now we add 3 lines to our code, to get the icon actually showing on our window. Just like in Visual Basics FORM LOAD in Windows API we use WM_INITDIALOG Here is where we have to write our lines:

[code] invoke LoadIcon,hInstance,500 ;our first Win API loading icon to our created window mov hIcon,eax ;the result loaded is stored in the eax register, our first OPCODE mov puts it into the hIcon variable. invoke SendMessage,hWin,WM_SETICON,NULL,hIcon ;our second WIN API sets the loaded icon to our dialog

[/code]
Looks like this:

Hit Go once more to see the result (Radasm autosaves your project as soon you link) If you did any typos (hope not ) Radasm will give you errormessages in the output window at the bottom: Simple doubleclick to jump the line. Radasm highlights the line where it finds an error. NOTE: Unlike Visual Basic here we are CASE SENSITIV. If you ve done all correct, take a look at your first created assembler standalone .exe file. It s just 5kb big. (without icon propably just 2kb) This is really impossible to do in VB. Ok now that we have created our first working window, how about putting some controls To our lill dialog. Note: textboxes are called editboxes and labels are calles statics from now on like in MS VC++ In this tutorial we will transfer following Visual Basic into Windows API / Assembler If Text1.Text <> VBNullstring then Text2.Text = Text1.Text else Msgbox "You didnt enter any text!", vbinformation End if Easy right ? Yeah cause the compiler is doing all the dirty Windows API work for you. This wont happen in C/C++ and for sure not in ASM. And we going to look into some other simple stuff to aswell. Lets get going.

Create a new project, and use this time DialogAsMain.tpl as a template. Project name will be Editbox. This new template is already an almost complete application with everything you need. All you need is to place your controls and write the code for them, the rest is done by the Editor. As a free bonus you already get a dropdown menu &Exit and &About.

Place 2 editboxes to your dialog, some statics (if you want) and 4 (Command-) Buttons. Name the two editboxes Text1 and Text2. If you want you can set Text2 Locked to TRUE. Name the four buttons Command1 Command2 and Command3 Command4 from left to right. Name the Dialog and the Buttons as seen on the picture below. To make the menu visible Radasm created for you, please take a look at the Dialog properties.

Click the menu button and from the open dialog choose the Editbox.mnu file. Voil you can see the menu on your from.

Also choose a nice icon for your program and store it in your \res folder Dont forget to include it with the resource dialog. ( Remember ? Tutorial 1 ) Click Go for testing, you should have something like this. NOTE: For example you place a STATIC on your dialog and add following text to your static: >> Press "enter" to continue. << When trying to assemble&link you will get an error, thats because you have to DOUBLE "" the quotes each time you use them on a static, the same is for the EDITBOX caption.

Once again Radasm is doing lots of work for us, check your \res folder and open the Editboxdlg.rc file. You see something like this: #define Text1 1001 #define Text2 1002 #define Command1 1003 #define Command2 1004 #define Command3 1005 #define Command4 1006 MyDialog DIALOGEX 6,6,199,109 CAPTION "Editbox sample" FONT 8,"MS Sans Serif" CLASS "DLGCLASS" STYLE 0x10CF0800 EXSTYLE 0x00000000 BEGIN CONTROL "",Text1,"Edit",0x50010000,12,11,120,11,0x00000200 CONTROL "",Text2,"Edit",0x50010000,12,25,120,11,0x00000200 CONTROL "&Text",Command1,"Button",0x50010000,4,48,40,15,0x00000000 CONTROL "&About",Command2,"Button",0x50010000,52,48,40,15,0x00000000 CONTROL "&Exit",Command3,"Button",0x50010000,100,48,40,15,0x00000000 CONTROL "&Macro",Command4,"Button",0x50010000,4,77,40,15,0x00000000 END Please dont edit any of these, just look at them. (the dialog editor will overwrite any changes.) I want to show you how Radasm makes your programming life easier. If you would use just Hutch`s Qeditor or MSVC++ without MFC you would have to manually type everything up there each time you change something on your dialog. We continue with our example: The defining of editboxes and buttons is done, now we have to give them unique ID`s.

Open your Editbox.inc file. Everything grey is what you should have already in your own file, whats read is what you should Insert.

include windows.inc include user32.inc include kernel32.inc include shell32.inc include comctl32.inc include comdlg32.inc

includelib user32.lib includelib kernel32.lib includelib shell32.lib includelib comctl32.lib includelib comdlg32.lib

WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD ;MACROS for our &Macro button, we re going to use our first MACRO here

literal MACRO quoted_text:VARARG LOCAL local_text .data local_text db quoted_text,0 .code EXITM <local_text> ENDM

SADD MACRO quoted_text:VARARG EXITM <ADDR literal(quoted_text)> ENDM .const IDM_FILE_EXIT equ 10001 IDM_HELP_ABOUT equ 10101

Text1 equ 1001 ;our ID Manager for the editboxes and the buttonsText2 equ 1002 Command1 equ 1003 Command2 equ 1004 Command3 equ 1005 Command4 equ 1006 .data ClassName db 'DLGCLASS',0 MenuName db 'MyMenu',0 DlgName db 'MyDialog',0 AppName db 'Dialog as main',0 AboutMsg db 'MASM32 RadASM Dialog as main',13,10,'Copyright MASM32 2001',0 Warning db 'You didnt type any text',0 ;declare byte Text ,0 zero terminated, a global variable string Copyright db 'This is my software',0 .data? hInstance dd ? CommandLine dd ? hWnd dd ?

hIcon dd ? ;Memory needed for Icons and our 2 editboxeshEdit1 dd ? hEdit2 dd ? ;Memory needed for Icons and our 2 editboxeshEdit1 dd ? hEdit2 dd ? You can close your Editbox.inc file now. Double click Editbox.asm. Code thats already there is in grey, what you still have to add is in red. .386 .model flat,stdcall option casemap:none include Editbox.inc

.code start: invoke GetModuleHandle,NULL mov hInstance,eax invoke GetCommandLine invoke InitCommonControls invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT invoke ExitProcess,eax

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD LOCAL wc:WNDCLASSEX LOCAL msg:MSG

mov wc.cbSize,SIZEOF WNDCLASSEX mov wc.style,CS_HREDRAW or CS_VREDRAW mov wc.lpfnWndProc,OFFSET WndProc mov wc.cbClsExtra,NULL mov wc.cbWndExtra,DLGWINDOWEXTRA push hInst pop wc.hInstance mov wc.hbrBackground,COLOR_BTNFACE+1 mov wc.lpszMenuName,OFFSET MenuName mov wc.lpszClassName,OFFSET ClassName invoke LoadIcon,NULL,500 ;NEW Load your icon here mov wc.hIcon,eax mov wc.hIconSm,eax invoke LoadCursor,NULL,IDC_ARROW mov wc.hCursor,eax invoke RegisterClassEx,addr wc invoke CreateDialogParam,hInstance,addr DlgName,NULL,addr WndProc,NULL invoke ShowWindow,hWnd,SW_SHOWNORMAL invoke UpdateWindow,hWnd .while TRUE invoke GetMessage,addr msg,NULL,0,0 .BREAK .if !eax invoke TranslateMessage,addr msg invoke DispatchMessage,addr msg .endw mov eax,msg.wParam ret WinMain endp

WndProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM LOCAL buffer[128]:BYTE ;Dim buffer as string

mov eax,uMsg .if eax==WM_INITDIALOG push hWin pop hWnd invoke LoadIcon,hInstance,500 mov hIcon,eax invoke SendMessage,hWin,WM_SETICON,NULL,hIcon ; initialising our 2 editboxes invoke GetDlgItem,hWin,1001 ;Windows API result gets stored in eax mov hEdit1,eax ;assembler OPCODE stored flag flag from eax moved to hEdit1 invoke SetFocus,hEdit1 ;Windows API invoke GetDlgItem,hWin,1002 mov hEdit2,eax .elseif eax==WM_COMMAND mov eax,wParam and eax,0FFFFh .if eax==IDM_FILE_EXIT invoke SendMessage,hWin,WM_CLOSE,0,0 .elseif eax==IDM_HELP_ABOUT invoke ShellAbout,hWin,addr AppName,addr AboutMsg,hIcon ;EDIT NULL into hIcon .elseif eax==Command1 ;first we check if the user has inserted any text ;if so we copy it to the second textbox invoke GetWindowTextLength,hEdit1 ;Win API result gets stored in the eax register cmp eax,0 ;Assembler OPCODE to compare je @F ;Jump if equal to @@: thats like a GOTO in VB ;ok here we get only if user has typed some text invoke SendMessage,hEdit1,WM_GETTEXT,sizeof buffer,addr buffer ;our local variable SendMessage,hEdit2,WM_SETTEXT,0,addr buffer ;the stored string in eax gets copied to editbox 2 jmp Exit ;Assembler OPCDOE jmp means jump now to (Exit) @@: ;here is where we came from je @F (User didnt enter any text) invoke MessageBox,hWin,offset Warning,offset AppName,MB_ICONERROR .elseif eax==Command2 invoke MessageBox,hWin,offset AppName,offset Copyright,MB_OK ;Win API for a messagebox

elseif eax==Command3 invoke SendMessage,hWin,WM_CLOSE,0,0 ;Windows API: Unload me. elseif eax==Command4 ;MACRO invoke MessageBox,hWin,SADD("Hello, this is a test"),SADD("Messagebox caption"),MB_ICONINFORMATION Exit: ;We exit the Messageloop here .endif ; .elseif eax==WM_SIZE .elseif eax==WM_CLOSE invoke DestroyWindow,hWin .elseif uMsg==WM_DESTROY invoke PostQuitMessage,NULL .else invoke DefWindowProc,hWin,uMsg,wParam,lParam ret .endif xor eax,eax ret WndProc endp

end start

When you are done, hit go. You get something like this:

We are done.
You can get the example code here. Under &Project click &VersionInfo You get following dialog:

Here is where you can enter Project Major Project Minor and Revision, also as your author notes and application title. Now click &Project and then &VersionControl You get this dialog. This is a RADASM ADDIN. There are lots and lots of them in Radasm, the documentations please read from the Radasm help file written by Donkey. You get this helpfile from the Radasm website.

My favorite RADASM ADDINS are ASMVARS and PROJECT ZIPPER.AsmVars is checking your files for UNUSED variables. The results are displayed in the bottom output window. Double click The found ones and RADASM will lead you to the already highlighted line. You can delete the variable safely.

If you are using the MZ tools for your VB you should know this function. Project zipper does what you think: zipping a project winzip compatible.

Vous aimerez peut-être aussi