· KLDP.org · KLDP.net · KLDP Wiki · KLDP BBS ·
IntroductionMASM32



#red ¹®¼­ ÀÛ¼º ¿ä·É: @¹®¼­ÀÛ¼º¿ä·É.hwp (28.5 KB)



1. Introduction to MASM32


1.1. Intro


Many remember assembler as a complex and tedious necessity when a high level language failed to deliver in terms of capacity or performance yet it has always been capable of writing full size applications in elegant and efficient ways.

MASM has the capacity to write proper modular code which becomes a necessity as a project becomes larger.

¸¹Àº »ç¶÷µéÀº ¾î¼Àºí·¯°¡ °í ¼öÁØ ÇÁ·Î±×·¡¹Ö ¾ð¾î°¡ ÆÄÀÏ »çÀÌÁî¿Í ¼º´É ¸é¿¡¼­ Á¦ ¿ªÇÒÀ» ÇÏÁö ¸øÇÒ ¶§ »ç¿ëÇÏ´Â º¹ÀâÇÏ°í µÚ¾ôÈù ÇʼöÇ° Á¤µµ·Î »ý°¢ÇÏ°ï ÇÑ´Ù. (ÇÏÁö¸¸) ¿©ÀüÈ÷ ÀÌ°ÍÀº ¿ì¾ÆÇÏ°í È¿°úÀûÀÎ ¹æ¹ýÀ¸·Î Ç® »çÀÌÁî ¾îÇø®ÄÉÀÌ¼Ç ÇÁ·Î±×·¡¹Ö¿¡ »ç¿ëµÇ¾îÁö°í ÀÖ´Ù.MASMÀº ÇÁ·ÎÁ§Æ®°¡ Ä¿Á®°¡´Â »óȲ¿¡¼­ Çʼö¿ä¼ÒÀÎ °íÀ¯ ´ÜÀ§ ÄÚµå(proper modular code) ÀÛ¼ºÀÌ °¡´ÉÇÏ´Ù.

¸¹Àº »ç¶÷µéÀÌ ¾î¼Àºí·¯¸¦ ÇÏÀÌ ·¹º§ ÇÁ·Î±×·¡¹Ö ¾ð¾î·Î ºÒ°¡´ÉÇÑ ÆÄÀÏ »çÀÌÁî¿Í ¼º´ÉÀ» ÇÊ¿ä·Î ÇÒ ¶§¸¸ »ç¿ëµÇ´Â ¾î·Æ°í Áö·çÇÏ°í ¾î¿ ¼ö ¾øÀÌ ½á¾ß ÇÏ´Â °ÍÀ¸·Î »ý°¢ÇÑ´Ù. ÇÏÁö¸¸ ¾î¼Àºí·¯´Â Æí¸®ÇÏ°í È¿°úÀûÀÎ ¹æ¹ýÀ¸·Î ¾îÇø®ÄÉÀÌ¼Ç ÇÁ·Î±×·¥ Àüü¸¦ ÇÁ·Î±×·¡¹ÖÇϱâ À§ÇØ »ç¿ëµÇ°í ÀÖ´Ù. MASMÀº ÇÁ·ÎÁ§Æ®°¡ Ä¿Áú ¶§ ÇʼöÀûÀÎ proper modular code (Àû´çÇÑ ´ÜÀ§·Î ¸ðµâÈ­ÇÑ ÄÚµå)¸¦ ÀÛ¼ºÇÒ ¼ö ÀÖµµ·Ï ÇØÁØ´Ù.
#blue ¾î¼Àºí·¯¶ó´Â Á־ ¹Ýº¹µÇ´õ¶óµµ ´Ù½Ã ½áÁÖ´Â °ÍÀÌ ÁÁ´Ù°í ÇÕ´Ï´Ù. #red ¿µ¾îÀÇ ½ÃÁ¦´Â Çѱۿ¡¼­ ¹«½ÃµÉ ¶§°¡ ¸¹½À´Ï´Ù. -- ±è±â¿À

Assembler has the freedom to write code ranging from the self imposed structural approach to unrestrained freestyle code, each having their respective advantages. Self imposed modular coding has the advantage of organization, particularly with larger projects where freestyle has its advantages in close range loop optimization code.

ÀÚ°¡ ±¸¼º¸ðµâ ÄÚµùÀº ƯÈ÷ (freestyleÀÇ)´ë±Ô¸ð ÇÁ·ÎÁ§Æ®¿¡¼­ Å« ·çÇÁ ³»¿¡¼­ÀÇ ÃÖÀûÈ­¿Í °°Àº ±¸Á¶ÀûÀÎ ÀÌÁ¡À» Á¦°øÇÑ´Ù.

¾î¼Àºí·¯´Â ½º½º·ÎÀÇ ±¸Á¶¸¦ ¹Ù²Ù´Â? ÇüÅÂÀÇ ÄÚµåºÎÅÍ Á¦ÇÑÀÌ ¾ø´Â ÀÚÀ¯·Î¿î ½ºÅ¸ÀÏÀÇ ÄÚµå±îÁö ´Ù¾çÇÑ Äڵ带 ÀÛ¼ºÇÒ ¼ö ÀÖ´Â ÀÚÀ¯·Î¿òÀ» °¡Áö°í ÀÖ´Ù. ÀÌ·¯ÇÑ ÄÚµå ÇüŵéÀº °¢°¢ °íÀ¯ÇÑ ÀåÁ¡µéÀÌ ÀÖ´Ù. -- ±è±â¿À

Performance to size ratio assembler code uses both approaches which takes advantage of many of the higher level language's efficiency techniques such as code reuse while being able to specifically target speed critical code where it is necessary.

¾î¼Àºí·¯ ÄÚµå´Â ´Ù¸¥ ¸¹Àº °í ¼öÁØ ¾ð¾îÀÇ ÄÚµå Àç»ç¿ë°ú °°Àº È¿°úÀûÀÎ ±â¼ú°ú 󸮼ӵµ¿¡ ÃÊÁ¡À» ¸ÂÃá ¾çÂÊ ¸ðµÎ°¡ °¡´ÉÇÏ´Ù.

32 bit assembler is both clearer and simpler than the DOS and 16 bit Windows code and is not cursed with the complexity of segment arithmetic. You no longer have to deal with AX:DX pairs for long integers and there is no 64k boundary imposed by the segmented structure of 16 bit software.

32 Bit±â¹ÝÀÇ assembler ´Â MS-DOS¿Í 16 Bit À©µµ¿ì Äڵ庸´Ù ½±°í ¸íÈ®ÇÏ´Ù. ´öºÐ¿¡ ÀúÁÖ¹ÞÀº ¼¼±×¸ÕÆ® ¿¬»ê¿¡¼­ ¹þ¾î³¯ ¼ö ÀÖ½À´Ï´Ù. ´õ ÀÌ»ó long integers¸¦ ÇÒ´çÇϱâ À§ÇØ AX:DX ½Ö°ú ½Ç¶ûÀ̸¦ ¹úÀÌÁö ¾Ê¾Æµµ µÇ¸ç, 16ºñÆ® ¼ÒÇÁÆ®¿þ¾îÀÇ 64k ¸Þ¸ð¸® Á¦Çѵµ ´õ ÀÌ»ó ¾ø´Ù.

The complexity of writing 32 bit Windows software is related to the structure of Windows and the sheer range of functions in the API set. It differs from DOS code only in so far as the parameters are passed on the stack rather than in registers as in the DOS interrupts.

(MASM¿¡¼­) 32ºñÆ® À©µµ¿ì ÇÁ·Î±×·¡¹ÖÀÌ º¹ÀâÇÑ ÀÌÀ¯´Â À©µµ¿ìO/SÀÇ ±¸Á¶°¡ º¹ÀâÇÏ°í APIÁýÇÕÀÇ ¹üÀ§°¡ ¹æ´ëÇÒ »ÓÀÌÁö DOS¿Í ºñ±³Çغ¸¸é ´ÜÁö ÆĶó¹ÌÅ͸¦ Àü´ÞÇÒ ¶§ ·¹Áö½ºÅÍ ´ë½Å¿¡ ½ºÅÿ¡ ÆĶó¹ÌÅ͸¦ Àü´ÞÇÑ´Ù´Â °Í¸¸ ´Ù¸¦ »ÓÀÌ´Ù.

While the sheer range of functions in Window can be a bit intimidating, it also puts in the hands of the assembler language programmer, a massive set of capacities that were never available in DOS.

À©µµ¿ì ȯ°æ¿¡¼­ Á¦°øµÇ´Â ¹æ´ëÇÑ ±â´ÉÀº ´Ù¼Ò ºÎ´ãÀÌ µÉ ¼öµµ ÀÖ´Â ¹Ý¸é, DOSȯ°æ¿¡¼­´Â »ý°¢Çϱâ Èûµç ¹æ´ëÇÑ ±â´ÉÀ» Á¦°øÇÑ´Ù.

One of the advantages of writing in assembler is that it comfortably handles the "C" format of the Windows APIs with no difficulty. Zero terminated strings, structures, pointers, data sizes etc... are all part of writing assembler.

¾î¼Àºí¸® ÇÁ·Î±×·¡¹ÖÀÇ ÀåÁ¡ Áß ÇÑ°¡Áö´Â º° ¾î·Á¿ò ¾øÀÌ À©µµ¿ì APIÀÇ ¡°C¡± Æ÷¸ä°ú º° ¾î·Á¿ò ¾øÀÌ Çڵ鸵ÇÒ¼ö ÀÖ´Ù´Â °ÍÀÌ´Ù.


1.2. How does MASM32 work?


It is designed to plug into a computer that has other programming environments set up on it and this places some restrictions on the format. To avoid the problems associated with picking up the wrong link versions and wrong library directory, MASM32 works with specified paths to all of the binary files it needs to build the files.

ÀÌ°ÍÀº ´Ù¸¥ °³¹ß¾ð¾î ȯ°æÀÌ ¼³Á¤µÇ¾î ÀÖ´Â ÄÄÇ»ÅÍ¿¡ ¼³Á¤µÇ¾î ÀÖÀ¸¹Ç·Î Æ÷¸Ë¿¡ À־ ¾à°£ÀÇ Á¦¾àÀ» °®´Â´Ù. À߸øµÈ ¸µÅ© ¹öÀü ÁöÁ¤ ¿À·ù¿Í À߸øµÈ ¶óÀ̺귯¸® ¿À·ù¿Í °ü·ÃµÈ ¹®Á¦¸¦ ÇÇÇϱâ À§ÇØ, MASM32´Â ÆÄÀϺôµå¿¡ ÇÊ¿äÇÑ ¸ðµç ÀÌÁøÆÄÀÏ¿¡ ´ëÇØ¿© ƯÁ¤°æ·Î¸¦ Á¤ÇÏ¿© ÀÛ¾÷ÇÏ°Ô µÈ´Ù.

In the source code, the paths to the library files are specified and in the batch files that are used by the editor to drive the build options, the paths of each binary file is specified as well.

¼Ò½ºµé¿¡´Â ¶óÀ̺귯¸®ÆÄÀÏÀÌ ÁöÁ¤µÈ °æ·Î¿Í ºôµå¿É¼ÇÀ» Á¦¾îÇϱâ À§Çؼ­ ¿¡µðÅÍ¿¡¼­ »ç¿ëµÇ´Â ¹èÄ¡ÆÄÀÏ ±×¸®°í °¢°¢ÀÇ ÀÌÁøÆÄÀÏÀÇ °æ·ÎµéÀÌ Àß ÁöÁ¤µÇ¾î ÀÖ´Ù.

Files from other sources usually do not build from MASM32 without some modification, usually placing the following MASM specific directives at the beginning of the source file will solve most of the problems. The other is to use the "include" & "includelib" syntax for the INCLUDE file and LIBRARIES so that their paths can be found.

´Ù¸¥ ¼Ò½ºÀÇ ÆÄÀϵéÀº º¸Åë MASM32·Î ¾î´À Á¤µµÀÇ ¼öÁ¤ ¾øÀÌ´Â ºôµåÇÏÁö ¾Ê´Â´Ù. º¸Åë ¼Ò½ºÆÄÀÏÀÇ Ãʹݺο¡ ´ÙÀ½°ú °°Àº MASM Áö½Ã¾îµéÀ» Àû¾îÁÖ¸é ´ëºÎºÐÀÇ ¹®Á¦¸¦ ó¸®ÇÒ ¼ö ÀÖ°Ô ÇØÁØ´Ù. ³ª¸ÓÁöµéÀº INCLUDEÆÄÀÏ°ú LIBRARYÆÄÀÏÀ» »ç¿ëÇϱâ À§ÇÑ ¡®include¡± ¿Í ¡°includelib¡± ¹®¹ýÀ¸·Î ÇØ´ç ÆÄÀÏÀÇ °æ·Î¸¦ ãÀ»¼ö ÀÖµµ·Ï ÇØÁØ´Ù.

      .386                      ; forces 32 bit assembly 
      .model flat, stdcall      ; memory model and calling convention 
      option casemap :none      ; case sensitive code 

MASM32 uses its own version of "windows.inc". It is a file over 800k in size and has a very large set of equates and structures in it for 32 bit windows programming. It should always be put before the system include files and libraries.

MASM32´Â ÇØ´ç¹öÀü¿¡ Æ÷ÇԵǾî ÀÖ´Â windows.inc ÆÄÀÏÀ» »ç¿ëÇÑ´Ù. ÀÌ ÆÄÀÏÀº 800k »çÀÌÁî·Î 32bit À©µµ¿ì ÇÁ·Î±×·¡¹ÖÀ» À§ÇÑ ¹«Ã´ ¹æ´ëÇÑ equates¿Í ±¸Á¶Ã¼µé·Î ÀÌ·ç¾îÁ®ÀÖ´Ù. ÀÌ ÆÄÀÏÀº Ç×»ó system include ÆÄÀÏ°ú ¶óÀ̺귯¸® ÆÄÀÏ ¾Õ¿¡ ÀûÇô¾ß ÇÑ´Ù.

EXAMPLE 
      include \masm32\include\windows.inc   ; always first 
      include \masm32\include\user32.inc    ; system include 
      include \masm32\include\kernel32.inc  ; file next 
      include \masm32\include\gdi32.inc 
      includelib \masm32\lib\user32.lib     ; matching system 
      includelib \masm32\lib\kernel32.lib   ; libraries after that 
      includelib \masm32\lib\gdi32.lib 

MASM32 version 8 starts with a set of rebuilt include files that are used to build matching libraries at installation so for each library, you use the include file that matches it. To find a function that you need depending on the reference material you are using, look in the system include file to see which file has the prototype for the function and include the file and the matching library.

MASM32 v.8¿¡¼­´Â ¹Ì¸® ÀÛ¼ºµÈ includeÆÄÀÏÀ» °¡Áö°í ½ÃÀÛÇÑ´Ù.

Most of the common functions are in the three big system DLLs so if you look in,

    GDI32.INC       ; graphics related functions 
    KERNEL32.INC    ; operating system kernel functions 
    USER32.INC      ; various user interface & other functions 


you will find most of the common functions.

For functions that are not in the main libraries, usually the Microsoft reference material specifies which library the function is in so if you look in the include file for that library, you will find the prototype for it. MASM32 also comes with a dedicated function to library tool called liblist.exe to help locate the function you require in the appropriate library. There are two main reference sources for writing 32 bit assembler in Windows, for the assembler instructions and the general architecture of x86 series processors, the three (3) volume set of PDF files from Intel are the best available and are exhaustively documented in the PIII manual set. There is also a set of manuals for the PIV series of Intel processors. The other is Microsoft reference material. The most common is a help file called "WIN32.HLP" which is now a little out of date but still useful. It is a help file of about 12 meg in size. Later information for Win98/se winME, win2k and XP are available in the PlatformSDK that can be obtained from Microsoft for the cost of the shipping. The MSDN CD set are also useful if you have them available.



Á¦ »ý°¢¿¡´Â ´Ü¾îµéµµ ¹®¾îü¿¡¼­ ¾²´Â ´Ü¾îµéÀÌ ¸¹Àº °Í °°°í ¹®¹ýµµ Àß ÀÌÇØ°¡ ¾ÈµÇ°í Çؼ­ Á¤È®ÇÏ°Ô ¹ø¿ªÇϱ⠺¸´Ù´Â Àǹ̸¦ ÆľÇÇؼ­ ¹®ÀåÀ» »õ·Ó°Ô ¾²´Â°Ô ÁÁÀ» °Í °°½À´Ï´Ù. -- ±è±â¿À

ID
Password
Join
"Say it, don't spray it!"


sponsored by andamiro
sponsored by cdnetworks
sponsored by HP

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2006-01-19 19:39:29
Processing time 0.0066 sec