/***************通过调用(INT 21H)表中的01h号功能号从键盘输入一个字符并回显到视频显示器上*****************/
DATAS SEGMENT ;此处输入数据段代码 DATAS ENDS STACKS SEGMENT ;此处输入堆栈段代码 STACKS ENDS CODES SEGMENT ASSUME CS:CODES,DS:DATAS,SS:STACKS START: MOV AX,DATAS MOV DS,AX ;此处输入代码段代码 MOV AH,1 INT 21H MOV AH,4CH INT 21H MOV AH,4CH INT 21H CODES ENDS END START
/***************输入姓名学号换行显示*****************/
DATA SEGMENT STRING DB 'xingming',0DH,0AH,'xuehao','$' DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA BEGIN: MOV AX,DATA MOV DS,AX MOV AH,09H LEA DX,STRING INT 21H MOV AH,4CH INT 21H CODE ENDS END BEGIN
/***************输入一个字母显示下一个字母*****************/
Code Segment Assume CS:Code,DS:Code KBEsc equ 1BH PromptStr DB 'Please input a letter(Esc to exit): $' Start: push cs pop ds ;使数据段与代码段同段 Begin: lea dx,PromptStr mov ah,9 int 21h mov ah,8 int 21h cmp al,KBEsc jz Exit_Proc mov cx,1 mov dl,al mov ah,2 Disp_Chr: inc dl int 21h loop Disp_Chr mov dl,13 int 21h mov dl,10 int 21h jmp Begin Exit_Proc: mov ah,4ch ;结束程序 int 21h Code ENDS END Start ;编译到此结束
/***************8位16进制加法*****************/
DATA SEGMENT STRING DB 'The result of 13579BDFH + 02468ACEH is:','$' XL DW 9BDFH XH DW 1357H YL DW 8ACEH YH DW 0246H DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START: MOV AX,DATA MOV DS,AX MOV DX,OFFSET STRING ;显示信息 MOV AH,09H INT 21H MOV AX,XL ADD AX,YL ;Y低位数值与X低位数值相加 MOV BX,AX ;BX中存放结果的低16位 MOV AX,XH ADC AX,YH ;Y高位数值与X高位数值相加 MOV CX,AX ;CX中存放结果的高16位 ;显示结果 MOV DH,CH CALL SHOW MOV DH,CL CALL SHOW MOV DH,BH CALL SHOW MOV DH,BL CALL SHOW MOV AX,4C00H INT 21H SHOW PROC NEAR PUSH DX PUSH AX MOV AL,DH AND AL,0F0H MOV DL,CL;必须把cl暂存dl里,否则下次对clcall show时会把cl变为4,而不是原来存的数 MOV CL,4 SHR AL,CL MOV CL,DL CMP AL,0AH JB C2 ADD AL,07H C2: ADD AL,30H MOV DL,AL;show character MOV AH,02H INT 21H MOV AL,DH AND AL,0FH;取低4位 CMP AL,0AH JB C3 ADD AL,07H C3: ADD AL,30H MOV DL,AL;show character MOV AH,02H INT 21H POP AX POP DX RET SHOW ENDP CODE ENDS END START