110 likes | 256 Vues
80x86 assembly language program structure and simple I/O. Assistant : 蘇建仲 (Su Jain-Zhong) LAB : ISMP LAB Tel : 62530-58 E-Mail : sujz@csie.ncku.edu.tw. INT 21H(DOS 插斷 ). 輸出字元 AH=02H ; DL= 要輸出的字元
E N D
80x86 assembly languageprogram structure and simple I/O Assistant : 蘇建仲(Su Jain-Zhong) LAB : ISMP LAB Tel : 62530-58 E-Mail : sujz@csie.ncku.edu.tw
INT 21H(DOS 插斷) • 輸出字元 • AH=02H ; DL=要輸出的字元 • PUTCHAR MACRO CHAR MOV DL,CHAR MOV AH,02H INT 21H ENDM
INT 21H(DOS 插斷)(Cont.) • 輸出字串 • AH=09H ; DS:DX=欲顯示字串起始位置 • 以“$”結束 • PRINT MACRO BUFF LEA DX,BUFF MOV AH,09H INT 21H ENDM
INT 21H(DOS 插斷)(Cont.) • 輸入字元 • AH=08H • READCHAR MACRO MOV AH,08H INT 21H ENDM • AL 輸入的字元
INT 21H(DOS 插斷)(Cont.) • 輸入字串 • AH=0AH ; DS:DX 緩衝區起始位置 • INPUT MACRO BUFF LEA DX,BUFF MOV AH,0AH INT 21H ENDM 最大輸入字元 實際輸入字元 DS:DX 輸入字串
An Example • Reference progam2-1
MACRO TEST MACRO STR,X………. L1: ……….. LOOP L1………. ENDM • Problem • TEST ASC1,X ……………TEST ASC2,Y L1: …………. LOOP L1…………. L1: ………… LOOP L1…………. • Solve error TEST MACRO STR,X LOCAL L1………. L1: ……….. LOOP L1………. ENDM
MARCO Lib • Reference program2-2
Subroutine • Parameter passing • By register • By data segment • Reference example program2-3,4 • Calling External Program • Calling program: EXTRN var: type • Called program: PUBLIC var • Type:BYTE,WORD,DWORD
Subroutine link in diff. files • PUBLIC subroutine name • EXTRN subroutine name:FAR
How to use assembler • Assembly Tool • masm asm_file.asm • link obj_file.obj [+ obj_file2.obj] ….. • ml asm_file.asm + asm_file2.asm • Debug tool • debug exe_file.exe • codeview exe_file.exe