An assembly programming guide (by Ralph (AWC)) Static Detection of Vulnerabilities in x86 Code Analysis of assembly code for security problems (by M.Cova V.Felmetsger G.Banks G.Vigna) The PC GAMES PROGRAMMERS ENCYCLOPEDIA 1.0 A collection of 85 asm programming documents (by various) Win32 Course in 35 Lessons Una guida con codice d'esempio per. General and Gameplay Programming; Win32 Assembly Part 5 Are you a mobile gamedev? Fill out a quick survey for a chance to win one of twenty $25 Amazon gift cards! What is your GameDev Story? Sign in to follow this. Win32 Assembly Part 5. General and Gameplay Programming. Randy Hyde’s Win32 Assembly Language Tutorials (Featuring HOWL) #1: Hello World Prerequisites: This tutorial set assumes that the reader is already familiar with assembly language program-ming and HLA programming in particular. If you are unfamiliar with assembly language pro. 'The Best Assembly Web Site on the Internet' Tutorials, programs, source code, links, and resources for Win32 assembly programming; including links to Microsofts MASM32 assembler and their SDK and DDK kits.
This is the article that I am sure all of you have been waiting ever so patiently for .. a complete series on the development of a game, in pure Assembly Language of all things. I know all of you are as excited about this article as I am, so I will try and keep this introduction brief. Instead of laying every single thing out to you in black and white, I will try and answer a few questions that are asked most often, and the details will appear as we progress[color='#C0C0C0'] ( I am making this up as I go you know )[/color].
What is this article about? This article is actually part of a seven article series on the development of a complete game, [color='#4169E1']SPACE-TRIS[/color], in 100% assembly language. We will be covering any aspect of game development that I can think of .. from design and code framework to graphics and sound. Who is this article for? This series is meant for anybody who wishes to learn something that they may not have known before. Since the game is a relatively simple Tetris clone it is great for the beginner. Also, given the fact that not many people are even aware that it is completely possible to write for Windows in assembly language, it is great for the more advanced developers out there too. What do I need? The only requirement is the ability to read. However, if you wish to assemble the source code, or participate in the challenge at the end of the article series, you need a copy of MASM 6.12+. You can download a package called MASM32 that will have everything that you need, and then some. Here is the link: http://www.pbq.com.au/home/hutch/. [size='5']Why Assembly Language? Many of you are probably wondering why anybody in their right mind would write in pure assembly language. Especially in the present, when optimizing compilers are the 'in' thing and everybody knows that VC++ is bug free, right? Okay I think I answered that argument .. but what about assembly language being hard to read, non-portable, and extremely difficult to learn. In the days of DOS these arguments were very valid ones. In Windows though, they are simply myths left over from the good old days of DOS. I might as well approach these one at a time. First, assembly language is hard to read. But for that matter so is C, or even VB. The readability results from the skill of the programmer and his/her thoroughness at commenting the code. This is especially true of C++. Which is easier to read: Assembly code which progress one step at a time[color='#008000'] ( e.g. move variable into a register, move a different variable into another register, multiply )[/color], or C++ code which can go through multiple layers of Virtual Functions that were inherited? No matter what language you are in, commenting is essential .. use it and you won't have any troubles reading source code. Remember just because you know what it means doesn't mean that everybody else does also. Second, the issue of portability. Granted assembly language is not portable to other platforms. There is a way around this, which allows you to write for any x86 platform, but that is way beyond the scope of this article series. A good 80-90% of the games written are for Windows. This means that the majority of your code is specific to DirectX or the Win32 API, therefore .. you won't be porting without a huge amount of work anyway. So, if you want a truly portable game, then don't bother with writing for DirectX at all .. go get a multi-platform development library. Finally, there comes the issue of Assembly Language being extremely difficult to learn. Although there is no real way for me to prove to you that it is easy, I can offer you the basics, in a few pages, which have helped many people, who never saw a line of assembly language before, learn it. Writing Windows assembly code, especially with MASM, is very easy. It is almost like writing some C code. Give it a chance and I am certain that you won't be disappointed. [size='5']Win32 ASM Basics If you are already familiar with assembly language in the windows platform, you may want to skip this section. For those of you who aren't, this may be a bit boring, but hang with it .. this is very important stuff. For this discussion I will presume that you are at least familiar with the x86 architecture. [size='3']MOV Example: MOV EAX, 30 [size='3'] ADD & SUB These two instructions perform addition and subtraction. Example: The examples simply add 30 to the EAX register and then subtract that value from the EBX register. [size='3'] MUL & DIV These two instructions perform multiplication and division. Example: MOV EAX, 10 Of course, there are many more instructions, but those should be enough to get you started. We will probably only be using a few others, but they fairly easy to figure out once you have seen the main ones. Now we need to deal with the calling convention. We will be using the Standard Call calling convention since that is what the Win32 API uses. What this means is that we push parameters onto the stack in right to left order, but we aren't responsible for the clearing the stack afterwards. Everything will be completely transparent to you however as we will be using the pseudo-op [color='#008000']INVOKE [/color]to make our calls. Next, there is the issue of calling Windows functions. In order to use invoke, you must have a function prototype. There is a program that comes with MASM32 which builds include files [color='#008000']( equivalent to header files in C ) [/color]out of the VC++ libraries. Then, you include the needed libraries in your code and you are free to make calls as you wish. You do have to build a special include file by hand for access to Win32 structures and constants. However, this too is included in the MASM32 package, and I have even put together a special one for game programmers which will be included in the source code and built upon as needed. The final thing that I need to inform you about is the high level syntax that MASM provides. These are constructs that allow you to create If-Then-Else and For loops in assembly with C-like expressions. They are easiest to show once we have some code to put in, therefore you won't see them until next time. But, they are there .. and they make life 100000 times easier than without them. That is really about all you need to know. The rest will come together as we take a look at the source code and such. So, now that we have that out of the way, we can work on designing the game and creating a code framework for it. [size='5']The Design Document Time for something a lot more fun .. designing the game. This is a process that is often neglected simply because people want to start writing code as soon as they have an idea. Although this approach can work for some people, it often does not. Or, if it does work, you end up re-coding a good portion of your game because of a simple oversight. So, we will cover exactly how to create a design document that you will be able to stick to, and will end up helping you with your game. First, you need to have an idea of what you want the game to be, and how you want the game play. In our case this is a simple Tetris clone so there isn't too much we need to cover in the way of game play and such. In many cases though, you will need to describe the game play as thoroughly as possible. This will help you see if your ideas are feasible, or if you are neglecting something. The easy part is finished, now we need to come up with as many details as we possibly can. Are we going to have a scoring system? Are we going to have load/save game options? How many levels are there? What happens at the end of a level? Is there an introductory screen? These are the kinds of questions that you should be asking yourself as you work on the design of the game. Another thing that may help you is to story board or flow chart the game on a piece of paper or your computer. This will allow you to see how the game is going to progress at each point. Once you have all of the details complete, it is time to start sketching the levels out. How do you want the screens to appear? What will the interfaces look like? This doesn't have to be precise just yet .. but it should give you a realistic idea of what the final versions will look like. I tend to break out my calculator and estimate positions at this point also. I have actually ran out of room while creating the menu screen before. This was my own fault for not calculating the largest size my text could be and it took a few hours to re-do everything. Don't make the same mistake, plan ahead. The final stage is just sort of a clean-up phase. I like to go back and make sure that everything is the way I want it to be. Take a few days break from your game beforehand. This will give you a fresh viewpoint when you come back to it later on. Often times, you will stare at the document for so long that something extraordinarily simple will be glanced over and not included in your plan -- for instance, how many points everything is worth and the maximum number of points they can get [color='#008000']( Not that I have ever found out halfway through the game that the player could obtain more points than the maximum score allowed for, or anything like that )[/color]. Whether you choose to use the process I have outlined, or one of your own making, it is imperative that you complete this step. I have never been one for wasted effort -- I do it right the first time if possible, and learn from my mistakes, as well as the mistakes of others. If this weren't necessary I wouldn't do it. So, do yourself a favor and complete a design document no matter how simple you think your game is. [size='5']Code Framework The final preparation step is something that I like to call code framework. This is where you lay out your blank source code modules and fill them with comments detailing the routines that will go into them and the basic idea behind how they operate. If you think you are perfect and have gotten every detail in your design document then you can probably skip this step. But, for those of you like me, who are cautious, then give this phase a whirl. It helps you see how all of the pieces will fit together and more importantly if something has been neglected or included that shouldn't have been. Here is an example of the framework that I am speaking about from SPACE-TRIS. You can see that nothing much goes into it .. just an overview of the module more or less. ;###########################################################################
[size='5']Until Next Time Well, this is the end of the first article. The good news is all of the dry boring stuff is behind us. The bad news is you won't get to see any code until I complete the next article. In the meantime I would suggest brushing up on your assembly language and maybe searching on the Internet for some references on Win32 assembly language. You can find links to a lot of Win32 ASM resources at my website: Http://www.fastsoftware.com. Researching more information isn't a must .. but for those of you that still think this might be difficult, I would suggest taking the time to do so. It isn't like you will be hindered by learning more. You may find another resource that helps you learn this stuff and that is ALWAYS a good thing. In the next article we will get a skeleton version of [color='#4169E1']SPACE-TRIS [/color]up and running along with coding our Direct Draw library functions. The goal is to get a bitmap up onto the screen and I think we can accomplish it next time. If everything goes as planned, you should see the work starting to pay off in a loading game screen. I know it doesn't sound like much .. but appreciate how slowly we are progressing before we get further along. Because once we have the basics down, we are going to pull out all of the stops and then you will be thankful we took the extra time to cover this stuff. So young grasshoppers, until next time .. happy coding.
Write Your First Application On Win32
What is Win32
:-) win32 is an plactform that like J2ME and J2SE means that it have it's memory model and have a architure and have those Applications programming interfaces to call to the operating system . Like the APIS in the java , the user mode Win32 program code cannot comminucate with the hardware componments directly , but the older 16 bit MS dos computer application software can do it .For an example if they need to paint a pixel on the screen then they can done it by two different ways . The F irst way is By using the DOS or BIOS calls that stored in the lower memory area . The DOS or BIOS calls are like APIs to the MS-Dos programs . The MS-Dos program put ts the system call id in a register like AH and puts other parameaters in the stack and the other registers and interrupt it . The interrupt vector table stores the address to the relavant procedure call . and that's how that was happen . The secon d method is by writing to the device registers and memory structures directly .For a example when a gam needs to place a bitmap in the screen it puts it directly to write it to the device rather than calling to the BIOS or MS-DOS system calls to draw it on the screen . But unlike the MS-DOS , 32-bit windows implements more security levels . Beacuse of morden processors are capable of doing many things in the hardware level , the operating systems that are implements on their architure are implementing those features . One of the special feature that we have to focus is that new 32 bit processors are implementing the executing modes . Modern processors are having at least 2 executing modes . In intel x86 architure processors , there are four execution modes . The root level of execution mode is the ring0 and the lowerst priviledge mode is called ring3 . There are intermeadiate levels like ring2 and ring1 but operating system typically does not use them to implement their security execution modes . (to make their operating system more simple and less bugs ).So what are you think about the win32 appications like Microsoft Excel ( comes with the office package by Microsoft ?). is an application program or not ? Yes brother that was an application program and it runs in the execution mode ring3 . That means it have less priviledges. But what about the device driver software that you installed to run your modem ? Ya that was an ring0 software componment in the win32 world . That means the win32 environment is devided into two main categories . They are win32 applications and win32 drivers . As your first application on win32 , I'm show you how to write your fist win32 application on ring3 . That means the application cannot call the hardware directly but through the API ( Application Programming Interface ) you can do whatever you need to perform as a application program .
The Memory Model In Win32
:-) The memory model in Win32 is somewhat linear than the old MS-DOS 16 bit memory model. However ,in MS-DOS you can use segments to segment and seperate your execution code , data , and stack . But in the 32 bit environment the segments are already there , but the segment value in a segment register simply means an start pointer to a datastructure or an code block rather than a starting page . The offset is simply added to the seg ment that's how segments are different in the win32 . Thus beacuse of that it's like to an memory model like in old msdos the small , that have used by the com files . However the techonlogy give this win32 to handdle more memory than 64KB memory segment . Now the size of the memory that can be accessed by a application program is 4GB . means 2^32 bytes of memory . WOW that's very interesting is'nt it ? But typically the truth is no computer program that uses the memory even up to 1GB . Beacuse of the partical limitations of the computing . Althrough the registers are 32 bit and can hold 32 bit pointers in them , so many application programs are sharing the sam memory , the phy sical memory limited to the 4GB , in the 32 bit world .Then the memory usage is more than 4GB . Yes most of time that is the truth , that's why windows keeps an paging file to page the memory form ram to the harddisk . That's a one of a reason that the things are not fast as you expect . In reallaty there are no even 32 bit computers what fulled with 4GB RAM cards . So then , Like an MS-Dos program , win32 programs are also having their segments . Yes there is an code segment and there is an stack segment and there is an also a data segment . Thre are segments like resource , that newcome to the win32 .However the things are grater if you know the assembly language programming for 16-bit MS DOS . However it doesn't matter . The 16-bit model is dead a long time ago . Nowdays that memory model is used for only in embedded devices shuch as cell phones , and POS (point of sale ) devices like these things .That means I cannot say that there is not worth to learn the x86 16 bit real mode assembly languae , Thus beacuse they are heavily industrial , the indistries shuch as programming Microcontrollers .For an example I found Z80 , like processor memory model in a morden day pannel bord that operates circuit brakers in a heavily techinical electrical subsystem . However in destop computing world that is'nt much worth . In the high end computing world the 32-bit environment is also a old one . Now I'm writing this note using the windows xp professional x64 bit Edition computer . But the operating system is still win32 backward compatiable , althrough it cannot supports the win16 environment . Means that you have to think again if you are interesting to start with the 16bit or go ahead with us with the knowledge of 32 or 64 bit computing . However I means 64 bit computing , I really still doesn't know very much in 64 bit assembly language .Still many programs are working in the 32bit mode either the operating system and it's kernel is in 64 bit mode .That means 32 bit assembly language is an good starting point to master , and come to the 64 bit world .
What did you want's to know before we I expalin the code
Oky you are going to write an application program in win32 Therefore , there are two types of win32 applications , [1] : Console Applications. [2] : GUI applications. The first type of application is like the applications like cmd.exe , if you doesn't know what is cmd.exe . Please press the windows logo key + R in the keyboard and type there cmd.exe and enter . The next type of application is GUI applications like the internet explore , notepad like these programs . The difference of the GUI form the console based application is that in GUI you have to use mostly the mouse rather than the keyboard . As a windows user I really hate the mouse .Beacuse the keyboard is more shourt cut than the mouse . However we are going to write an GUI application to the in win32 .
what is our program ?
As the first program in console we can say 'Hello World !' . But in GUI we can make an message box and say 'Hello World ! ' .it uses the MessageBoxA@16 API call , typically in windows API's are stored in a DLL file . In here it was stored in a uesr32.dll file .So we have to make an external connection to that API call . EXTERN MessageBox@16 That's how we did it . After that you can call that API in anywhere in your program .By the way when you linking you have to /defaultlib:c:masm32libuser32.dll ,like this . That is why , the external API's external information is inside that libarary file .Means the dynamic linking information is in that lib file and actually when the program runs . the call statement points to a somekind of procedure that really stored in the user32.dll not the user32.lib. when comes to dynamic linking , the lib file only contains the information about how to link the code to the external dll file , but not the real procedure code .By the way code also can hold in lib files , whe there is an external static procedure is there . But remember that API calls are typically a procudure that comes form a dll file that stored in your windowssystem32 directory.
So what about the @16 ? That's what I needs to come here .16 means that there are 16/4 = 4
dword parameaters in this call . means stack is filled with 16bytes when calling to the MessageBoxA .
However do you wondering what are the API calls ? Wonder about what are the parameaters that
i have push to the stack , first one is 0 , means MB_OK , second parameater is the offset to the text that we need to display its on the message box as a caption and the thirid parameater is the offset to the text that we are want to display on the message-box body. and the last parameater is the hInstance , that the instance handler of the calling code . I place it as 0 however . you can learn more about this MessageBoxA function call by the MSDN. just type the MessageBoxA in the search tag . What are the tools that I need? Basically you need these tools , A text editor : what about the notepad comes with windows A assembler and a linker A debugger : not optional A disassembler : not optional Any kind of 32-bit windows operating system , above windows 95 or itself.
As a text editor you can easily find the notepad.exe easily . However your paying for
it . isn't it . As an assembler you can use MASM 32bit edition or the TASM32.exe . Hoever MASM32 bit version can be freely download form the internet . As a debugger you can use the SoftIce if you have money to buy it . But I'm not just using soft ICE even . Beacuse its costly . However I'm using Ollydbg as a user mode debugger . As an desaassebler I'm using the IDA pro . You can download the IDA Pro a freeware version form the internet . you have to search for that . if you unable to search for that you can email me .As a operating system , trouble is'nt it , wow that's really wont be a problem anymore however . Thus beacuse you can find the above 5 tools in a one free iso image and you can burn the iso image into a CD-ROM using a software like NERO . However you have to find out that iso image in the internet and download it . You can find it at the virus group web site www.29a.net . you really have to search for it . If you unable to find it you can email me then .
That was an bootable CD that starts alike windows xpe operating system . However I don't
know that it was leagal but I know that you can use that . It not only provides you a operating system and a text editor . It provides the assemblers like masm , tasm and even nasm . As a debugger it provides Ollydbg , my faviourate debugger . And a Integradate development for assembly language programming . Another benefit of that CD is that you not need to install it or deploy it on your hardware. It's bootable CD like KNOPPIX . My faviourate LINUX .
OKY you got everything lets go now . Check Everyting that work properly
As a first setp you can open the cmd.exe . I mention how to open cmd.exe earlier .and make an appropriate directory for your assembly language source files and binary files . Then you have to set your paths to the MASM or TASM 's bin directory and windowssystem32 directory .A command like this will work if your operating system and masm32's directories are same as mine. set path=C:masm32bin;C:windowssystem32; :-) >>> The reason that set to the windows system32 directory is that the notepad.exe is there . Then your are going to write your first assembly language source file . The extension for the assembly language source file is still .asm . Like MS-DOS assembly . But remember that the assembly language extension is sometimes can have .S even specially in the LINUX GNU environments . For the GNU compilers the extendsion is .S . However our source file is named is HelloWin and Extension is .asm . do it in the cmd like I did . C:srcHelloWin> notepad HelloWin.asm The you are going to write the first assembly language program in the notepad
HelloWin.asm
.586 .model flat, stdcall
EXTERN MessageBoxA@16:NEAR
.data
szCaption db 'Hello World',0 szAppName db 'HelloWorld',0
.code
start: push 0 push offset szCaption push offset szAppName push 0 call MessageBoxA@16 ret
end start
Save it and back to the command prompt . then you have to assemble it use the following commands to assemble it . C:srcHelloWin> ml.exe /coff /c HelloWin.asm
and this to link it
c:srcHelloWin> link /subsystem:windows HelloWin.obj /defaultlib:C:masm32libuser32.lib
and run the program .
This causes an error message to pop up that this operation cannot be performed as well as other erros the wording of which I cannot recall now - effectively saying that the latest changes cannot be saved. Microsoft money plus sunset windows 7. I have tried running the.exe in comp mode (Win XP) and made the Money file, Backup file and LRD file writeable (i.e.
C:srcHelloWin> dir Volume in drive C has no label. Volume Serial Number is 7829-4529
Directory of H:assemblyHELLOWORLD
01/24/2002 11:48 PM . 01/24/2002 11:48 PM . 01/25/2002 12:07 AM 269 HelloWin.asm 01/25/2002 12:07 AM 500 HelloWin.obj <<-- this is the object file 01/25/2002 12:09 AM 2,560 HelloWin.exe <<-- this is the exe file that we need to run 4 File(s) 3,609 bytes 2 Dir(s) 821,002,240 bytes free Assembly Coding Tutorial
C:srcHelloWin> HelloWin.exe
Then as you can see
[X]= HelloWorld --------------------------
hello World
[OK] --------------------------
A message Box something like this will be popup on the screen.
yes you worte an application for win32 GUI . you may wonder what is the /SUBSYSTEM:windows means . That meas
that you are link the program as an win32 GUI program. Errors: Xbmc repository download. if you are having errors while compiling the program please read the source program again . Thik that the at first the worng is in your program , beacuse the tools are tested very long time . you can find some differences in my link command and your link command beacuse of that /defaultlib:c:masm32libuser32.lib is in your computer may be in F:masm32libuser32.lib .
USing TOOLS:
you never need to byhart that how to compile the program using masm or tasm beacuse the tool developer can change it . The only thing that you need is you have to read the documentation of the masm and tasm . whatever you are using .For an example if you need to get the command summary about the link command you can just type 'link' with nothing parameters . Sometimes it can be 'link /?' or 'link --help' or 'link -h' .Try all of these things . the switches shuch as --help and -h are mostly you can see in the nasm . thus beacuse nasm comes form the linux world . but don't use nasm in here. You can use masm32 or tasm in here. Note that you have to download the masm32 bit version . Look, in link.exe found in the masm32lib i really forgoten how to invoke the library file in the cmd line.Then I use the help and find a switch like /defaultlib: .Then I test it like /defaultlib:user32.lib , and that does not works , and then I tried /defaultlib:c:masm32libuser32.lib and that properly works .However its ups to you to read the documentation of the assembler /linker that you are using . Althrough if you don't like to read the documentation via the black-background white text screen you can find the doucmentation in a pdf file on the internet . GOOGLE it . or you can get the whole documentation into an txt file like this . Invoke this command in the command line .
c:srcHelloWin> link.exe /? > linkDocumentation.txt
and you can read it by using a text editor or HTML it ,and have a fun !
Is't yet not working the program ?
Oky you can email me : [email protected] Assembly Coding Language
--- By Sanzilla Jackcat
sorry about my english grammer rules . Thus beacuse there is no mathematical specification to english grammer rules yet .However please send me feedback . Mips Assembly Coding
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |