http://www.hackerschool.org/HS_Boards/zboard.php?id=Free_Lectures&no=1139 [º¹»ç]
6.5 ÇÁ·Î½Ãµà¾îÀÇ ¹èÄ¡
--------------------------------------------------------------------------------
PROC ~ ENDP ´Â »ç¶÷ÀÌ º¸±â ÆíÇϱâ À§ÇÑ ±¸ºÐ¿¡ ºÒ°úÇÏ´Ù.¾î¼Àºí·¯´Â ½ÇÁ¦·Î ÇÁ·Î½Ã
µà¾î¸¦ ±¸º°ÇÏÁö ¾Ê´Â´Ù.
¿¹Á¦)CALL2.ASM
CODE SEGMENT
ASSUME CS:CODE
EOF EQU 1AH
START: CALL GETCH
JC EXITP ;--+¿©±â¿¡¼ ÇÁ·Î½Ãµà¾î¸¦ È£ÃâÇÏ°í ÀÖ´Ù.
MOV DL,AL |
CALL PUTCH ;--+
JMP START
EXITP: MOV AH,4CH
INT 21H
GETCH PROC
MOV AH,8
INT 21H
CMP AL,EOF
JNE GETCHEND
STC
RET
GETCHEND: ;±äÀ̸§ÀÇ ¶óº§µµ »ç¿ë°¡´É ±×¶§¶óº§¸¸ÀÇ ÇàÀ¸·Î ÇصµÁÁ´Ù
CLC
RET
GETCH ENDP
PUTCH PROC
MOV AH,2
INT 21H
RET
PUTCH ENDP
CODE ENDS
END START ;½ÇÇà½ÃÀÛÀ» ¾Ë¸®´Â ¹®Àå
END ¹®ÀÌ °¡Áö´Â ±â´É: ÇÁ·Î±×·¥ÀÇ ½ÃÀÛ¹øÁö¸¦ ÁöÁ¤ÇÑ´Ù.
ÀÌ¿Í°°Àº°ÍÀº ¿©·¯°³ÀÇ ÄÚµå ¼¼±×¸ÕÆ®¸¦ °¡Áø ÇÁ·Î±×·¥À» ÀÛ¼ºÇÑ´ÙµçÁö ,ÇÁ·Î½Ãµà¾î¿Í
¸ÞÀÎ ·çƾÀÇ ¼ø¼¸¦ ¹Ù²Û ÇÁ·Î±×·¥À» ÀÛ¼ºÇÏ´Â °æ¿ì¿¡´Â Àý´ë·Î ÇÊ¿äÇÏ´Ù.
¿¹Á¦)CALL2-2.ASM
CODE SEGMENT
ASSUME CS:CODE
EOF EQU 1AH
GETCH PROC
MOV AH,8
INT 21H
CMP AL,EOF
JNE GETCHEND
STC
RET
GETCHEND: ;±äÀ̸§ÀÇ ¶óº§µµ »ç¿ë°¡´É ±×¶§¶óº§¸¸ÀÇ ÇàÀ¸·Î ÇصµÁÁ´Ù
CLC
RET
GETCH ENDP
PUTCH PROC
MOV AH,2
INT 21H
RET
PUTCH ENDP
START: CALL GETCH ; ¸ÞÀÎ ·çƾÀÇ ½ÃÀÛ <--------------------+
JC EXITP ;--+¿©±â¿¡¼ ÇÁ·Î½Ãµà¾î¸¦ È£ÃâÇÏ°í ÀÖ´Ù. |
MOV DL,AL | |
CALL PUTCH ;--+ |
JMP START |
EXITP: MOV AH,4CH |
INT 21H |
|
CODE ENDS |
END START ;½ÇÇà½ÃÀÛÀ» ¾Ë¸®´Â ¹®Àå >------------------+
Á¦7Àå ¸ðµâº° ÇÁ·Î±×·¥ÀÇ ÀÛ¼º¹ý
--------------------------------------------------------------------------------
7.1 INCLUDE ÀÇ ¹æ¹ý
--------------------------------------------------------------------------------
¸ðµâÈÀÇ ÀÌÁ¡: ÇÁ·Î±×·¥À»±â´É º°·Î ºÐÈ°ÇÏ¿© ¾Ë±â½±°Ô ÇÏ´Â °Í°ú °Â¹ßÈ¿À²À»
Çâ»ó½Ãų¼öÀÖ´Ù
¾Æ¹«¸® °°Àº ·çƾÀ» »ç¿ëÇÒ¼öÀÖ´Ù°í ÇÏ´õ¶óµµ ,´Ù¸¥ ÇÁ·Î±×·¥À» ¸¸µé¶§¸¶´Ù. °°Àº
·çƾÀ» Å°º¸µå·Î ºÎÅÍ ÀÔ·ÂÇÏÁö ¾ÊÀ¸¸é ¾ÈµÈ´Ù´Â °ÍÀº ,¿ª½Ã±ÍÂúÀº ÀÛ¾÷ÀÔ´Ï´Ù.
±×·¡¼ ¿Ï¼ºµÈ ·çƾÀÇ ºÎºÐÀ» ¹Ì¸® ´Ù¸¥ ÈÀÏ ·Î ºÎÅÍ ÀÛ¼ºÇصΰí,¸ÞÀÎ ·çƾ¸¸À» ¿¡µð
ÅÍ·Î ºÎÅÍ ÀÔ·ÂÇÏ¿©,¼ºê·çƾÀÎ ºÎºÐÀº ³ªÁß¿¡ ÈÀÏ ´ÜÀ§·Î °áÇÕ½ÃÅ°´Â ¹æ¹ýÀ» »ý°¢ÇØ
³ÂÀ¾´Ï´Ù.ÀÌ°ÍÀÌ ¾î¼Àºí·¯¿¡ ÀÖ´Â ÀÎŬ·çµå(INCLUDE) ±â´ÉÀÔ´Ï´Ù.
À̱â´ÉÀ» »ç¿ëÇÒ ¶§¿¡´Â ¿ì¼± ,¼ºê·çƾ µîÀÇ ºÎºÐÀ» µ¶¸³½ÃŲ ÈÀϷμ ÀÛ¼ºÇصΰí ,
¸ÞÀÎ ·çƾÀ» ÀÛ¼ºÇÒ¶§¿¡ ±×Áß ÇÊ¿äÇÑ ºÎºÐÀ¸·Î INCLUDE ÀÇ»ç¸í·ÉÀ» »ç¿ëÇÏ¿©
"INCLUDE ÈÀÏ À̸§ " À¸·Î ÇÑ´ÙÀ½ ,°áÇÕÇÏ´Â ÈÀÏ À̸§À» ÁöÁ¤ÇÕ´Ï´Ù.ÀÌ·¸°Ô Çصθé
¸ÞÀÎ ·çƾÀ» ¾î¼ÀºíÇÒ¶§¿¡ ÀÚµ¿ÀûÀ¸·Î ÇÊ¿äÇÑ ÈÀÏÀÌ °áÇÕµÇ¾î ¾î¼ÀºíµË´Ï´Ù.
CODE SEGMENT
ASSUME CS:CODE,DS:CODE
;
INCLUDE PUTAL.SUB ; PUTAL.SUB ÈÀÏÀÇ ³»¿ëÀ» ÀοëÇÑ´Ù.
;
START: MOV AX,CODE
MOV DS,AX
MOV AL,3FH
CALL PUTAL
MOV AH,4CH
INT 21H
CODE ENDS
END START
B µå¶óÀ̺꿡 PUTAL.SUB ÈÀÏÀÌ µé¾î ÀÖÀ»¶§
INCLUDE B:PUTAL.SUB
INCLUDE ·Î Àü°³µÈ ºÎºÐÀÇ ¾î¼ÀºíµÈ¸®½ºÆ® ÈÀÏÀº "C " °¡ ºÙ¾îÀÖ´Ù.
µ¿ÀÏ º¯¼ö¿¡ ,¿©·¯°³ÀÇ µ¥ÀÌÅ͸¦ ³ª¿ÇÒ¶§¿¡´Â ´ÙÀ½ Çà¿¡ º¯¼öÀ̸§À» °¡ÁöÁö¾Ê´Â
DB(define byte) ¼±¾ð µîÀ» °è¼ÓÇÑ´Ù.
NUM DB 12H,34H
´Â
NUM DB 12H
DB 34H
¶ó°í ÇÑ°Í°ú °°´Ù.
·¹Áö½ºÅÍÀÇ ´ëÇÇ:
MOV BXSAVE,BX --+
CALL PUTAL | BX ·¹Áö½ºÅÍÀÇ °ªÀ» ´ëÇÇÇß´Ù°¡ º¹±ÍÇÑ´Ù.
MOV BX,BXSAVE --+
..........
BXSAVE DW ? ; º¯¼ö ¼±¾ð
7.2 PUSH,POP ¸í·É
--------------------------------------------------------------------------------
PUSH,POP ¸í·ÉÀº ,½ºÅà ¿µ¿ªÀ̶ó°í ºÎ¸£´Â Ưº°ÇÑ ¿µ¿ª¿¡ ´ëÇÏ¿© µ¥ÀÌÅ͸¦ ±â·Ï,Àоî
³»´Â ¸í·ÉÀÔ´Ï´Ù.
½ºÅõ¿ÀÛ(stack operation)
¸¶Áö¸·¿¡ ³ÖÀº °ÍÀ» óÀ½¿¡ ²¨³»´Â µ¿ÀÛ(LIFO,Last In First Out)À» ½ºÅõ¿ÀÛ
¸Þ¸ð¸®´Â ¼ø¼´ë·Î ³ª¿µÇ¾î ÀÖÀ¸¹Ç·Î ,ÇöÀç¾îµð±îÁö µ¥ÀÌÅÍ°¡ ½×¿©ÀÖ´ÂÁö¸¦ ³ªÅ¸³»±â
À§ÇÏ¿©,½ºÅà Æ÷ÀÎÅÍ(stack pointer,ST ·¹Áö½ºÅÍÀÇ ÀÏÁ¾)¿¡ ¸¶Áö¸·¿¡ ³õ¿©Áø µ¥ÀÌÅÍ°¡
ÀÖ´Â ¸Þ¸ð¸®ÀÇ ¹øÁö¸¦ ±â¾ïÇϵµ·Ï µÇ¾îÀÖÀ¾´Ï´Ù.
»õ·Î¿î µ¥ÀÌÅ͸¦ ½×¾Æ¿Ã¸®¸é SP °ªÀº °¨¼Ò ÇÏ°í,µ¥ÀÌÅ͸¦ ²¨³»¸é SP °ªÀº Áõ°¡
¹øÁö ¸Þ¸ð¸®
ÇÏÀ§¹øÁö | |
FFFA +-------+
FFFB +-------+
FFFC +-------+ <-- SP(½ºÅÃÆ÷ÀÎÅÍ)¿¡ ÀÇÇØ
FFFD +-------+ Áö½ÃµÇ´Â ¸Þ¸ð¸®(¸¶Áö¸·¿¡ ³Ö¾îÁø µ¥ÀÌÅÍ°¡
FFFE +-------+ µé¾î ÀÖ´Ù.)
FFFF +-------+
ÁÖÀÇ) º¸ÅëÀÇ °æ¿ì¿Í ,µ¥ÀÌÅÍÀÇ ÀúÀå¹ý°ú ¼ø¼°¡ °Å²Ù·Î µÇ¾î ÀÖÀ¸¹Ç·Î ÁÖÀÇ°¡ ¿äÇÔ
8086ÀÇ PUSH, POP ¸í·É¿¡¼´Â ¹Ýµå½Ã 2 ¹ÙÀÌÆ®ÀÇ µ¥ÀÌÅÍ°¡ Çѹø¿¡ Àоîµé¿©Áö°í ²¨³»
¾îÁö¹Ç·Î, SP ÀÇ °ªÀº Ç×»ó 2¾¿ Áõ°¨ÇÕ´Ï´Ù.
½ºÅÿµ¿ªÀº º¸Åë ¸Þ¸ð¸®ÀÇ ÃÖ»óÀ§ ¹øÁö·Î ¼³Á¤µÇÁö¸¸ ÀÌ°ÍÀº 8ºñÆ® CPU ¿Í °°ÀÌ ¸Þ¸ð
¸®°ø°£ÀÌ Á¼Àº ½Ã½ºÅÛ¿¡ ÀÖ¾î¼ ÇÁ·Î±×·¥°ú ½ºÅûóÀÇ µ¥ÀÌÅÍ°¡ Ãæµ¹ÇÏÁö ¾Ê°Ô ÇϱâÀ§
Çؼ ¿´À¾´Ï´Ù.
8086¿¡¼´Â º¸´Ù ³ÐÀº ¸Þ¸ð¸® °ø°£À» »ç¿ëÇÒ¼ö °¡ ÀÖÀ¸¹Ç·Î ,½ºÅà µ¿ÀÛÀ» À§Çؼ ½ºÅÃ
¼¼±×¸ÕÆ®¸¦ µ¶¸³ÇÏ¿© ¼³Á¤ÇÏ°í ÀÖÀ¾´Ï´Ù.
SP °¡ °¡¸®Å°´Â¹øÁö´Â ½ÇÁ¦´Â ½ºÅà ¼¼±×¸ÕÆ®(SS)°¡ °¡¸®Å°´Â º£À̽º ¹øÁö·Î ºÎÅÍÀÇ ¿À
ÇÁ¼Â ¹øÁöÀÔ´Ï´Ù.
½ºÅà ¼¼±×¸ÕÆ®ÀÇ ¼³Á¤¹ý¿¡ ÀÇÇØ ÇÁ·Î±×·¥À̳ª µ¥ÀÌÅÍ¿Í ½ºÅ÷ָ¦ µ¶¸³ÇÏ¿© ¹èÄ¡ÇÒ¼öµµ
ÀÖ°í,¶ÇÇÑ 8ÁöÆ® CPU¿Í °°ÀÌ ÇÁ·Î±×·¥°ú ½ºÅÃÀ» µ¿ÀÏÇÑ ¸Þ¸ð¸® °ø°£¿¡ ¹èÄ¡ÇÒ ¸Þ¸ð¸®
°ø°£¿¡ ¹èÄ¡ÇÒ¼öµµ ÀÖÀ¾´Ï´Ù.
¾î´À°æ¿ì¿¡¼µµ ½ºÅà Æ÷ÀÎÅÍÀÇ ÃʱâÄ¡¸¦ Àû´çÇÏ°Ô ¼³Á¤ÇÔÀ¸·Î½á Àû´çÇÑ ¹øÁö¸¦ ½ºÅÿµ
¿ªÀÇ ½ÃÀÛ ¹øÁö·Î ÇÒ¼ö°¡ Àִµ¥ ,º¸ÅëÀº ÃÖ»óÀ§ ¹øÁö·Î ºÎÅͽÃÀÛÇÕ´Ï´Ù.
CS -->+--------+--- ÇÁ·Î±×·¥ | |
+--------+ CS,SS ->+------------|
+--------+ | |ÇÁ·Î±×·¥
SS -->+--------+ +------------+
+--------+ SP½ºÅÿµ¿ª +------------+<-- SP
+--------+ +------------+ ½ºÅÿµ¿ª
CS¿Í SS ¸¦ µ¶¸³½ÃŲ °æ¿ì CS¿Í SS¸¦ ÀÏÄ¡½ÃŲ °æ¿ì
( 8ºñÆ® CPU ¿Í °°Àº »ç¿ë¹ý )
+-----------------------------------------+
| PUSH +- 16ºñÆ® ¹ü¿ë ·¹ÁöÆ®ÅÍ -+ |
| | ¼¼±×¸ÕÆ® ·¹Áö½ºÅÍ | |
| +- 16ºñÆ® ¸Þ¸ð¸® -+ |
| POP +- 16ºñÆ® ¹ü¿ë ·¹Áö½ºÅÍ -+ |
| | ¼¼±×¸ÕÆ® ·¹Áö½ºÅÍ | |
| +- 16ºñÆ® ¸Þ¸ð¸® -+ |
+-----------------------------------------+
*.POP CS ¸í·É¸¸Àº Á¸ÀçÇÏÁö ¾Ê´Â´Ù.
IP¸¦ PUSH, POP ÇÏ´Â ¸í·ÉÀº ¾ø´Ù.
Ç÷¹±× ·¹Áö½ºÅ͸¦ PUSH, POP ÇÏ´Â ¸í·ÉÀ¸·Î´Â À§¿Í º°µµ·Î PUSHF, POPF¸í·ÉÀ» »ç¿ë
PUSH, POP ¸í·ÉÀÇ ½ÇÁ¦ »ç¿ë ¿¹:
·¹Áö½ºÅÍÀÇ ´ëÇÇ°¡ ÇÊ¿ä ÇÏ°Ô µÈ°ÍÀº ¼ºê·çƾ Áß¿¡¼ ·¹Áö½ºÅÍÀÇ ³»¿ëÀÌ Æı« µÇ±â
¶§¹®ÀÔ´Ï´Ù. ¾î´À ·¹Áö½ºÅÍÀÇ ³»¿ëÀÌ Æı«µÇ´ÂÁö´Â ¼ºê·çƾÀÇ ³»¿ëÀ» º¸Áö¾Ê°í¼´Â
¾Ë¼ö¾øÀ¾´Ï´Ù. ±×·¡¼ ·¹Áö½ºÅÍÀÇ ´ëÇÇ, º¹±Í´Â ¸ÞÀÎ ·çƾÂÊÀÌ ¾Æ´Ï¶ó ¼ºê·çƾ ÂÊ¿¡
¼ ÇÏ´Â °ÍÀÌ ÀûÀý ÇÕ´Ï´Ù.
+--------------+ +--------------+
| ¸ÞÀηçƾ | |¸ÞÀηçƾ |
| ........ | | ..... |
| PUSH BX | |CALL PUTAL |
| CALL PUTAL | <--+ | ..... |
| POP BX | | | |
+--------------+ | +--------------+
+--------------+ | +---------------+
|¼ºê·çƾ +-----+ |¼ºê·çƾ |
+--------------+ |PUSH BX |
PUSH ,POP ¸¦ ¸ÞÀηçƾÂÊ¿¡¼ | ..... |
ÇàÇÑ°æ¿ìÀÇ ÇÁ·Î±×·¥ |POP BX |
+---------------+
PUSH,POP¸¦ ¼ºê·çƾÂÊ¿¡¼ ÇàÇÑ °æ¿ìÀÇ ÇÁ·Î±×·¥
¿ÏÀüÈ÷ °°Àº µ¿ÀÛÀ» ÇÏÁö¸¸ ¿À¸¥ÂÊÀÌ ´õ ÁÁÀº ÇÁ·Î±×·¥ÀÔ´Ï´Ù.
¸ÞÀÎ ·çƾÂÊ¿¡¼ ¾î´À ·¹Áö½ºÅÍ°¡ ¼ºê·çƾ ³»¿¡¼ º¯°æÀ̳ª Æı«µÇ´Â°¡¸¦ »ý°¢ÇÏÁö
¾Ê¾Æµµ µÇ±â ¶§¹®ÀÔ´Ï´Ù.
¼ºê·çƾÀ» ¿ÏÀüÈ÷ ºí·¢ ¹Ú½º ·Î¼ »ç¿ëÇÒ¼ö°¡ Àֱ⠶§¹®ÀÔ´Ï´Ù.
ÀÌ¿Í °°ÀÌ ÇÔÀ¸·Î½á ¼ºê·çƾÀÇ ¸ðµâÈ°¡ Á¡Á¡ È¿À²ÀûÀ¸·Î µË´Ï´Ù.
¿¹Á¦)PUSH1.ASM
BL¿¡ ÃʱâÄ¡·Î ÁÖ¾îÁø ¾î¶² 8ºñÆ® °ª()À» 1¹è,2¹è,..., F¹è ÇѼöÄ¡¸¦ Ãâ·ÂÇÑ´Ù.
CODE SEGMENT
ASSUME CS:CODE,DS:CODE
;
INCLUDE PUTAL2.SUB
INCLUDE CRLF.SUB
;
ENTRY: MOV AX,CODE -+
MOV DS,AX -+DS¼³Á¤
;
MOV BL,SEED ;Ãʱ⠵¥ÀÌÅÍ 21H¸¦ BL ¿¡ ÁöÁ¤ÇÑ´Ù.
MOV CL,1
NEXT: CMP CL,10H ;10H¹èÀÌ¸é ³¡³².
JE EXITP
MOV AL,CL -+Ãʱ⠵¥ÀÌÅÍÀÇ BL¹è¸¦ ±¸ÇÑ´Ù.
MUL BL, -+
PUSH AX --+
MOV AL,AH -+-+---- »óÀ§ ¹ÙÀÌÆ® Ãâ·Â
CALL PUTAL -+ |
POP AX --+-- AX·¹Áö½ºÅ͸¦ º¸Á¸(Ãâ·Â¿¡ AL ·¹Áö½ºÅ͸¦ »ç¿ëÇϱâ
CALL PUTAL ;ÇÏÀ§ ¹ÙÀÌÆ® Ãâ·Â ¶§¹® )
CALL CRLF ;°³Çà
INC CL
UMP NEXT
EXITP: MOV AH,4CH -+
INT 21H -+³¡³»°íMS-DOS ·Î ±Íȯ
;
SEED DB 21H ;Ãʱ⠵¥ÀÌÅÍ
CODE ENDS
END ENTRY
PUTAL2.SUB
PUTAL:
+--- PUSH AX -+;¼ºê·çƾ ¼Ó¿¡¼ ·¹Áö½ºÅÍ
|+-- PUSH BX | AX,BX,DX ¸¦ ´ëÇÇÇÏ°í ÀÖ´Ù
||+- PUSH DX -+
||| MOV BL,10H
||| MUL BL
||| MOV DL,AH
||| CALL PUTHEX ; »óÀ§ÀÚ¸®¸¦ Ãâ·Â
||| MOV AH,0
||| MOV BL,10H
||| DIV BL
||| MOV DL,AL
||| CALL PUTHEX ;ÇÏÀ§ÀÚ¸®¸¦ Ãâ·Â
||+- POP DX -+ AX,BX,DX ¸¦ º¹±Í
|+-- POP BX | (PUSH¿Í ÀÇ ¿ª¼ø)
+--- POP AX -+
RET
;
PUTHEX: PUSH AX
PUSH DX
CMP DL,0AH
JAE HEX2
ADD DL,'0'
JMP HEX3
HEX2: ADD DL,'A'-0AH
HEX3: MOV AH,2
INT 21H
POP DX
POP AX
RET
CRLF.SUB
CRLF:
+-- PUSH AX
|+- PUSH DX
|| MOV DL,0DH ;CR(º¹±Í)À» Ãâ·Â
|| MOV AH,2 -+
|| INT 21H -+
|| MOV DL,0AH
|| MOV AH,2 -+ ;LF(°³Çà)À» Ãâ·Â
|| INT 21H -+
|+- POP DX
+- POP AX
RET
PUSH,POP ¸í·ÉÀº 16ºñÆ®·Î µÈ ·¹Áö½ºÅÍ¿¡ ,ȤÀº ¸Þ¸ð¸®¿¡ ´ëÇÇ,º¹±Í¹Û¿¡ ÇÏÁö ¸øÇϹÇ
·Î ,¼ºê·çƾ ³»ÀÇ DL·¹Áö½ºÅÍ ¹Û¿¡ »ç¿ëÇÏÁö ¾Ê´Â°æ¿ì¿¡µµ DX·¹Áö½ºÅͷμ ´ëÇÇÇÑ´Ù.
PUSH AX ; AXÀÇ ³»¿ëÀ» BX¿¡ Àü¼Û
POP BX
Á÷Á¢ Àü¼ÛÀ» Çã¿ëÇÏÁö ¸øÇÏ´Â ¼¼±×¸ÕÆ®°£ÀÇ °ªÀ» Àü¼ÛÇϴµ¥ À¯È¿ÇÕ´Ï´Ù.
¿¹) PUSH CS
POP DS
°¡ÀåÁÖÀÇ ÇؾßÇÒÁ¡:
ÇϳªÀÇ ¼ºê·çƾ Áß¿¡¼ PUSH ÇÑ°ÍÀº ±× ·çƾ ³»¿¡¼ ¹Ýµå½Ã POP ÇÑ´Ù.
7.3 ÇÁ·Î±×·¥ÀÇ ¸ðµâÈ¿Í ¸µÅ¬¹æ¹ý
--------------------------------------------------------------------------------
¸ðµâÈµÈ ÇÁ·Î±×·¥À» µû·Î º°µµ·Î ¾î¼ÀºíÇÏ°í ,LINK¿¡ ÀÇÇØ °áÇÕ ÇÒ¼öµµ ÀÖÀ¾´Ï´Ù.
+-----------------------------------------------------------------------------+
|¸ÞÀÎ ÇÁ·Î±×·¥ ¼ºêÇÁ·Î±×·¥ ¸ÞÀÎ ÇÁ·Î±×·¥ ¼ºêÇÁ·Î±×·¥ |
| | | \/ \/ |
| +-> MASM <-+ MASM MASM |
| \/ \/ \/ |
| ¿ÀºêÁ§Æ® ÇÁ·Î±×·¥ ¿ÀºêÁ§Æ® ÇÁ·Î±×·¥ ¿ÀºêÁ§Æ® ÇÁ·Î±×·¥ |
| \/ \/ |
| LINK LINK |
| \/ \/ |
| ½ÇÇà°¡´É ÇÁ·Î±×·¥ ½ÇÇà°¡´É ÈÀÏ |
| |
| ¾î¼Àºí´Ü°è¿¡¼ °áÇÕÇϴ°æ¿ì ¸µÅ© ´Ü°è¿¡¼ °áÇÕÇÏ´Â °æ¿ì |
+-----------------------------------------------------------------------------+
¿ÀºêÁ§Æ® ´Ü°è¿¡¼ ¸µÅ©°¡ °¡´ÉÇϱ⠶§¹®¿¡ ,MS-DOS¿¡¼´À °øµ¿Çü½Ä¤·ÀÇ ¿ÀºêÁ§Æ® È
ÀÏÀ» ÀÛ¼ºÇÏ´Â ¾î¼Àºí·¯³ªÄÄÆÄÀÏ·¯ÀÇ Ãâ·ÂÀ» ÇÕÃļ ÇϳªÀÇ ½ÇÇà°¡´É ÇÁ·Î±×·¥Çϴ°Í
ÀÌ °¡´ÉÇÏ´Ù.
À̶§¹®¿¡ ¾î¼Àºí·¯¿Í C ¾ð¾î¿Í ÀÇ ¸µÅ© µîÀÌ °¡´ÉÇÏ°Ô µË´Ï´Ù.
±×·¯³ª ¸µÅ©ÀÇ ±â´ÉÀ» Àß »ç¿ëÇϱâ À§Çؼ´Â ,¸¹Àº Çü½Ä»çÀÇ ¾à¼ÓÀ̳ª ¸µÄ¿ÀÇ µ¿ÀÛÀ»
ÀÌÇØÇÏÁö ¾ÊÀ¸¸é ¾ÈµÇ¾Æ¼ ±× °³¿ä¸¦ ¼³¸íÇÏ´Â °Í¸¸Çصµ »ó´çÇÑ ºÐ·®À» Â÷ÁöÇÏ°Ô µË´Ï
´Ù.
ÇÁ·Î±×·¥ÀÇ °³¹ß¿¡ ´ëÇؼ´Â ¸ÞÀÎ ÇÁ·Î±×·¥À» Æ÷ÇÔÇÏ´Â ¸ðµâÀÇ ¼Ò½º ÇÁ·Î±×·¥°ú ¼ºê
·çƾÀ¸·Î ÀÌ·ç¾îÁö´Â ¼Ò½º ÇÁ·Î±×·¥À¸·Î ÀÛ¼ºÇÕ´Ï´Ù.
¿¹Á¦)MODULE1.ASM
¹®ÀÚ¿(string) We are the world ¸¦ Ãâ·ÂÇÑ´Ù.
CODE SEGMENT PUBLIC
ASSUME CS:CODE,DS:DATA
;
EXTRN PUTSTR:NEAR ¿ÜºÎ¿¡¼ ÂüÁ¶ÇÏ´Â ¼ºê·çƾÀÇ ¼±¾ð
;
START: MOV AX,DATA
MOV DS,AX
MOV BX,OFFSET MSG
CALL PUTSTR
MOV AH,4CH
INT 21H
;
CODE ENDS
;
DATA SEGMENT PUBLIC
MSG DB 'We are the world',00H
; |
DATA ENDS +-->³¡³»±â À§ÇØ »ðÀÔµÈ 0 ÀÌ´Ù.
END START
PUTSTR.ASM
¹®ÀÚ¿À» Ãâ·ÂÇÏ´Â ¼ºê·çƾ
CODE SEGMENT PUBLIC
ASSUME CS:CODE
;
PUBLIC PUSTR ;´Ù¸¥ ¸ðµâ¿¡¼ ÂüÁ¶µÇ´Â ¼ºê·çƾ À̸§À» PUBLIC ÀÇ»ç¸í·ÉÀ¸·Î
; ¼±¾ðÇÑ´Ù. Áï ´Ù¸¥µ¥¼ PUTSTRÀ» ÂüÁ¶ÇÒ°ÍÀ̶ó°í ¼±¾ðÇÔ.
PUTSTR PROC NEAR --+
PUSH AX |
PUSH DX |
PUSH SI |
MOV SI,0 |
PUT_NET: |
MOV DL,[BX+SI] |
CMP DL,0 -+-+----->¹®ÀÚ¿Áß 0 ÀÌ ³ªÅ¸³ª¸é ³¡³½´Ù.
JZ PUT_EXIT -+ |
MOV AH,2 |¹Ýµå½Ã ¼ºê·çƾ
INT 21H | PROC ~ ENDP ·Î
INC SI | ¼±¾ðÇÑ´Ù.
JMP PUT_NEXT |
PUT_EXIT: |
POP SI |
POP DX |
POP AX |
RET |
PUTSTR ENDP ----------+
;
CODE ENDS Çü½Ä»ó ÇϳªÀÇ ¼¼±×¸ÕÆ®¿¡ ÀÖ´Â °É·ÎÇÑ´Ù.
END
¼ºê·çƾ PUTSTRÀº ,BX¿¡ ÀÇÇØ °£Á¢ÁöÁ¤µÇ´Â ¹øÁö¸¦ ¼±µÎ·Î Çѵ¥ÀÌÅÍ ¿À»
¹®ÀÚ¿·Î¼ Ãâ·ÂÇÏ°í ,0 ÀÌ ³ªÅ¸³ª¸é Á¾·áÇÏ´Â °ÍÀÔ´Ï´Ù.
PUBLIC À̶ó´Â ÁöÁ¤Àº : ´Ù¸¥ ¸ðµâ°ú ¸µÅ©ÇÒ ¶§¿¡ °°Àº À̸§ÀÇ ¼¼±×¸ÕÆ®°¡ ÀÖ´Ù¸é
±×°ÍÀ» ÇÕÃļ Çϳª·Î Ç϶ó, ¶ó´Â ÁöÁ¤ÀÔ´Ï´Ù.
EXTRN(external) :
¿°ÅµÈ ¼ºê·çƾÀÌ ¿ÜºÎÀÇ ¸ðµâÀÇ ¸ðµâ ¼Ó¿¡ µé¾îÀÖ´Ù´Â °ÍÀ» ³ªÅ¸³»°í ÀÖÀ¾´Ï´Ù.
¾î¼Àºí·¯´Â ´õ¼Àºí ´Ü°è¿¡¼ °°Àº ¸ðµâ ³»ÀÇ ¼ºê·çƾÀ̳ª ¶óº§ÀÌ Á¸ÀçÇÏÁö ¾Ê´Â °æ¿ì
¿¡´Â Symbol not defined ¿¡·¯¸¦ ¹ß»ýÇϴµ¥, EXTRN ÀÇ»ç¸í·É¿¡ ÀÇÇØ ¼±¾ðµÇ¾î ÀÖ
°ÔµÇ¸é ,±×¼ºê·çƾÀ̳ª ¶óº§Àº ´Ù¸¥ ¸ðµâ¿¡ ÀÖ¾î¼ ¸µÅ©ÇÒ¶§ °áÇÕÇÒ¼öÀÖ´Ù°í °£ÁÖµÇ
¾î ¿¡·¯¸¦ ¹ß»ýÇÏÁö ¾Ê°í ¾î¼ÀºíÀ» °è¼ÓÇÕ´Ï´Ù.
¶óº§À̸§ÀÌ µ¿Àϼ¼±×¸ÕÆ® ³»¿¡ ¹èÄ¡µÇ´Â °ÍÀÎ °æ¿ì¿¡´Â ,
: ¿¡ ¹Ù·Î ÀÌ¾î¼ NERÀ» ºÙÀÌ°í, ¶óº§ÀÇ ¼Ó¼ºÀ» ¼±¾ðÇÏÁö ¾ÊÀ¸¸é ¾ÈµË´Ï´Ù.
¸¸Àϵ¿ÀÏ ¼¼±×¸ÕÆ®³»¿¡ Á¸ÀçÇÏÁö ¾ÊÀ» ¶§¿¡´Â ,
: FAR À» ºÙÀÌÁö ¾ÊÀ¸¸é ¾ÈµË´Ï´Ù.
¼ºê·çƾ :
¼ºê·çƾ¿¡ ³õÀÌ´Â ¸ðµâµµ ÇϳªÀÇ ¼¼±×¸ÕÆ®·Î¼ Çü½ÄÀ» °®Ãß±âÀ§ÇØ ±× ¾ÕµÚ¸¦
SEGMENT ~ ENDS ·Î µÑ·¯ ½Ô´Ï´Ù.¿©±â ¿¡¼ ¼¼±×¸ÕÆ®¼±¾ðÀº ¸ÞÀηçƾ°ú °°Áö¾ÊÀ¸¸é ¾È
µË´Ï´Ù.(µ¿ÀÏÇѼ¼±×¸ÕÆ® À̸§À̾î¾ß ÇÑ´Ù) µ¥ÀÌÅÍ ¼¼±×¸ÕÆ®¸¦ »ç¿ëÇÏÁö¾ÊÀ» ¶§¿¡´Â
ASSUME ¹®ÀåÀ¸·Î DS ¼±¾ðÀ» ÇÏÁö ¾Êµµ·Ï ÇÕ´Ï´Ù.
PUBLIC :
ÀÇ»ç¸í·É À¸·Î PUTSTR À̶ó´Â À̸§ÀÇ ¼ºê·çƾ(¶óº§ À̸§)ÀÌ ´Ù¸¥ ¿ÜºÎÀÇ ¸ðµâ¿¡¼ Âü
Á¶ °¡´ÉÇÏ´Ù´Â °ÍÀ» ¼±¾ðÇÏ°í ÀÖÀ¾´Ï´Ù.ÀÌ°ÍÀº ÀÌ ·çƾ Áß ¾î´À ¶óº§ À̸§´Ï ¿ÜºÎÂü
Á¶°¡ °¡´É ÇÏ´Ù´Â °ÍÀ» ³ªÅ¸³»´Â °Í ÀÔ´Ï´Ù.
¿©±â¼ »ç¿ëÇÏ°í ÀÖ´À PUBLC °ú ¼¼±×¸ÕÆ® ¼±¾ðÁß¿¡ »ç¿ëµÇ°í ÀÖ´À PUBLC°ú´Â ´Ù¸¥ °Í
ÀÔ´Ï´Ù. ±×¸®°í ¼ºê·çƾ ÀüÈĸ¦ PROC ~ ENDP ¿¡ ÀÇÇØ µÑ·¯½Î°í, ±¸Á¶¸¦ ¸íÈ®ÇÏ°Ô
ÇÕ´Ï´Ù. ÀÌÀü°ú ¸¶Âù°¡Áö·Î ´Ü¼øÈ÷ ¶óº§ À̸§¸¸À» ¼ºê·çƾÀ¸·Î ÇÒ¼öµµ ÀÖÁö¸¸, º°·Î
ÃßõÇÒ¸¸ ÇÏÁöÇÏÁö´Â ¾Ê½À´Ï´Ù. ±×¸®°í PROC ÀÇ ´ÙÀ½ÀÇ NEAR Àº ¾ø¾îµµ »ó°üÀÌ ¾øÁö
¸¸,À̰͵µ µ¿ÀÏÇÑ ¼¼±×¸ÕÆ® ³»¿¡¼ ÂüÁ¶ µÇ´Â ¶óº§À̶ó´Â °ÍÀ» ³ªÅ¸³»°í ÀÖÀ¾´Ï´Ù.
ÀÌ»óÀÇ °ÍÀ» Á¤¸®ÇÏ¿© ÇÁ·Î±×·¥¿¡ ÇÊ¿äÇÑ ±¸Á¶¸¦ ³ªÅ¸³»°í¸é ´ÙÀ½°ú °°ÀÌ µË´Ï´Ù.
(¼¼±×¸ÕÆ® À̸§À» CODE , ¼ºê·çƾ À̸§À» PUTSTR ·Î ÇÑ´Ù.)
+------------- ¸ÞÀηçƾ -------------------------------------+
| CODE SEGMENT PUBLC |
| ASSUME CS:CODE....... |
| EXTRN PUTSTR:NEAR |
| START: |
| +---------+ |
| | º» ¹® | |
| +---------+ |
| CODE ENDS |
| +----------------------------------+ |
| | ¸¸ÀÏ ÀÖ´Ù¸é µ¥ÀÌÅÍ ¼¼±×¸ÕÆ® µî | |
| +----------------------------------+ |
| END START |
+----------------------------------------------------------------+
+------- ¼ºê·çƾ -------------------------+
| CODE SEGMENT PUBLC |
| ASSUME CS:CODE..... |
| PUBLC PUTSTR |
| PUTSTR PROC NEAR |
| +---------+ |
| | º» ¹® | |
| +---------+ |
| PUTSTR ENDP |
| CODE ENDS |
| END |
+----------------------------------------------+
¿ÀºêÁ§Æ® ÈÀÏÀ» ¸µÅ©ÇÒ ¶§¿¡´Â ÈÀÏ À̸§À» " + " ·Î ¿¬°áÇÏ¿© ÁöÁ¤ÇÕ´Ï´Ù.
¹Ýµå½Ã ¸ÞÀÎ ·çƾÀ» Æ÷ÇÔÇÏ´Â ¸ðµâÀÇ ÈÀÏ À̸§À» ¼±µÎ¿¡ ÁöÁ¤ÇÕ´Ï´Ù.
A>LINK MODULE1+PUTSTR,,MODULE1;
ÀÌ°ÍÀ¸·Î ½ÇÇà°¡´É ÈÀÏÀÌ ¿Ï¼ºµË´Ï´Ù.
ÀڱⰡ ¸ðµâÀ» ¸¸µé¾î ³ª°¥¶§¿¡´Â À§·¹¼ ¼³¸íÇÑ ¹æ¹ý¿¡ µû¶ó¼ ¸ðµâÀ¸ °³¹ßÇÏ¸é µÇ
´Âµ¥, ¾Æ¸¥ Âü°í¼ ·Î ºÎÅÍ ÀοëÇÒ °æ¿ì¿¡ ¹Ýµå½Ã À§¿Í °°Àº ´ë·Î µÇ¾î ÀÖÁö ¾ÊÀº °æ
¿ì°¡ ÀÖÀ¾´Ï´Ù. ±×¿Í °°Àº °æ¿ì¿¡´Â ¼¼±×¸ÕÆ® À̸§À» °íÃÄ ¾²´Â ¹æ¹ý µîÀ¸·Î ´ëóÇØ
ÁֽʽÿÀ. ±×·¡µµ ¾ÈµÇ´Â°Ü¿ì¿¡´Â ¿øÀÎÀ» ¿©·¯°¡Áö·Î »ý°¢ ÇÒ¼ö°¡ ÀÖÁö¸¸,ÀÚ¼¼ÇÏ°Ô´Â
³ªÁß¿¡ ´Ù·çµµ·Ï ÇÏ°í ,ÇÒ¼ö¾øÀÌ ¼ºê·çƾ ÀÚü¸¦ ¸Âµµ·Ï ÀڱⰡ ´Ù½Ã º£¿ ÇÏ¿© °í
ÃÄ ÀÛ¼ºÇÏ´Â µî ½ÃÇàÂø¿À¸¦ ÇØ º¸½Ê½Ã¿ä.
|
Hit : 9204 Date : 2008/12/13 11:08
|