TASM 中的 BEL 功能

问题描述 投票:0回答:1

我有这个问题:

从键盘读取两位十进制数(00 到 12 之间)。

“大本钟”时钟会按所读到的数字响多少次。

输入00将导致程序结束。否则,系统会要求您输入新时间。

提示:要发出声音,请参阅称为 BEL" 的 ASCII 字符

在 TASM。

...我写了这段代码,但它不起作用..

.model small
.stack 100h

.data
    number_db  ?           ; Variable to store the entered number

.code
main proc
    mov ax, @data          ; Initialize the data segment
    mov ds, ax

    ; Displaying the input message for the number
    mov ah, 9
    lea dx, prompt
    int 21h

input_loop:
    ; Reading the number from the keyboard
    mov ah, 1
    int 21h
    sub al, '0'            ; Conversion from ASCII character to numeric value
    cmp al, 0              ; Check if 00 is entered to exit the program
    je exit_program
    cmp al, 12             ; Check if the entered number is valid (between 00 and 12)
    ja input_error

    ; Saving and displaying the entered number
    mov number, al
    add number, '0'        ; Conversion from numeric value to ASCII character for display
    mov ah, 2
    mov dl, number
    int 21h

    ; Ringing the "Big Ben" clock
    mov cl, al             ; Save the number of chimes
    mov bx, cl             ; Counter for the number of chimes

    sound_loop:
        mov ah, 0Eh        ; Displaying the BEL character (ASCII 7)
        mov al, 7
        int 10h            ; Call function to display the BEL character

        dec bx             ; Decrease the counter
        jnz sound_loop     ; Continue the sound as long as the counter is not zero

    jmp input_loop         ; Continue reading another number

input_error:
    ; Displaying an error message for an invalid number
    mov ah, 9
    lea dx, error_message
    int 21h
    jmp input_loop         ; Return to read another number

exit_program:
    mov ah, 4Ch            ; Terminate the program
    int 21h
main endp

; Data section
prompt db 'Enter a number between 00 and 12 (or 00 to exit): $'
error_message db 'The entered number is not valid! Please enter another number: $'
number db 0

end main

assembly tasm
1个回答
0
投票

您的错误描述

这不起作用...

有点宽泛,您的代码可能包含其他错误...

...但是可以肯定的是你不能调用视频中断10h来发出BELL声音。你最好使用MS-DOS中断21h来输出字符:

sound_loop:
    mov ah, 02h     ; Displaying...
    mov dl, 07h     ; ...the BEL character (ASCII 7)  
    int 21h         ; Call DOS function to display the BEL character
...

这是一次输出一个字符的标准功能

© www.soinside.com 2019 - 2024. All rights reserved.