¨Æ¹ê¤W¡A¦³³\¦h¤½¥q³£¦³½æµ{¦¡®w¡A¯S§O¬O C/C++ »y¨¥¡Aµ{¦¡®w¬O«Ü«nªº¡C¦b³o¤@³¹ùØ¡A§Ú̦ۤv¤]¥i¥H¦Û»s¤@Óµ{¦¡®w¡C¨BÆJ¦p¤U¡G
byte public 'code'³o¸Ìªº¡ypublic¡z©M¤Wzªº¡ypublic¡z(¤½¥Îªº) ¨Ã¤£¬Û¦P¡A¸Ô²Ó±¡§Î¤U¤@³¹»¡©ú¡A±z¥ý§â¥¦·í¦¨¬O¤@Ӽ˪O§a¡I
¥H¤U¬O print_bl_hex °Æµ{¦¡ªºì©lÀÉ¡A±N¥¦¼g¦n«á¦sÀɬ°PNT_BL.ASM¡G
;*************************************** code segment byte public 'code' assume cs:code,ds:code public print_bl_hex ;--------------------------------------- ;¦L¥X BL ªº¤Q¤»¶i¦ì¼Æ ;¿é¤J¡GBL ;¿é¥X¡GÅã¥ÜBLªº¤Q¤»¶i¦ì¼Æ ;³Æµù¡GAX¡BCL¡BDX¤§È·|§ïÅÜ print_bl_hex proc near mov cl,4 rol bl,cl call print_4_bits rol bl,cl print_4_bits: mov dx,bx and dl,0fh add dl,30h cmp dl,3ah jb print add dl,7 print: mov ah,2 int 21h ret print_bl_hex endp ;--------------------------------------- code ends ;*************************************** end print_bl_hex
¥H¤U¬O±N print_bx_hex °Æµ{¦¡¡A¥¦ªº¥\¥Î¬O§â BX ªº¤º®e¥H¤Q¤»¶i¦ìªº¤è¦¡Åã¥Ü¦b¿Ã¹õ¤W¡A©³¤U¬Oì©lµ{¦¡¦Cªí¡A±N¥¦¦s¦¨ PNT_BX.ASM¡G
;*************************************** code segment byte public 'code' assume cs:code,ds:code public print_bx_hex ;--------------------------------------- ;¥Øªº¡G¦b»È¹õ¤W¦L¥X BX ¤§¤Q¤»¶i¦ìÈ ;¿é¤J¡GBX ;¿é¥X¡G¦L¥X BX ªº¤Q¤»¶i¦ì¼Æ ;³Æµù¡G print_bx_hex proc near mov cl,4 rol bx,cl call print_4_bits rol bx,cl call print_4_bits rol bx,cl call print_4_bits rol bx,cl print_4_bits: mov dx,bx and dl,0fh add dl,30h cmp dl,3ah jb print add dl,7 print: mov ah,2 int 21h ret print_bx_hex endp ;--------------------------------------- code ends ;*************************************** end print_bx_hex
¦]¬°³o¨âӰƵ{¦¡±Nn¥[¤Jµ{¦¡®w¡A¦¹®É¨Ã¤£ª¾¹Dn³Q¨ºÓ¥Dµ{¦¡©I¥s¡A¥u¦³·í LINK.EXE §â°Æµ{¦¡»P¥Dµ{¦¡³sµ²®É¡A¤~¯à¨Ì¹ê»Ú±¡§Î±µ¦b¥Dµ{¦¡¤§«á¡A©Ò¥H¤£¥²¦b³o¨âӰƵ{¦¡¥[¤W¡yorg 100h¡z¡AµM«á¶i¦æ¥H¤U¾Þ§@¡G
H:\HomePage\SOURCE>..\masm50\masm pnt_bl; [Enter]
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved.
51578 + 365350 Bytes symbol space free
0 Warning Errors
0 Severe Errors
H:\HomePage\SOURCE>..\masm50\lib [Enter] Microsoft (R) Library Manager Version 3.07 Copyright (C) Microsoft Corp 1983-1987. All rights reserved. Library name: myasmlib [Enter] Library does not exist. Create?y [Enter] Operations: +pnt_bl [Enter] List file: myasmlib.lst [Enter]®e§Ú¦b¦¹¸ÑÄÀ¡G·í LIB.EXE °õ¦æ«á¡A¨Ì¦¸·|°Ý§An³B²zªºµ{¦¡®w¡A¤p¤ì°¸´N¿é¤J¦Û¤vªºµ{¦¡®wÀɦW¡AMYASMLIB¡A°ÆÀɦW¥i¥H¤£¿é¤J¡ALIB.EXE ·|¦Û°Ê¥[¤W .LIB §@¬°°ÆÀɦW¡C¦pªG LIB §ä¤£µÛ¡A´N·|°Ý§A¬O§_n«Ø¥ß¡A·íµM¤p¤ì°¸¦^µª y (yes ¤§·N)¡C±µ¤U¨Ó¥X²{¡yOperations:¡z¡A·N«ä¬O°Ý§An¹ï MYASMLIB.LIB °µ¤°»ò¨Æ¡C¤p¤ì°¸¿é¤J¡y+pnt_bl¡z·N«ä¬O¦b³oÓµ{¦¡®w¥[¤J°Æµ{¦¡ pnt_bl¡A·íµM¦pªG§A·Q§R°£°Æµ{¦¡¡A´N¥Î¡y-¡z¸¹¡Q¦b³o¸Ì¿é¤Jªº¨ä¹ê¬O¥ØªºÀɪºÀɦW¡APNT_BL.OBJ¡ALIB ·|±N¸Ó OBJ Àɪº°Æµ{¦¡¦Û°Ê¦a¥[¤Jµ{¦¡®w¤º¡C¦A±µ¤U¨Ó LIB ·|°Ý§An²£¥Í¦CªíÀɪº¦W¦r¡ALIB ©Ò²£¥Íªº¦CªíÀɮ׬O¤@ӯ¤å¦rÀÉ¡A¥i¥HÅý¨Ï¥ÎªÌª¾¹D³oÓµ{¦¡®w¤º¦³¤°»ò°Æµ{¦¡¡C
H:\HomePage\SOURCE>type myasmlib.lst [Enter]
PRINT_BL_HEX......pnt_bl
pnt_bl Offset: 00000010H Code and data size: 1eH
PRINT_BL_HEX
H:\HomePage\SOURCE>..\masm50\masm pnt_bx; [Enter] Microsoft (R) Macro Assembler Version 5.00 Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved. 51578 + 365350 Bytes symbol space free 0 Warning Errors 0 Severe Errors H:\HomePage\SOURCE>..\masm50\lib [Enter] Microsoft (R) Library Manager Version 3.07 Copyright (C) Microsoft Corp 1983-1987. All rights reserved. Library name: myasmlib [Enter] Operations: +pnt_bx [Enter] List file: myasmlib.lst [Enter] Output library: myasmlib [Enter] H:\HomePage\SOURCE>
·í LIB µo²{¨Ï¥ÎªÌ¿é¤Jªºµ{¦¡®w¤w¦s¦b¡ALIB ·|°Ýnªºµ{¦¡®w¦WºÙ(¥Õ¦â³¡¥÷)¡AY±zªº¦^µª©M«e±ªºµ{¦¡®w¦WºÙ¬Û¦Pªº¸Ü¡A¨ºìµ{¦¡®w´N·|³Q¨ú¥N¡C©³¤U¬Ý¬Ý¦Cªí¡G
H:\HomePage\SOURCE>type myasmlib.lst [Enter]
PRINT_BL_HEX......pnt_bl PRINT_BX_HEX......pnt_bx
pnt_bl Offset: 00000010H Code and data size: 1eH
PRINT_BL_HEX
pnt_bx Offset: 000000a0H Code and data size: 28H
PRINT_BX_HEX
H:\HomePage\SOURCE>
cr equ 0dh ;01 ±`¼Æ¡Aªí¥ÜÂk¦ì¦r¤¸
lf equ 0ah ;02 ±`¼Æ¡Aªí¥Ü´«¦æ¦r¤¸
;***************************************
code segment public 'code'
assume cs:code,ds:code
extrn print_bl_hex:near ;06 «Å§i¥~³¡°Æµ{¦¡
org 100h
;---------------------------------------
start: jmp short begin
msg1 db cr,lf,cr,lf,'Scan code:$'
msg2 db cr,lf,'ASCII character:$'
begin: mov ah,0
int 16h
mov bx,ax ;11 BH=±½´y½X¡ABL=ASCII½X
mov dx,offset msg1
mov ah,9
int 21h
xchg bh,bl ;15 ¥æ´««á¡ABL=±½´y½X¡ABH=ASCII½X
call print_bl_hex ;16 ¦L¥X BL
mov dx,offset msg2
mov ah,9
int 21h
mov dl,bh
mov ah,2
int 21h
cmp bl,1 ;23 Àˬd¬O§_«ö¤UEscÁä
jne start ;24 Y¬°1¡Aªí¥Ü«ö¤UEscÁä¡A«hµ²§ô
mov ax,4c00h
int 21h
;---------------------------------------
code ends
;***************************************
end start
±µ¤U¨Ó¡A¦b DOS ¼Ò¦¡²ÕĶ PNTKYSC.ASM¡A¨Ã³sµ²¦Û»sªºµ{¦¡®w¡G
H:\HomePage\SOURCE>..\masm50\masm pntkysc; [Enter] Microsoft (R) Macro Assembler Version 5.00 Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved. 51536 + 418704 Bytes symbol space free 0 Warning Errors 0 Severe Errors H:\HomePage\SOURCE>..\masm50\link pntkysc [Enter] Microsoft (R) Personal Computer Linker Version 2.40 Copyright (C) Microsoft Corp 1983, 1984, 1985. All rights reserved. Run File [PNTKYSC.EXE]:[Enter] List File [NUL.MAP]:[Enter] Libraries [.LIB]: myasmlib [Enter] Warning: no stack segment H:\HomePage\SOURCE>..\masm50\exe2bin pntkysc pntkysc.com [Enter] H:\HomePage\SOURCE>ÁöµM¦b PNTKYSC.ASM ¤¤¨Ã¨S¦³ print_bl_hex °Æµ{¦¡¡A¦ý¬O¦]¬°¤@¶}©l´N¤w¸g±N¥¦«Å§i¬°¡y¥~³¡¡zªñµ{°Æµ{¦¡¡A¬G²ÕĶ®É (masm pntktsc;)¨Ã¤£·|µo¥Í¿ù»~¡A¦Ó³sµ²®É¡A¿é¤J§t¦³ print_bl_hex °Æµ{¦¡ªºµ{¦¡®w (¬õ¦â³¡¥÷)¡ALINK ·|±Nì©lµ{¦¡»Pµ{¦¡®w³s°_¨Ó¦ÓÅܦ¨¥i°õ¦æÀÉ¡C§ÚÌ°õ¦æ pntkysc.com ¬Ý¬Ý§a¡I
H:\HomePage\SOURCE>pntkysc [Enter]
Scan code:10 («ö¤U Q Áä)
ASCII character:q
Scan code:10 («ö¤U Q Áä¤Î Shift Áä)
ASCII character:Q
Scan code:44 («ö¤U F10 Áä)
ASCII character:
Scan code:01 («ö¤U Esc Áäµ²§ô)
ASCII character:.
H:\HomePage\SOURCE>
PUBLIC ±`±`©M EXTRN °t¦X¨Ï¥Î¡CEXTRN ªº·N«ä¬O¡y¥~³¡¡zªº¡A·í MASM.EXE ¬Ý¨ì³Q«Å§i¥~³¡ªºÅܼơB°Æµ{¦¡©Î¼Ð°O®É¡AÁöµM¦bµ{¦¡¤¤§ä¤£¨ì¡A¤]¤£·|¥X²{¿ù»~¡A¦Ó·|§â¬ÛÃö¸ê°T¼g¶i¥ØªºÀÉ¡Aµ¥¨ì³sµ²®É·|´M§ä³Q³sµ²ªºµ{¦¡®w©Î¥ØªºÀÉ¡A¦pªG§ä¨ì´N¤£·|²£¥Í¿ù»~¡C¦]¬°¨Ï¥Î¥~³¡ªº¡yªFªF¡z¬OÅܼơB¼Ð°OÁÙ¬O°Æµ{¦¡ªº³B²z¤è¦¡¤£¦P¡A©Ò¥H¥²¶·¦b EXTRN «á±§i¶D MASM.EXE ¬O¨º¤@ºØ¡C
EXTRN ªº»yªk¬O¡G
EXTRN °Æµ{¦¡¦W:©I¥s¤è¦¡©I¥s¤è¦¡¥i¥H¥Î near ©Î far¡C
EQU ¬O¡yµ¥©ó¡zªº·N«ä¡C»yªk¬O
±`¼Æ¦W equ ¼ÆÈ
²ÕĶ¾¹·|±Nì©lµ{¦¡¤¤©Ò¦³ªº±`¼Æ¦W§ó´«¦¨ EQU «áªº¼ÆÈ¡C¦b³oÓµ{¦¡ªº²Ä¤@¦æ±N cr ³]©w¬°¤Q¤»¶i¦ìªº 0D (¤Q¶i¦ìªº 12 )¡A¦Ó«á²ÕĶ¾¹¬Ý¨ìì©lµ{¦¡¤¤ªº cr¡A³£·|´«¦¨ 12¡A¦Ó¥B¦bµ{¦¡°õ¦æ®É³£µLªk§ó§ï¡A©Ò¥H cr ¬O¤@Ó±`¼Æ¡C
¨º±z¥i¯à·|°Ý¬°¦ó¤£ª½±µ¼g 12 ´N¦n¤F¡AÁÙn³]¤@Ó±`¼Æ¡A¤£¬O¦h¦¹¤@Á|¶Ü¡Hì¨Ó¡A¦pªGµ{¦¡¨Ï¥Î¤@¬q®É¶¡«ánק令¨ä¥L¼Æ ªº¸Ü¡A¥Î equ °²«ü¥O¡A¥u»Ýnקï¤@¦æ¡A¦A«·s²ÕĶ§Y¥i¡Q°²¦p¤£¥Î equ¡A¨º´N±o´M§äì©lµ{¦¡¤@¦æ¤@¦æ¬Ý¡A±z»¡¨º¤@ºØ¤è«K©O¡H
©³¤U§ÚÌ¨Ó¬Ý¬Ý LINK.EXE ¬O«ç¼Ë§â°Æµ{¦¡¥[¨ì¥Dµ{¦¡¤§«á©O¡Hì¨ÓÃöÁä¦b©ó°Æµ{¦¡°Ï¬q©w¸qªº¦a¤è¡G
code segment byte public 'code'
·í°²«ü¥O segment ¤§«á±µ¤W BYTE «hªí¥Ü°_©l¦ì§}¬O¥H¦ì¤¸²Õ¬°³æ¦ì¡F¥t¥~ÁÙ¦³¤@Ó¸û±`¥Îªº¬O¡yPARA¡z¡Aªí¥Ü¥H¤@¡y¸`¡z¬°°_©l¦ì§}¡A©Ò¿×¤@¸`´N¬O 16 Ӧ줸²Õ¡A´«¥y¸Ü»¡¨ä°_©l¦ì§}ªº³Ì§C¥|Ӧ줸§¡¬°¹s¡CÁÙ¦³¨ä¥L¸û¤Ö¥Îªº¿ï¶µ½Ð°Ñ¦Ò²Ä 11 ³¹¡C©³¤U§Ú̥ΠDEBUG ¸ü¤J PNTKYSC.COM Æ[¹î¬Ý¬Ý¡C
H:\HomePage\SOURCE>debug pntkysc.com [Enter] -t [Enter] ¡÷¸õ¹L¸ê®Æ AX=0000 BX=0000 CX=006B DX=0000 SP=FFFE BP=0000 SI=0000 DI=0000 DS=1F91 ES=1F91 SS=1F91 CS=1F91 IP=0124 NV UP EI PL NZ NA PO NC 1F91:0124 B400 MOV AH,00 -u 124 158 [Enter] 1F91:0124 B400 MOV AH,00 1F91:0126 CD16 INT 16 1F91:0128 8BD8 MOV BX,AX 1F91:012A BA0201 MOV DX,0102 1F91:012D B409 MOV AH,09 1F91:012F CD21 INT 21 1F91:0131 86FB XCHG BH,BL 1F91:0133 E81700 CALL 014D ¡÷©I¥s print_bl_hex °Æµ{¦¡ 1F91:0136 BA1101 MOV DX,0111 1F91:0139 B409 MOV AH,09 1F91:013B CD21 INT 21 1F91:013D 8AD7 MOV DL,BH 1F91:013F B402 MOV AH,02 1F91:0141 CD21 INT 21 1F91:0143 80FB01 CMP BL,01 1F91:0146 75B8 JNZ 0100 1F91:0148 B8004C MOV AX,4C00 1F91:014B CD21 INT 21 ¡÷¥Dµ{¦¡µ²§ô 1F91:014D B104 MOV CL,04 ¡÷°Æµ{¦¡¶}©l 1F91:014F D2C3 ROL BL,CL 1F91:0151 E80200 CALL 0156 1F91:0154 D2C3 ROL BL,CL 1F91:0156 8BD3 MOV DX,BX 1F91:0158 80E20F AND DL,0F
±z¥i¥H¸Õ¸Õ¡A§â PNT_BL.ASM ¤¤ªº¡ycode segment byte¡z§ï¦¨¡ycode segment para¡z¬Ý¬Ý¡A·|¦³¤°»òµ²ªG¡H