code segment assume cs:code start: mov ah,01h;调用DOS中断的01号功能,输入字符,存储于al中 int 21h cmp al,'0';输入字符存在al寄存器中,使其与0比较 jb start;如果其asc码比'0'小,则继续输入 cmp al,'9';与9比较 ja start;如果比输入的asc码比'9'还大,则继续输入 clc;CF标志清零 rcr al,1;将al的低1位右移出道cf中 jnc EVE;如果cf!=1,则判断此数为偶数,则跳转到偶数的操作 mov al, 31h;如果没有跳转,则为奇数,则输出字符为1,及其asc码为31H jmp DISP;强制跳转到输出分支 EVE: mov al,30h;0的asc码为30H DISP: mov ah,02h;调用DOS中断的02H功能,实现输出字符 mov dl,al;输入字符即为al,将其赋值给dl寄存器,输出 int 21h mov ax,4c00h int 21h code ends end start
代码不足:字符输入输出显示格式比较丑陋,且不友好,可以考虑添加回车加换行等。 ———————————————————————————————— 题目要求:利用汇编代码实现一个dos功能菜单题目分析:主要难点在于字符串输出,字符的输入;解决办法,可以调用dos中断的09H功能输出字符串,01H号功能输入字符。代码实现:data segment MENU db 'Action: ',0dh,0ah;提示信息准备
db 'This is a washing machine!',0dh,0ah db 'You can use the MENU to choose function!',0dh,0ah db '----------------------------------------',0dh,0ah db '1.open the cap of washing machine ! ',0dh,0ah db '2.close the cap !',0dh,0ahdb '3.set washing time !' ,0dh,0ah db '4.start the washing machine !',0dh,0ah db '5.stop the washing machine !',0dh,0ah
db '6.quit !',0dh,0ah db '----------------------------------------',0dh,0ah,'$'
INPUT db 'input your choose: $'
F1 db 0dh,0ah,'cap opened, clothes puted in !',0dh,0ah,'$'F2 db 0dh,0ah,'cap closed !',0dh,0ah,'$'F3 db 0dh,0ah,'set washing time to 5 min!',0dh,0ah,'$'F4 db 0dh,0ah,'washing machine has started',0dh,0ah,'$'F5 db 0dh,0ah,'succeed in washing the clothes !',0dh,0ah,'$'F6 db 0dh,0ah,'quitd! thanks to using this washing machine !',0dh,0ah,'$'F7 db 0dh,0ah,'no this choose ,please reinput your choose !',0dh,0ah,'$'