[汇编] 从键盘输入一个一位数字,然后响铃n声

 

 1 ; multi-segment executable file template.
 2 
 3 data segment
 4 
 5 ends
 6 
 7 stack segment
 8     dw   128  dup(0)
 9 ends
10 
11 code segment
12 start:
13 ; set segment registers:
14     mov ax, data
15     mov ds, ax
16     mov es, ax
17 
18     ; add your code here 
19     BEGIN:        
20     MOV    AH, 1            ;从键盘输入一个字符的DOS调用AL存放输入的字符
21     INT        21H
22     SUB        AL, '0'     ;输入的是字符需要转化为数字
23     JB        STOP                    ;输入字符<'0'吗?;below
24     CMP    AL, 9                         ;输入字符>'9'吗?;above
25     JA        STOP
26     CBW                             ;AL扩展到AH
27     MOV    CX, AX                        ;响铃次数N
28     JCXZ    STOP
29         BELL:        
30         MOV    DL, 07H                    ;准备响铃
31         MOV    AH, 2                    ;显示一个字符的DOS调用,实际为响铃
32         INT        21H
33         LOOP    BELL
34     STOP:        RET
35 
36     ; wait for any key....    
37     mov ah, 1
38     int 21h
39     
40     mov ax, 4c00h ; exit to operating system.
41     int 21h    
42 ends
43 
44 end start ; set entry point and stop the assembler.

 

posted @ 2014-04-03 14:57  beautifulzzzz  阅读(2308)  评论(0编辑  收藏  举报