http://www.hackerschool.org/HS_Boards/zboard.php?id=Free_Lectures&no=1138 [º¹»ç]
Á¦ 5Àå ºñ±³ºÐ±â¿Í ¼ºê·çƾ
--------------------------------------------------------------------------------
µð¹ö±×(DEBUG)ÀÇ Ä¿¸ÇµåÀÇ ¿ä¾à
-------------+----------------------------------------+-------------------------
Ä¿¸Çµå | ¸ñÀû(Purpose) |¸í·É
COMMAND | |Çü½Ä(Format)
-------------+----------------------------------------+-------------------------
Assemble |¹®ÀåÀ» ¾î¼ÀºíÇÑ´Ù. A[¹øÁö]
Compare |¸Þ¸ð¸®¸¦ ºñ±³ÇÑ´Ù. C¹üÀ§¹øÁö
Dump |¸Þ¸ð¸®¸¦ Ç¥½ÃÇÑ´Ù. D[¹øÁö]À̰ųª
| D[¹üÀ§]
Enter |¸Þ¸ð¸®¸¦ º¯°æÇÑ´Ù. E ¹øÁö [¸®½ºÆ®]
Fill |¸Þ¸ð¸® ºí·°À» º¯°æÇÑ´Ù. F¹üÀ§ ¸®½ºÆ®
Go |¼±ÅÃÀû ºê·¹ÀÌÅ© Æ÷ÀÎÆ®¸¦ °®°í ½ÇÇàÇÑ´Ù. G [=¹øÁö]
| [¹øÁö
| [¹øÁö...]]
Hexarithmetic|16Áø¼öµ¡¼À,»¬¼À H °ª °ª
Input |ÀÔ·Â ¹ÙÀÌÆ®¸¦ Àаųª Ç¥½ÃÇÑ´Ù. I Æ÷Æ®¹øÁö
Load |ÈÀÏÀ̳ª Àý´ë µð½ºÄÏ ¼½Å͸¦ ¸Þ¸ð¸®¿¡ ·ÎµåÇÑ´Ù. L[¹øÁö[µå¶óÀ̺ê
| ¼½ÅÍ ¼½ÅÍ]]
Move |¸Þ¸ð¸® ºí·°À» Àü¼ÛÇÑ´Ù. M ¹üÀ§¹øÁö
Name |ÈÀÏÀ̳ª Æз¯¹ÌÅ͸¦ Á¤ÀÇÇÑ´Ù. [d:]
| [Æнº]ÈÀÏÀ̸§[.È®ÀåÀÚ]
Output |Ãâ·Â¹ÙÀÌÆ®¸¦ ³»º¸³½´Ù. O Æ÷Æ®¹øÁö ¹ÙÀÌÆ®
Quit |µð¹ö±× ÇÁ·Î±×·¥À» ³¡³½´Ù. Q
Register |·¹Áö½ºÅͳª Ç÷¹±×¸¦ Ç¥½ÃÇÑ´Ù. R[·¹Áö½ºÅÍÀ̸§]
Search |¹®ÀÚ¸¦ ã´Â´Ù. S ¹üÀ§¸®½ºÆ®
Trace |ÁýÇàÇÏ°í Ç¥½ÃÇÑ´Ù. T [=¹øÁö][°ª]
Unassemble |¸í·ÉÀ» µð¾î¼ÀºíÇÑ´Ù. U[¹øÁö]À̰ųª
| U[¹üÀ§]
Write |ÈÀÏÀ̳ª Àý´ë µð½ºÄÏ ¼½Å͸¦ ±â·ÏÇÑ´Ù. W[¹øÁö][µå¶óÀ̺ê
| ¼½ÅÍ ¼½ÅÍ]
-------------+------------------------------------------------------------------
6.1 ¹Ýº¹Ã³¸®¿Í Á¶°ÇºÐ±â ¸í·É(conditional branch instruction)
--------------------------------------------------------------------------------
Á¶°ÇºÐ±â ¸í·É:¹Ýº¹À» ÇÒ¶§ ÇÊ¿ä ºÒ°¡°áÇÑ ¿ä¼Ò
CMP AX,0 ; AX·¹Áö½ºÅÍÀÇ °ªÀ» 0 °ú ºñ±³Ç϶ó
JE 100 ; ¹Ù·Î À§ÀÇ ºñ±³ °á°ú°¡ °°´Ù¸é 100¹øÁö·Î ºÐ±âÇ϶ó
CMP(compare) : ·¹Áö½ºÅͳª ¸Þ¸ð¸® ¹× ¼ýÀÚÀÇ Å©±â¸¦ ºñ±³ÇÕ´Ï´Ù.
JE(Jump if Equal) °°´Ù¸é ºÐ±âÇ϶ó
JNE(Jump if Nor Equal) °°Áö ¾Ê´Ù¸é ºÐ±âÇ϶ó
JA(Jump if Above) ~ ÀÌ»ó À̶ó¸é ºÐ±âÇ϶ó
JC(Jump if Carry) ij¸®Ç÷¡±×°¡ 1 À̶ó¸é ºÐ±âÇ϶ó
CMP +- ¹ü¿ë ·¹Áö½ºÅÍ(8/16ºñÆ®)-+ +-·¹Áö½ºÅÍ(8/16ºñÆ®)
+- ¸Þ¸ð¸® (8/16ºñÆ®)-+ +-¸Þ¸ð¸® (8/16ºñÆ®)
+-¼ýÀÚ (8/16ºñÆ®)
¿¹Á¦) JMP1.ASM
1ºÎÅÍ 100 ±îÁö ÀÇ ¼ö¸¦ ´õÇÏ´Â ÇÁ·Î±×·¥
CODE SEGMENT
ASSUME CS:CODE,DS:CODE
MOV AX,CODE ; DS¼³Á¤
MOV DS,AX
;
MOV CX,100 ;CX¿¡ 100À» ÁöÁ¤
MOV AX,0 ;AX ¿¡ 0À» ÁöÁ¤
MEXT: ADD AX,CX
SUB CX,1
CMP CX,0 ; CXÀÇ ³»¿ëÀÌ 0Àΰ¡ ºñ±³
JNE NEXT ;0ÀÌ¸é ¹ØÀ¸·Î ¾Æ´Ï¸é NEXT ¶ó´Â ¶óº§·Î À̵¿
MOV TOTAL,AX
MOV AH,4CH ;³¡³»°í MS-DOS·Î µ¹¾Æ°£´Ù.
INT 21H
;
TOTAL DW ?
;
CODE ENDS
END
¶óº§(label)ÀÇ »ç¿ë:
¶óº§À̶ó´Â °ÍÀº ¸í·ÉµîÀÌ ÀÖ´Â ¹øÁö¿¡ ºÙ¿©Áø À̸§ÀÔ´Ï´Ù.
¶óº§À̸§ÀÇ Á÷ÈÄ¿¡ ÄÝ·Ð" : " À» ³Ö´Â´Ù
INC,DEC ¸í·É:
·¹Áö½ºÅͳª ¸Þ¸ð¸®ÀÇ ³»¿ëÀ» +/-1 ÇϱâÀ§ÇÑ ¸í·ÉÀ¸·Î¼ INC(increment.Áõ°¡)
DEC(decrement.°¨¼Ò)¸í·ÉÀÌ ÁغñµÇ¾î ÀÖÀ¾´Ï´Ù.
SUB CX,1
´ë½Å DEC CX ·Î ¾µ¼ö°¡ ÀÖÀ¾´Ï´Ù.
INC +- ¹ü¿ë ·¹Áö½ºÅÍ(8/16ºñÆ®)
+- ¸Þ¸ð¸® (8/16ºñÆ®)
DEC +- ¹ü¿ë ·¹Áö½ºÅÍ(8/16ºñÆ®)
+- ¸Þ¸ð¸® (8/16ºñÆ®)
¶ÇÇÑ ¿©»ê Á÷ÈÄ¿¡ ±×°á°ú°¡ 0 ÀÎÁö ¾Æ´ÑÁö¸¦ ºñ±³ÇÏ¿© ºÐ±âÇÏ´Â °æ¿ì¿¡´Â ºñ±³¸í·ÉÀ»
»ý·« ÇÒ¼ö°¡ ÀÖÀ¾´Ï´Ù. Ç÷¹±× ·¹Áö½ºÅÍÀÇ µ¿ÀÛ¿¡ °üÇÑ Àý¿¡¼ ¼³¸íÇÏ°ÚÁö¸¸ ,ADD³ª
SUB,INC,DEC µîÀÇ ¿¬»ê ¸í·É ´ÙÀ½¿¡ ´Â Á÷Á¢ Á¶°Ç ºÐ±â ¸í·ÉÀ» ³ÖÀ» ¼ö°¡ ÀÖÀ¾´Ï´Ù.
( ÀÌ °æ¿ì ¿¡ ´Â °á°ú°¡ 0 À¸·Î ºñ±³µÈ °ÍÀ¸·Î °£ÁÖ µË´Ï´Ù.)
µû¶ó¼
NEXT: ADD AX,CX
DEC CX
CMP CX,0
JNE NEXT
´Â
NEXT: ADD AX,CX
DEC CX
JNE NEXT
°¡ µË´Ï´Ù.
¹Ýº¹À» ³¡³»´Â Á¶°ÇÀº ,óÀ½ÀÇ Çϳª ,¸¶Áö¸·ÀÇ Çϳª¿¡ ÁÖÀÇ
L1: ADD AX,CX
INC CX
CMP CX,100
JBE
CX=100 À¸·Î Çعö¸°¸é AX ¿¡´Â 100 ÀÌ ´õÇØÁöÁö ¾ÊÀ¾´Ï´Ù.
±×·¡¼ ¹Ýº¹ÇÏ´Â Á¶°ÇÀ¸·Î CX < 100 ÀÇ »çÀÌ¿¡¼°¡ ¾Æ´Ï¶ó CX<=100ÀÇ Á¶°ÇºÐ±â ¸í·É
¿¡´Â JBE(Jump if Below or Equal)¸¦ »ç¿ëÇÕ´Ï´Ù.
DUPÀÇ»ç¸í·É°ú ºí·°Àü¼Û:
----------------------
DB 16 DUP (?)
|
+--->DUP´Â duplication ÀÇ ¾àÀÚ
¿©±â¿¡¼ ÇàÇÑ Á¤ÀÇ Áß¿¡ »ç¿ëµÇ°í ÀÖ´Â DUP´Â ()¼Ó¿¡ °ÍÀ» ()¿ÞÂÊÀÇ °¹¼ö¸¸Å ¹Ýº¹ÇÏ
¶ó´Â ÀǹÌÀÔ´Ï´Ù.
¿¹Á¦)JMP3.ASM
MSG1ºÎÅÍ ÀúÀåµÈ 10¹ÙÀÌÆ®¸¦ MSG2 ·Î Àü¼ÛÇÏ´Â ÇÁ·Î±×·¥
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
;
MOV AX,DATA ; DS¼³Á¤
MOV DS,AX
MOV SI,OFFSET MSG1 ;SI ¿¡ MSG1 ¹øÁö°ªÀ» ÁöÁ¤ÇÑ´Ù.
MOV DI,OFFSET MSG2
MOV CX,10
CONT: MOV AL,BYTE PTR [SI] ;MSG1 ºÎÅÍ MSG2 ·Î 1¹ÙÀÌÆ®Àü¼Û
MOV BYTE PTR [DI],AL
INC SI ;Àü¼ÛÇÏ´Â ¹øÁö¸¦ Çϳª¾¿ Áõ°¡½ÃŲ´Ù.
INC DI
DEC CX ;Àü¼ÛÇؾßÇÒ °¹¼öÀÇ Ä«¿îÆ®¸¦ Çϳª¾¿ ÁÙÀδÙ.
JNE CONT
MOV AH,4CH ; ³¡³»´Â ½Ã½ºÅÛÈ£Ãâ
INT 21H
;
CODE ENDS
;----------------
DATA SEGMENT
MSG1 DB 'ABCDEFGHIJKLMNOP'
MSG2 DB 16 DUP (?) ;16¹ÙÀÌÆ® ¸¸ÅÀÇ ºñÃʱâÈ ¸Þ¸ð¸®¸¦ È®º¸
DATA ENDS
END
µ¥ÀÌÅÍ ¼¼±×¸ÕÆ®(DS;data segment)°ªÀ» ¾Æ´Â ¹æ¹ý:
À§ÇÁ·Î±×·¥ÀÇ ½ÇÇà°á°ú¸¦ È®ÀÎÇÏ·Á¸é ,MSG1 ¹× MSG2 ¿¡ ÀÖ´Â ¹øÁö¸¦ ¾ËÁö¾ÊÀ¸¸é ¾ÈµË
´Ï´Ù. ±×·¯³ª ÇÁ·Î±×·¥À» ½ÇÇàÇϱâÀü¿¡´Â DS ÀÇ °ªÀº PSP(program segment prefix)ÀÇ
¼±µÎ¸¦ °¡¸®Å°°í Àֱ⠶§¹®¿¡ µ¥ÀÌÅ͸¦ ÀÐÀ» ¼ö°¡ ¾øÀ¾´Ï´Ù.
+--------------------------------------------------+
DS:µ¥ÀÌÅÍ ¼¼±×¸ÕÆ® | +---------------+--->DS,ES |
·¹Áö½ºÅÍ | | PSP | |
ES:¿¢½ºÆ®¶ó ¼¼±×¸ÕÆ® | +---------------+--->CS,SS |
·¹Áö½ºÅÍ | |ÄÚµå ¼¼±×¸ÕÆ® | |
| +---------------+<-- ¿©±â¿¡ ¼¼±×¸ÕÆ® ¹øÁö¸¦ |
| |µ¥ÀÌÅÍ ¼¼±×¸ÕÆ®| ¾Ë°í½Í´Ù |
| +---------------+ |
+--------------------------------------------------+
¸Þ¸ð¸®¿¡ ·ÎµåµÇ¾úÀ» ¶§ÀÇ EXEÈÀÏÀÇ ¿¹
½ÇÁ¦·Î µ¥ÀÌÅÍ°¡ ÀúÀåµÇ¾î ÀÖ´Â ¼¼±×¸ÕÆ® ¹øÁö¸¦ ¾ËÇÊ¿ä°¡ ÀÖÀ¾´Ï´Ù.
MOV AX,DATA
MOV DS,AX ¿¡¼ DATA ÀÇ ³»¿ëÀ» ´ëÄ¡ÇÏ´Â
MOV AX,2244 ·Î ¿ª¾î¼Àºí µË´Ï´Ù. 2244´Â °¢ PC ÀÇ »óȲ¿¡µû¶ó ´Ù¸¨´Ï´Ù.
-D2244:0,1F
2244:0000 41 42 43 44 45 46 47 48-49 4A 4B 4C 4D 4E 4F 50 ABCDEFGHIJKLMNOP
·¹Áö½ºÅÍ Àд R Ä¿¸Çµå¿¡ ÀÇÇØ µ¥ÀÌÅÍ ¼¼±×¸ÕÆ®ÀÇ°ªÀ» ¼¼Æ®ÇÑ´ÙÀ½,´ÙÀ½°ú °°ÀÌ º¼¼ö
µµÀÖÀ¾´Ï´Ù.
-RDS
DS 2232
:2244
-D0,1F
2244:0000 41 42 43 44 45 46 47 48-49 4A 4B 4C 4D 4F 50
Á¶°Ç ºÐ±â ¸í·É¿¡ ´ëÇÑ À϶÷Ç¥¸¦ ¸¸µé¾úÀ¾´Ï´Ù.
+-----------------+----------------+---------------------+
|ºÐ±âÇϱâÀ§ÇÑ A,B |ºÎÈ£¾ø´Â ¼ýÀÚÀÎ |ºÎÈ£ÀÖ´Â ¼ýÀÚÀÎ |
|ÀÇ ´ë¼Ò°ü°è |°æ¿ì |°æ¿ì |
+-----------------+----------------+---------------------+
|A>B |JA/JNBE |JG/JNLE |
|A>=B |JNB/JAE |JGE/JNL |
|A=B |JZ/JE |JZ/JE |
|A<=B |JBE/JNA |JLE/JNG |
|A<B |JB/JNAE |JL/JNGE |
|A=\=B |JNZ/JNE |JNZ/JNE |
+-----------------+----------------+---------------------+
6.2 ¹«Á¶°Ç ºÐ±â¸í·É
--------------------------------------------------------------------------------
JMP ¸í·É:
¿¹Á¦)JMP4.ASM
MSG1¹øÁöºÎÅÍ ½ÃÀÛÇÏ´Â ¹®ÀÚ¿À» MSG2¹øÁö ÀÌÈÄ·Î ¿Å±â´Âµ¥ " $" ÀÚ°¡
³ªÅ¸³¯¶§±îÁö ÇàÇÏ´Â ÇÁ·Î±×·¥
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
;
MOV AX,DATA ;DS ¼³Á¤
MOV DS,AX
MOV SI,OFFSET MSG1 ;MSG1¹øÁö¸¦SI¿¡ ÁöÁ¤
MOV DI,OFFSET MSG2
MOV DX,0
CONT: MOV AL,BYTE PTR [SI]
| CMP AL,"$" ;'$' À̸é Á¾·á
| JE EXITP
| MOV BYTE PTR [DI]
| INC SI
| INC DI
| INC DX ;Àü¼Û¹®ÀÚ¼öÀÇ Ä«¿îÆ®
+--- JMP CONT ;¹«Á¶°Ç ¹Ýº¹
EXITP: MOV NUMBER,DX
MOV AH,4CH
INT 21H
;
CODE ENDS
;-------------------
DATA SEGMENT
MSG1 DB 'ABCDEFGHIJKLMNO'
MSG2 DB 16 DUP (?)
NUMBER DW ?
DATA ENDS
END
Á¾·á¸¦ ³ªÅ¸³»´Â ¹®ÀÚ (¿©±â¼´Â "$" ÀÚ )°¡ ³ªÅ¸³¯¶§ ±îÁö Àü¼ÛÀ» ¹Ýº¹ÇÑ´Ù.
´ë¹®ÀÚ - ¼Ò¹®ÀÚ º¯È¯ ·çƾ:
¿µ¾î´ë¹®ÀÚ´Â 41H(=A)ºÎÅÍ 5AH(=Z) ±îÁö ¿¬¼ÓÀûÀ¸·Î ÇÒ´çµÇ¾îÀÖÀ¾´Ï´Ù.
CODE SEGMENT
ASSUME CS:CODE
MEXT: MOV AH,1 ; 1¹®ÀÚÀÔ·Â ½Ã½ºÅÛ È£Ãâ¸í·É»ç¿ë
INT 21H
CMP AL,1AH ; CTRL+Z À̸é Á¾·á
JE EXITP
CMP AL,'A' ; ¾Æ½ºÅ°ÄÚµå 'A' ¹Ì¸¸À̸é L1 À¸·Î
JB L1
CMP AL,'Z' ; ¾Æ½ºÅ°ÄÚµå 'Z' º¸´ÙÅ©¸é L1 À¸·Î
JA L1
ADD AL,'a'-'A' ;»óÀÀÇÏ´Â ¼Ò¹®ÀÚ¸¦ ã±âÀ§ÇØ'a'-'A'=20H¸¦ ´õÇÑ´Ù.
L1: MOV AH,2 ; 1¹®ÀÚ Ãâ·Â ½Ã½ºÅÛ È£Ãâ ¸í·É»ç¿ë
MOV DL,AL
INT 21H
JMP NEXT
EXITP: MOV AH,4CH
INT 21H
CODE ENDS
END
6.3 ºñ±³ºÐ±â¿Í Ç÷¹±× ·¹Áö½ºÅÍ
--------------------------------------------------------------------------------
Á¶°ÇºÐ±â¸í·ÉÀº ºñ±³¸í·ÉÀ̳ª ¿¬»ê¸í·ÉÀÇ °á°ú ¿¡ ÀÇÇØ ¼¼Æ®µÈ Ç÷¹±× ·¹Áö½ºÅÍÀÇ °ª
¿¡ µû¶ó¼ ºÐ±âÇÒ°ÍÀÎÁö ¾Æ´ÑÁö¸¦ °áÁ¤ÇÏ°í ÀÖ´Â °ÍÀÔ´Ï´Ù.
Ç÷¹±× ·¹Áö½ºÅÍÀÇ °¢ ºñÆ®ÀÇ ÀǹÌ
Ç÷¹±× ·¹Áö½ºÅÍ´Â ÀÌ¿Í °°ÀÌ ÀϹÝÀûÀÎ ·¹Áö½ºÅÍ¿Í ´Þ¶ó¼ ,¿©·¯°¡Áö »óŸ¦ ±â¾ïÇϱâ
ÀÇÇÑ ·¹Áö½ºÅÍÀÔ´Ï´Ù.
ºñÆ®¸¶´Ù µ¶¸³µÈ Àǹ̸¦ °¡Áö°íÀÖ¾î µ¶¸³µÇ¾î ÀÛµ¿ÇÑ´Ù.
CF:ij¸® Ç÷¹±×
¿¬»êÇÑ °á°ú,ÃÖ»óÀÇ ºñÆ®·ÎºÎÅÍÀÇ ³ôÀº ÀÚ¸®·Î ÀÚ¸®¿Ã¸²(ij¸® CARRY) ȤÀº ÃÖ»óÀÇ ºñ
Æ®·ÎºÎÅÍÀÇ ºô¸²(borrow)ÀÌ ¹ß»ýÇÑ °æ¿ì¿¡ 1·Î ¼¼Æ®µÇ°í ±× ÀÌ¿ÜÀÇ °æ¿ì 0 À¸·Î ¸®¼Â
µÈ´Ù. ±×¹ÛÀÇ ¸ñÀûÀ¸·Î »ç¿ëµÉ¶§µµ ÀÖ´Ù.
PF:Æи®Æ¼ Ç÷¹±×
¿¬»êÇÑ °á°ú ,1 ·Î µÈ ºñÆ®ÀÇ ¼ö°¡ ¦¼ö°³(even number)ÀÏ ¶§ 1·Î ¼¼Æ®µÇ °í,Ȧ¼ö
(odd number)À϶§ 0 À¸·Î ¸®¼ÂµÈ´Ù.
AF:º¸Á¶ ij¸® Ç÷¹±×
8(16)ºñÆ® ¿¬»ê¿¡¼ ,ÇÏÀ§ 4(8)ºñÆ®·Î ºÎÅÍ »óÀ§ 4(8)ºñÆ®·Î ÀÚ¸®¿Ã¸² ȤÀº ºô¸²ÀÌ ¹ß
»ýÇÑ °æ¿ì¿¡ 1·Î ¼¼Æ®µÇ°í ±×ÀÌ¿ÜÀÇ °æ¿ì 0 À¸·Î ¸®¼ÂµÈ´Ù. 10 Áø º¸Á¤¸í·É¿¡ ÀÖ¾î¼
µµ »ç¿ëµÈ´Ù.
ZF:Á¦·Î Ç÷¹±×
¿¬»êÇÑ °á°ú °¡ 0 À¸·Î µÇ¾úÀ» ¶§¿¡ 1·Î ¼¼Æ®µÇ°í,±× ÀÌ¿ÜÀ϶§¿¡ 0 À¸·Î ¸®¼ÂµÈ´Ù.
SF: »çÀÎ Ç÷¹±×
¿¬»êÇÑ °á°ú,ÃÖ»óÀÇ ºñÆ®°¡ 1 ÀÌ µÇ¾úÀ» ¶§ (Áï ,º¸¼öÇ¥ÇöÀ¸·Î À½¼ö°¡ µÇ¾úÀ» ¶§)
1·Î ¼¼Æ®µÇ°í,±× ÀÌ¿ÜÀ϶§¿¡ 0 À¸·Î ¸®¼ÂµÈ´Ù.
OF:¿À¹öÇ÷οì Ç÷¹±×(overflow flag)
¿¬»êÀ» ºÎÈ£°¡ ´Þ¸° ¼ýÀÚ·Î ÇßÀ» ¶§ ,¿À¹öÇ÷οì ȤÀº ¾ð´õ Ç÷οì(under flow)°¡ ¹ß
»ýÇÑ °æ¿ì¿¡ 1·Î ¼¼Æ®µÇ°í,±×ÀÌ¿Ü À϶§¿¡´Â 0 À¸·Î ¸®¼ÂµÈ´Ù.
ÀÌ»óÀÇ 6°¡ÁöÇ÷¹±×´Â ¿¬»êÀÇ °á°ú¿¡ µû¶ó¼ ¼¼Æ® ȤÀº ¸®¼ÂµÇ´Â Ç÷¹±×·Î½á ½ºÅ×ÀÌÅÍ
½º Ç÷¹±×(status flag, »óÅ Ç÷¹±×)¶ó°í ºÎ¸¨´Ï´Ù.
Ç÷¹±×¿¡´Â ±× ÀÌ¿Ü¿¡µµ 3°¡Áö´õ ÀÖ¾î¼ ,±×µéÀº CPU ÀÇ µ¿ÀÛ »óŸ¦ Á¦¾îÇÏ´Â °ÍÀ¸·Î
¼ ÄÁÆ®·Ñ Ç÷¹±×(control flag,Á¦¾î Ç÷¹±×)¶ó°í ºÎ¸¨´Ï´Ù.
DF:µð·º¼Ç Ç÷¹±×(direction flag)
½ºÆ®¸µ Á¶ÀÛÀ» ÇÒ¶§¿¡ ÀÌ Ç÷¹±×°¡ 0 ÀÌ¸é ¹øÁö¸¦ ³ªÅ¸³»´Â ·¹Áö½ºÅÍ °ªÀÌ ÀÚµ¿ÀûÀ¸
·Î Áõ°¡ÇÏ°í 1 ÀÌ¸é ·¹Áö½ºÅÍ°ªÀº ÀÚµ¿ÀûÀ¸·Î °¨¼ÒÇÑ´Ù.
IF:ÀÎÅÍ·´Æ® Ç÷¹±×(interrupt . enable . flag)
ÀÌ Ç÷¹±×°¡ 0ÀÏ ¶§ INTR ´ÜÀÚ·Î ºÎÅÍÀÇ ¿ÜºÎ ÀÎÅÍ·´Æ®¿ä±¸´Â ¹«½ÃµÇ°í ,1À϶§¿¡´Â
¿ÜºÎ ÀÎÅÍ·´Æ® ¿ä±¸¸¦ ¹Þ¾ÆµéÀϼö ÀÖ°Ô µÈ´Ù.
TF:Æ®·¦ Ç÷¹±×(trap flag)
ÀÌ Ç÷¹±×°¡ 0 À϶§ CUP ´Â º¸Åë´ë·Î ¸í·ÉÀ» ½ÇÇàÇÑ´Ù.
ÀÌ Ç÷¹±×°¡ 1 À϶§ CUP ´Â ÇÑ ¸í·É ½ÃÇàÇÒ¶§ ¸¶´Ù ÀÚµ¿ÀûÀ¸·Î ³»ºÎ ÀÎÅÍ·´Æ®(INT1)
¸¦ ¹ß»ýÇÏ°í ,ÀÎÅÍ·´Æ®Ã³¸® ·çƾÀ¸·Î µé¾î°£´Ù.(´Ü,ÀÌ Ã³¸® ·çƾÀÇ ½ÇÇàÁß¿¡´Â Æ®·¦ÇÃ
·¡±×´Â 0 À¸·ÎŬ¸®¾îµÈ´Ù.) ÇÁ·Î±×·¥ÀÇ ÃßÀû(trace)¿¡ »ç¿ëµÈ´Ù.
ij¸® Ç÷¹±×´Â ÇÁ·Î±×·¥¿¡ ÀÇÇؼµµ ¼¼Æ® ȤÀº ¸®¼¼Æ® ÇÒ ¼ö ÀÖ½À´Ï´Ù.
Ç÷¹±× ·¹Áö½ºÅÍ Á¦¾î¸í·É
STC(Set Carry flag) ij¸®Ç÷¹±×¸¦ 1·Î ¼¼Æ®ÇÑ´Ù.
CLC(CLdar Carry flag) ij¸® Ç÷¹±×¸¦ 0À¸·Î ¸®¼ÂÇÑ´Ù.
CMC(CoMplement Carry flag) ij¸® Ç÷¹±×°¡ 0À̸é 1·Î ,1À̸é 0À¸·Î ¼¼Æ®ÇÑ´Ù.
STD(Set Direction flag) µð·º¼Ç Ç÷¹±×¸¦ 1·Î ¼¼Æ®ÇÑ´Ù.(¹øÁö¸¦ ÀÚµ¿ÀûÀ¸·Î
°¨¼Ò½ÃÅ°´Â ¹æÇâ)
CLD(CLear Direction flag) µð·º¼Ç Ç÷¹±×¸¦ 0 À¸·Î ¸®¼ÂÇÑ´Ù.(¹øÁö¸¦ ÀÚµ¿ÀûÀ¸
·Î Áõ°¡½ÃƼ´Â ¹æÇâ)
STI(Set Interrupt-enable flag) ÀÎÅÍ·´Æ® Ç÷¹±×¸¦ 1 ·Î ¼¼Æ®ÇÏ°í ÀÎÅÍ·´Æ®¸¦ ¹Þ¾Æ
µéÀϼö ÀÖ´Â »óÅ·ΠÇÑ´Ù.
CLI(CLear Interrupt-enable flag)ÀÎÅÍ·´Æ® Ç÷¹±×¸¦ 0À¸·ÎÇÏ°í,ÀÎÅÍ·´Æ®¸¦ °ÉÁö ¸øÇÏ
°Ô ±ÝÁö»óÅ·ΠÇÑ´Ù.
LAHF(Load AH from Flags) Ç÷¡±× ·¹Áö½ºÅÍÀÇ ÇÏÀ§ 8ºñÆ®¸¦ AH·¹Áö½ºÅÍ·ÎÀü¼ÛÇÑ
´Ù.»ç¿ëÇÏÁö ¾Ê´Â ºñÆ®ÀÇ °ªÀº Á¤ÇØÁ® ÀÖÁö¾Ê´Ù.
SAHF(Store AH into Flags) AH·¹Áö½ºÅÍÀÇ ³»¿ëÀ» Ç÷¡±× ·¹Áö½ºÅÍÀÇ ÇÏÀ§ 8ºñÆ®
¿¡ Àü¼ÛÇÑ´Ù.
PUSHF(PUSH Flags onto stack) Ç÷¹±× ·¹Áö½ºÅÍÀÇ ³»¿ëÀ» ½ºÅÃ(stag)»ó¿¡ Ǫ½¬(PUSH)
ÇÑ´Ù.
POPF(POP Flags off stack) ½ºÅØÀ§ÀÇ ¿öµå µ¥ÀÌÅ͸¦ Ç÷¹±× ·¹Áö½ºÅÍ¿¡ POP ÇÑ´Ù.
ºñ±³¿¬»ê ¸í·É°ú Á¶°ÇºÐ±â¸í·ÉÀÇ °ü°è:
ºñ±³¿¬»ê ¸í·ÉÀº »¬¼À¸í·É°ú °°Àº °ÍÀÔ´Ï´Ù.´Ù¸¥Á¡Àº ºñ±³ÇÑ °á°ú ºñ±³¸¦ ÇàÇÑ ·¹Áö½º
Åͳª ¸Þ¸ð¸®ÀÇ ³»¿ëÀº ÀüÇô º¯ÇÏÁö ¾Ê°í ´ÜÁö Ç÷¹±× ·¹Áö½ºÅ͸¸À» º¯È½ÃŲ´Ù.
CMP AX,BX
¶ó°í ÇßÀ»¶§,AX ·¹Áö½ºÅÍ·Î ºÎÅÍ BX ·¹Áö½ºÅÍÀÇ ³»¿ëÀ» (°¡»óÀûÀ¸·Î ) »«´ÙÀ½,±× °á°ú
¿¡ µû¶ó¼ Ç÷¹±× ·¹Áö½ºÅÍ ¸¸À» º¯È ½ÃÅ°°í AX,BX ÀÇ ³»¿ëÀº º¸Á¸ µË´Ï´Ù.
SUB AX,BX
¶ó°í Çϸé Ç÷¹±× ·¹Áö½ºÅÍ´Â ¿ÏÀüÈ÷ ¶È°°°Ô ¼¼Æ®µÇÁö¸¸,AX ·¹Áö½ºÅÍÀÇ °ªµµ º¯ÈµÇ¾î
AX ¿¡¼ BX ¸¦ »« °á°ú°¡ AX ÀÇ °ªÀÌ µÇ¾î ¹ö¸³´Ï´Ù.
Ç÷¹±×·¹Áö½ºÅÍÀÇ °ªÀº »ê¼ú ³í¸®¿¬»êÀ» ÇàÇÒ ¶§¿¡ ¼¼Æ® ¸®¼ÂµÇ°í, Àü¼Û¸í·ÉÀ̳ª ºÐ±â
¸í·ÉÀ» ½ÇÇàÇؼ´Â º¯ÈÇÏÁö ¾Ê½À´Ï´Ù.
Á¶°Ç ºÐ±â ¸í·ÉÀÇ Á¤¸®
+--------+---------+---------------+--------+---------------+
|A,B ÀÇ |ºÎÈ£¾ø´Â |Á¶°ÇÀ» ¸¸Á·ÇÏ´Â|ºÎÈ£ÀÖ´Â|Á¶°ÇÀ» ¸¸Á·ÇÏ´Â|
|´ë¼Ò °ü |¼ýÀÚÀÇ |Ç÷¹±×ÀÇ »óÅ |¼ýÀÚÀÇ |Ç÷¹±×ÀÇ »óÅ |
|°è |°æ¿ì |CF | °æ ¿ì |SF¨äOF | ZF |
+--------+---------+-------+-------+--------+-------+-------+
|A>B |JA/JNBE | 0 | 0 |JG/JNLE | 0 | 0 |
|A>=B |JNB/JAE | 0 | * |JGE/JNL | 0 | * |
|A=B |JZ/JE | * | 1 |JZ/JE | * | 1 |
|A<=B |JBE/JNA | 1 | 1 |JLE/JNG | 1 | 1 |
|A<B |JB/JNAE | 1 | * |JL/JNGE | 1 | * |
|A=\=B |JNZ/JNE | * | 0 |JNZ/JNE | * | 0 |
+--------+---------+-------+-------+--------+-------+-------+
A,B ÀÇ ´ë¼Ò°ü°è´Â ,CMP A,B Áï(A-B)ÀÇ °á°ú·Î Ç¥½ÃµÈ´Ù.
¨ä´Â ¹èŸÀû ³íÀÌÇÕ(exclusive OR)À» ±¸ÇÏ´Â ¿¬»êÀÌ´Ù.
* Ç¥½Ã¶õÀÇ °ªÀº 0 ÀÌ¶óµµ 1 ÀÌ¶óµµ Á¶°ÇÆÇ´Ü¿¡ ¿µÇâÀ» ÁÖÁö ¾Ê´Â´Ù.
JA/JNBE ¿Í °°ÀÌ / ·Î ±¸ºÐµÈ 2°³ÀÇ Ç¥ÇöÀº ,¿ÏÀüÈ÷ °°Àº °ü°è¸¦ ´Ù¸¥ ¸»·Î Ç¥ÇöÇÑ
°ÍÀ¸·Î¼ ,¾î´ÀÂÊÀ» »ç¿ëÇصµ »ó°üÀÌ ¾ø´Ù.
´Ü,µð¹ö±×¿¡ ÀÇÇÑ µð½º¾î¼Àºí °á°ú´Â ¿ÞÂÊÀÇ Ç¥Çö À¸·Î µÈ´Ù.
Á¶°Ç ºÐ±â¸í·É¿¡¼´Â ¼îÆ® Á¡ÇÁ(short jump) Áï,¸í·ÉÀÌ ÀÖ´Â ´ÙÀ½ ¹øÁö·Î ºÎÅÍ +127 ~
-128¹ÙÀÌÆ® À̳»·Î ¸¸ ºÐ±âÇÒ¼öÀÖ´Ù.
+------+------------+------------+------------------------------------------+
|Ç÷¹±×|1À϶§ÀÇ ºÐ±â|0À϶§ÀÇ ºÐ±â|Ç÷¹±×°¡ 1À϶§ÀÇ ÀÇ¹Ì |
+------+------------+------------+------------------------------------------+
|SF |JS |JNS |º¸¼öÇ¥ÇöÀ¸·Î À½¼öÀÌ´Ù. |
|ZF |JZ/JE |JNZ/JNE |°á°ú°¡ 0 ÀÌ´Ù.(À§Ç¥ÀÇ A=B¿Í °°´Ù) |
|PF |JP/JPE |JNP/JAE | 1ÀÌµÈ ºñÆ®ÀÇ ¼ö°¡ ¦¼öÀÌ´Ù. |
|CF |JB/JNAE |JNB/JAE |ij¸®Ç÷¹±×°¡ 1ÀÌ´Ù(¿¬»êÇÑ°á°ú ÀÚ¸®¿Ã¸² |
| | | | ȤÀº ºô¸²ÀÌ ¹ß»ýÇÑ °æ¿ì µî) |
|OF |JO |JNO |º¸¼öÇ¥ÇöÀ» »ç¿ëÇÑ ¿¬»ê¿¡¼ °á°ú°¡ ¹üÀ§¸¦ |
| | | |ÃÊ°úÇß´Ù. |
+------+------------+------------+------------------------------------------+
|·¹Áö½ºÅÍ | | ¸í·ÉÀÇ ÀÇ¹Ì |
+------+------------+------------+------------------------------------------+
|CX | ------ | JCXZ | CX·¹Áö½ºÅÍ°¡ 0À϶§¸¸ ºÐ±âÇÑ´Ù. |
+------+------------+------------+------------------------------------------+
Á¶°ÇºÐ±â¸í·É ¾àÀÚ¸¦ Àд¹ý
A:Above À§(ºÎÈ£¾øÀ½) O:Overflow ¿À¹öÇ÷οì
B:Below ¾Æ·¡(ºÎÈ£¾øÀ½) Odd ¦¼ö
E:Equal 0 ȤÀº °°À½ P:Parity Æи®Æ¼
G:Greater À§(ºÎÈ£ÀÖÀ½) S:Sign ºÎÈ£°¡ À½¼ö
L:Less ¾Æ·¡(º¸È£ÀÖÀ½) Z:Zero 0 ȤÀº °°À½
N:Not ~ °¡¾Æ´Ï´Ù
JNGE ´Â
Jump if Not Greater or Equal
À̹ǷÎ(A>=B),Áï A<B¶ó´Â Àǹ̰¡ µË´Ï´Ù.
Ç÷¹±×·¹Áö½ºÅÍ Ç¥½Ã¸¦ º¸´Â¹ý:
DEBUG¿¡¼´Â ,R Ä¿¸Çµå·Î ·¹Áö½ºÅÍÀÇ ³»¿ëÀ» Ç¥½ÃÇßÀ» ¶§ ±×¸®°í ÃßÀû(trace) °í¿ì
(GO)ÀÎ T,G Ä¿¸Çµå ·Î ½ÇÇàÀ» ÃßÀûÇßÀ» ¶§¿¡,°¢Á¾ ·¹Áö½ºÅÍÀÇ ³»¿ë°ú ÇÔ²² Ç÷¹±×·¹Áö
½ºÅÍÀÇ ³»¿ëµµ Ç¥½Ã µË´Ï´Ù.Ç÷¹±× ·¹Áö½ºÅÍÀÇ Ç¥½Ã´Â ¼ýÀÚ³ª 1,0 ¿¡ ÀÇÇÑ °ÍÀÌ ¾Æ´Ï
¶ó °¢ Ç÷¹±× ÀÇ ¸íĪÀ» »ç¿ë ÇÏ¿© Ç¥½Ã µË´Ï´Ù.
°¢ Ç÷¹±×ÀÇ 0,1 ÀÇ »óÅÂ¿Í Ç¥½Ã¸¦ ´ëÀÀ½ÃŲ °ÍÀº ´ÙÀ½°ú °°½À´Ï´Ù.
+-----------+---+---+---+---+---+---+---+---+
|Ç÷¹±× À̸§|OF |DF |IF |SF |ZF |AF |PF |CF |
+-----------+---+---+---+---+---+---+---+---+
| 0 |NV |UP |DI |PL |NZ |NA |PO |NC |
+-----------+---+---+---+---+---+---+---+---+
| 1 |OV |DN |EI |NG |ZR |AC |PE |CY |
+-----------+---+---+---+---+---+---+---+---+
+--------------------+--------------------+-----------------+
|Ç÷¹±× À̸§ | 0 | 1 |
+--------------------+--------------------+-----------------+
|Overflow flag | Not oVerflow |OVerflow |
|Direction flag | UP |DowN |
|Interrupt flag | Disable Interrupt |Enable Interrrupt|
|Sign flag | PLus |NeGative |
|Zero flag | Not Auxiliary carry|ZeRo |
|Auxiliary Carry flag| Parity Odd |Auxiliary Carry |
|Parity flag | Parity Odd |Parity Even |
|Carry flag | Not Carry |Carry |
+--------------------+--------------------+-----------------+
MOV BX,8888H
CMP BX,0
0°ú ºñ±³ÇÑ°á°ú 8888H - 0HÀÇ °á°ú¿¡ µû¶ó¼ Ç÷¡±× ·¹Áö½ºÅÍ°¡ ¼¼Æ®µË´Ï´Ù.
»¬¼ÀÀÇ °á°ú ´Â 8888H À̹ǷΠÃÖ»óÀ§ ºñÆ®°¡ 1 ÀÌ µÇ°í ,»çÀÎ Ç÷¡±×´Â NG(À½¼ö)°¡
µË´Ï´Ù.±×·¯³ª ºô¸²Àº ¹ß»ýÇÏÁö ¾Ê¾ÒÀ¸¹Ç·Î ,ij¸® Ç÷¡±×´Â NC (0)°¡ µÇ¾î ÀÖÀ¾´Ï´Ù.
¿À¹öÇ÷οì Ç÷¡±×°¡ NV(0)ÀÔ´Ï´Ù.
µû¶ó¼ ºÎÈ£¾ø´Â ºñ±³ JB ´Â Á¶°ÇÀ» ¸¸Á·ÇÏÁö ¾ÊÀ¸¹Ç·Î,´ÙÀ½ ¸í·ÉÀ¸·Î ÁøÇàÇÕ´Ï´Ù.
¿©±â¿¡¼ ºÎÈ£ÀÖ´Â ºñ±³ JLÀº Á¶°ÇÀ» ¸¸Á·ÇÏ°í ÀÖÀ¸¹Ç·Î ,ÁöÁ¤ÇÑ ¹øÁö·Î ºÐ±â ÇÕ´Ï´Ù.
ÁÖÀÇ )
1À» ´õÇÏ´Â ¸í·ÉÀ» ADD¸í·ÉÀ¸·Î ÇÑ°æ¿ì¿Í ,INC ¸í·ÉÀ¸·Î ÇÑ °æ¿ì
µ¡¼À°á°ú´Â ¾çÂÊ´Ù °°Áö¸¸ Ç÷¡±× ·¹Áö½ºÅÍÀÇ º¯È´Â ´Þ¶ó Áý´Ï´Ù.
º¸ÅëÀÇ »ê¼ú¿¬»ê ¸í·É¿¡¼´Â ÀÚ¸® ¿Ã¸² ȤÀº ºô¸²ÀÌ ¹ß»ýÇÑ °æ¿ì´Â ij¸® Ç÷¡±×°¡ ¼¼
Æ® µÇÁö¸¸ ,INC ¸í·É°ú DEC ¸í·É¸¸Àº Ư¼öÇؼ,ÀÌ 2 Á¾·ùÀÇ ¸í·É¸¸Àº ÀÚ¸®¿Ã¸²À̳ª ºô
¸²ÀÌ ¹ß»ýÇصµ ij¸® Ç÷¡±×¿¡ ¿µÇâÀ» ÁÖÁö ¾Ê½À´Ï´Ù.
À̶§¹®¿¡ ÀÚ¸®¿Ã¸²()À» »ç¿ëÇÏ¿© Á¶°ÇÆÇ´ÜÀ» ÇÏ´Â ¸í·É¾Õ¿¡ INC ¸í·É,DEC ¸í·ÉÀ» ³õÀ»
¶§ ´Â ÁÖÀÇ °¡ ÇÊ¿ä ÇÕ´Ï´Ù. ij¸® Ç÷¡±×´Â ,À̵é¸í·Éº¸´Ù ¾ÕÀÇ »óŸ¦ °è¼Ó °¡Áö°í
ÀÖÀ¾´Ï´Ù.
INC ,DEC ¸í·ÉÀÌ ÀÌ¿Í °°Àº ¼ºÁúÀ» °®°íÀÖ´Ù´Â °ÍÀº °áÄÚ ºÒÆíÇÑ°ÍÀÌ ¾Æ´Ï¶ó ,¿ÀÈ÷
·Á ½ÇÁ¦ ÇÁ·Î±×·¥ »ó¿¡¼ ´À µµ¿òÀÌ µÇ´Â °æ¿ì°¡ ¸¹À¾´Ï´Ù.
ij¸® Ç÷¡±×¸¦ Á¦¿ÜÇÑ ´Ù¸¥ Ç÷¡±× ·¹Áö½ºÅÍ´Â INC,DEC ¸í·ÉÀÇ °á°ú¿¡ µû¶ó¼ ¼¼Æ® Ȥ
Àº ¸®¼ÂµË´Ï´Ù.
6.4 ¼ºê·çƾÀÇ »ç¿ë¹ý
--------------------------------------------------------------------------------
¼ºê·çƾ(subroutine)À̶õ
ÇÁ·Î±×·¥ Áß¿¡¼ ¿©·¯¹ø µÇÇ®ÀÌ »ç¿ëµÇ´Â ºÎºÐÀ» ¸ÞÀÎ ·çƾÀ¸·Î ºÎÅÍ µ¶¸³ÇÏ¿© ÀÛ¼º
ÇÁ·Î±×·¥À» È¿À²ÀûÀ¸·Î ÇÏ´Â È¿°ú°¡ÀÖ´Ù.
ÇÁ·Î±×·¥À» 󸮳»¿ë¿¡ µû¶ó ºÒ·°À¸·Î ³ª´®À¸·Î½á Àüü¸¦ º¸±â ½±µµ·Ï ÇØÁÖ°í ,º¸¼ö
¸¦ ½±°Ô ¸¸µé¾î ÁÖ´Â ÀÌÁ¡ÀÌ ÀÖÀ¾´Ï´Ù.
¾î¼Àºí·¯ÀÇ ¼ºê·çƾÀº BASIC °ú ºñ¼ýÇÑ »ç¿ë¹æ¹ýÀÌ´Ù.
¼ºê·çƾÀÇ ³¡À» ³ªÅ¸³»´Â RET ¸í·ÉÀ¸·Î ³¡³³´Ï´Ù.
RET (return command )´Â ¼ºê·çµòÀ¸·Î ºÎÅÍ ¸ÞÀÎ ·çƾÀ¸·Î µ¹¾Æ¿À´Â ¸í·ÉÀÔ´Ï´Ù.
¼ºê·çƾÀ» ºÎ¸¦ ¶§´Â CALL ´ÙÀ½¿¡ ¼ºê·çƾÀÇ ½ÃÀÛ¿¡ ºÙ¿©Áø ¶óº§À» »ç¿ëÇÕ´Ï´Ù.
¿¹)CALL1.ASM
0ºÎÅÍ 9±îÁöÀÇ ¼ýÀÚ¸¦ Ãâ·ÂÇÏ´Â ÇÁ·Î±×·¥ÀÌ´Ù. ´Ü ÇÑ ÀÚ ÇÑÀÚ Ãâ·ÂÇÏ´Â ¼ºê·çƾÀ» ¸¸
µé¾î È£ÃâÇÑ´Ù.
CODE SEGMENT
ASSUME CS:CODE
;
MOV CX,0
NEXT: CALL SUB1 ;CALL¸í·ÉÀ¸·Î ¼ºê·çƾÀ» È£Ãâ
INC CX
CMP CX,10
JB NEXT
MOV AH,4CH
INT 21H
;
SUB1: MOV DX,CX
ADD DL,'0'
MOV AH,2
INT 21H
RET ;¸®Åϸí·É
CODE ENDS
END
¼ºê·çƾ SUB1¼Ó¿¡¼´Â , CX ·¹Áö½ºÅÍÀÇ °ªÀ» º¯°æ½ÃÅ°Áö ¾Êµµ·Ï CX ·¹Áö½ºÅÍÀÇ °ªÀ»
DX ·¹Áö½ºÅÍ·Î Àü¼ÛÇÑ´Ù
16Áø¼ö°ªÀÇ È¸é»ó¿¡ Ãâ·Â¹ý:
±âº»±¸»ó _ AL·¹Áö½ºÅÍÀÇ ³»¿ëÀ» Ç¥½ÃÇÏ·Á°í ÇÑ´Ù¸é, AL=3FHÀÏ°æ¿ì
"3" ¿Í "F" ¿ÍÀÇ 2°¡Áö ¹®ÀÚ¸¦ Ãâ·ÂÇÏÁö ¾ÊÀ¸¸é ¾ÈµÈ´Ù.
AL·¹Áö½ºÅÍÀÇ ³»¿ëÀ» »óÀ§ 4ºñÆ®¿Í ÇÏÀ§ 4ºñÆ®·Î ³ª´©¾î¼ ,2¹ø¿¡ °ÉÃÄ Ãâ·ÂÇØ¾ß ÇÑ
´Ù.
+--------------------------------------------------------+
| AL DL |
|+--+--+ +--+--+ |
||3 |F |--->|0 |F | --->¾Æ½ºÅ° ÄÚµå·Î º¯È¯ --> Ãâ·Â |
|+--+--+ +--+--+ |
| DL |
| | +--+--+ |
| +------->|0 |3 | --->¾Æ½ºÅ° ÄÚµå·Î º¯È¯ --> Ãâ·Â |
| +--+--+ |
+--------------------------------------------------------+
·¹Áö½ºÅÍÀÇ ºñÆ® ´ÜÀ§·Î µ¥ÀÌÅ͸¦ Ãë±ÞÇÏ·Á¸é,º¸Åë ³í¸® ¿¬»ê¸í·ÉÀ̳ª,½¬ÇÁÆ®(À̵¿)
·ÎÅ×ÀÌÆ®(rotate, ȸÀü ) ¸í·ÉÀ» »ç¿ëÇÑ´Ù.
¿©±â¼´Â ÇнÀÀ» À§ÇØ °ö¼À°ú ³ª´°¼ÀÀ» »ç¿ëÇÑ´Ù.
AL 3F
\/ * 10H
AX 03F0
/ |
»óÀ§ÀÚ¸® º¸Á¸ <--- 03 |
AH 00 |
\ \/
AX 00F0
\/ %10H
AX 000F
\/
<-------- 0F
¿¹Á¦)PUTAL.ASM
AL·¹Áö½ºÅÍ ³»ÀÇ °ªÀ» ASCIIÄÚµå 16Áø¼ö°ªÀ¸·Î ȸ鿡 Ç¥½ÃÇÏ´Â ÇÁ·Î±×·¥
(¼ºê·çƾÀ» »ç¿ëÇÑ´Ù.)AL ³»ÀÇ °ªÀº 3FH°ªÀ» ¿¹·Î µé¾ú´Ù.
CODE SEGMENT
ASSUME CS:CODE,DS:CODE
;
MOV AX,CODE ; DSÀÇ ÃʱâÄ¡ ¼³Á¤
MOV DS,AX
;
MOV AL,3FH ;óÀ½AL¿¡ 3FH°¡ µé¾î ÀÖ´Ù°í ÇÏÀÚ
CALL PUTAL ;¼ºê·çƾÀ» È£ÃâÇÑ´Ù.
;
MOV AH,4CH
INT 21H
;-----------------------
PUTAL: MOV BL,10H ;ALÀ» 10H Çϸé AH,AL -----+»óÀ§ÀÚ¸®
MUL BL ; 03 F0 °¡ µÈ´Ù. |ÇÏÀ§ÀÚ¸®·Î
MOV LEVEL2,AH ; |ºÐÇÒÇÏ´Â
MOV AH,0 ;AX¸¦ 10H ºÐÀÇ 1 ·Î ³ª´©¸é AH AL |¼ºê·çƾ
MOV BL,10H 00 0F °¡ µÈ´Ù |
DIV BL |
MOV LEVEL1,AL ; ÇÏÀ§ÀÚ¸® º¸Á¸ |
MOV DL,LEVEL2 ; -+ »óÀ§ÀÚ¸® Ç¥½Ã |
CALL PUTHEX -+ |
MOV DL,LEVEL1 ; -+ ÇÏÀ§ÀÚ¸® Ç¥½Ã |
CALL PUTHEX -+ |
RET ----+
;---------------------------
PUTHEX: CMP DL,0AH
JAE HEX2
ADD DL,'0' ; 0 ÀÇ ASCII ÄÚµå °ªÀÌ 30H ÀÌ´Ù. ----+¼öÄ¡¿¡ ´ëÇÑ
JMP HEX3 (0 ¿¡¼ 9 Àΰæ¿ì) |¾Æ½ºÅ° Äڵ带
HEX2: ADD DL,'A'-0AH ; A ¿¡¼ F Àΰæ¿ì |»êÃâ,Ç¥½ÃÇÏ´Â
HEX3: MOV AH,2 'A' ÀÇ ASCIIÄڵ尪Àº 41ÀÌ´Ù |¼ºê·çƾ
INT 21H 'B'´Â 42°¡ Ç¥½Ãµµ±â À§Çؼ´Â |
RET 41+1ÀÌ µÇ¾î¾ß Çϴµ¥ ÀÌ°ÍÀº |
'A'+(BH-AH)ÀÇ °è»êÀ¸·Î °¡´ÉÇÏ´Ù. --+
LEVEL2 DB ?
LEVEL1 DB ?
;
CODE ENDS
END
¼ºê·çƾ PUTAL ¼Ó¿¡¼ ´Ù½Ã ¼ºê·çƾ PUTHEX ¸¦ È£ÃâÇÒ¼öµµ ÀÖÀ¾´Ï´Ù.
¿©±â¿¡¼ Ãâ·Â½Ã½ºÅÛ INT 21Àº DL ·¹Áö½ºÅÍ¿¡ ASCIIÄڵ尪À» ³ÖÀ» ¶§ ±×¿¡ ÇØ´çÇÏ´Â
ASCII ¹®ÀÚ°¡ ȸ鿡 Ãâ·ÂµÈ´Ù.
0 ¿¡¼ 9 ±îÁöÀÇ ¼ýÀÚ¿¡ ´ëÀÀÇÏ´Â ¾Æ½ºÅ° ÄÚµå¿Í A ¿¡¼ F ±îÁö ´ëÀÀ ÇÏ´Â ¾Æ½ºÅ°ÄÚµå
°¡ ¿¬¼ÓÇÏ¿© ÀÖÁö¾ÈÀ¸¹Ç·Î ,¼ýÀÚ°¡ 0AH ¹Ì¸¸ÀÎÁö ¾Æ´ÑÁö ¿¡ µû¶ó º¯È¯À» À§Çؼ ´õÇÏ
´Â ¼ýÀÚ°¡ ´Þ¶ó Áý´Ï´Ù.
+-------------+--------------+--------------+
| ¹®ÀÚ | 0 ~ 9 | A ~ F |
| ¾Æ½ºÅ° ÄÚµå | 30 ~ 39 | 41 ~ 46 |
+-------------+--------------+--------------+
¼ýÀÚ¸¦ Ç¥½ÃÇÒ°æ¿ì¿¡´Â ÀÀÚ¸®¸¦ ¸ÕÀú, ¾Æ·§ÀÚ¸®¸¦ ³ªÁß¿¡ Ç¥½ÃÇÏÁö ¾ÊÀ¸¸é ¾È µË
´Ï´Ù. ±¸ÇÑ ¼ø¼¿Í Ç¥½ÃÇÑ ¼ø¼°¡ ÀÏÄ¡ÇÏÁö ¾ÊÀ» ¶§µµ ÀÖÀ¸¹Ç·Î ,±× ¿Í °°Àº °æ¿ì¿¡´Â
°¢ ÀÚ¸®ÀÇ ¼ýÀÚ¸¦ º¸Á¸ÇØ µÎ´Â °ÍÀÌ ÇÊ¿äÇÕ´Ï´Ù.
PROC¿¡ ÀÇÇÏ ¼ºê·çƾÀÇ ±¸Á¶È:
¼ºê·çƾÀ» º¸´Ù ±¸Á¶ÀûÀ¸·Î Ç¥ÇöÇϱâÀ§Çؼ ÇÁ·Î½Ãµà¾î(procedure)ÀÇ»ç ¸í·É¿¡ ÀÇÇØ
¼ºê·çƾÀÇ ¾ÕµÚ¸¦ ¸í½Ã Çϵµ·Ï ÇÕ´Ï´Ù.
SUB1 PROC
¼ºê·çƾ º»Ã¼
SUB1 ENDP
16Áø¼ö°ªÀÇ ÀԷ¹ý
¿¹Á¦)GETAL.ASM
Å°º¸µå·Î ºÎÅÍ ASCIIÄڵ带 ÀÔ·ÂÇÏ¿© ÀÌÄڵ忡 ÇØ´çÇÏ´Â ASCII¹®ÀÚ Ãâ·Â
CODE SEGMENT
ASSUME CS:CODE
CR EQU 0DH
LF EQU 0AH
;
NEXT: CALL GETAL ; Å°º¸µå·Î ºÎÅÍ µÎ°³ÀÇ ¼ýÀÚ ÀÔ·Â
JC EXITP ;¿¡·¯ÀÌ¸é ³¡³¿
MOV DL.AL
CALL PUTASC ;¾Æ½ºÅ° ÄÚµåÀÇ Ãâ·Â
JMP NEXT
EXITP: MOV AH,4CH ;Á¾·áÇÏ¿© MS-DOS·Îµ¹¾Æ°£´Ù.
INT 21H
;-----------------------
GETAL PROC
MOV AH,1 ; ¿ì¼±ÇÑÀÚ¸¦ ÀÔ·ÂÇÑ´Ù.
INT 21H
CALL CVTAL ; ¾Æ½ºÅ° ÄÚµå ---> ¼ýÀÚ
JC GETEND ;¿¡·¯ÀÌ¸é µÇµ¹¾Æ °£´Ù.
MOV DH,AL ; º¸Á¸
MOV AH,1 ;µÎ¹ø°±ÛÀÚÀÔ·Â
INT 21H
CALL CVTAL --- ¾Æ½ºÅ° ÄÚµå ---> ¼ýÀÚ
JC GETEND ;¿¡·¯ÀÌ¸é µÇµ¹¾Æ°£´Ù.
MOV DL,AL
MOV BH,10H ;»óÀ§ÀÚ¸®¸¦ 10¹è
MOV AL,DH
MUL BH
ADD AL,DL ;ÇÏÀ§ÀÚ¸®¿Í ´õÇÑ´Ù
GETEND: RET
GETAL ENDP
;--------------------------
CVTAL PROC
CMP AL,'0'
JB ERR1 ;ASCII Äڵ尪À¸·ÎºÎÅÍ
CMP AL,'9' 30Hº¸´Ù ÀûÀ»°æ¿ì ERR1
JA SKIP1
SUB AL,'0'
JMP SKIP2
SKIP1: CMP AL,'A' ---+ 'A'~'F'À̸é
JB ERR1 | ¾Æ½ºÅ° ÄÚµåÀÇ
CMP AL,'F' | 'A'¸¦ »©°í
JA ERR1 | 0AH¸¦ ´õÇÑ´Ù.
SUB AL,'A'-OAH -+
SKIP2: CLC ;¿¡·¯°¡¾øÀ¸¸é
JMP CVTEND ij¸®¸¦ Ŭ¸®¾î
ERR1: STC ;¿¡·¯À̸é ij¸®¸¦ ¼¼Æ®
CVTEND: RET
CVTAL ENDP
;---------------------
PUTASC PROC
MOV DH,DL ; DL ¿¡ÀÖ´Â ASCIIÄÚµå 16Áø °ªÀ»Àá±ñ ´ëÇǽÃŲ´Ù.
MOV DL,' ' -+ ; DL¿¡ ÀÖ´Â ¾Æ½ºÅ°ÄÚµå 16Áø°ªÀ» Àá±ñ´ëÇǽÃŲ´Ù.
MOV AH,2 |°ø¹éÃâ·Â
INT 21H -+
MOV DL,DH -+ ; ´ëÇǽÃÄ×´ø°ÍÀ» µÇ ã´Â´Ù
MOV AH,2 |¾Æ½ºÅ°ÄÚµå Ãâ·Â
INT 21H -+
MOV DL,CR -+ ; carriage return À» Ãâ·Â
MOV AH,2 | º¹±Í °³Çà
INT 21H |
MOV DL,LF | ; line feed
MOV AH,2 |
INT 21H -+
RET
PUTASC ENDP
CODE ENDS
END
CVTALÀº ,GETAL·ÎºÎÅÍ È£ÃâµÈ ¼ºê·çƾ¿¡¼ ¾Æ½ºÅ° Äڵ带¼ýÀÚ·Î º¯È¯Çϴ°ÍÀÔ´Ï´Ù.
¸¸ÀÏ ¼ýÀÚÀÌ¿Ü¿¡ ÀÔ·ÂÀÌ ÀÖÀ» ¶§¿¡´Â ij¸®Ç÷¡±×°¡ ¼¼Æ®µÇ¾î µ¹¾Æ¿É´Ï´Ù.
PUTASC ´Â 1¹®ÀÚ¸¦ ¶ç°í ÁöÁ¤µÈ ¾Æ½ºÅ° Äڵ忡 »ó´çÇÏ´Â ¹®ÀÚ¸¦ Ãâ·ÂÇÏ°í ,ÁÙÀ» ¹Ù²Ù
´Â°ÍÀÔ´Ï´Ù.
GETAL¿¡¼´Â ij¸®Ç÷¹±×°¡ ¼¼Æ®µÇ¾î ÀÖ´ÂÁö ¾î¶²Áö¸¦ üũÇÏ¿©,¼¼Æ®µÇ¾îÀÖÀ¸¸é ¿¡·¯·Î
°£ÁÖ ¸ÞÀηçƾÀ¸·Î µ¹¾Æ¿É´Ï´Ù.
¸ÞÀÎ ·çƾ¿¡¼µµ, ¿ª½Ã ij¸®Ç÷¡±×°¡ ¼¼Æ®µÇ¾î ÀÖ´Ù¸é ¿¡·¯·Î °£ÁÖÇÏ°í 󸮸¦ ³¡³À´Ï
´Ù. ij¸® Ç÷¡±×¿¡ ÀÇÇؼ ºÐ±âÇÏ´Â ¸í·ÉÀÌ JC¸í·ÉÀÔ´Ï´Ù.
|
Hit : 22026 Date : 2008/12/13 11:08
|