T
T
Type Programmer2018-06-21 19:46:40
assembler
Type Programmer, 2018-06-21 19:46:40

Assembler how to work with the speaker directly?

I am writing a small OS, purely to teach assembler. In the OS, I cannot use dos interrupts, so the question is how to work with the speaker, for example, how to make it beep. It seems that there is Google, but it’s somehow difficult to show it all and it’s tricky, I just realized that 60h seems to be responsible for the speaker.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-06-21
@MegaCraZy6

On bare metal you will have to use ports

MOV     DX, 2000         ; Number of times to repeat whole routine.

MOV     BX, 1            ; Frequency value.

MOV     AL, 10110110B    ; The Magic Number (use this binary number only)
OUT     43H, AL          ; Send it to the initializing port 43H Timer 2.

NEXT_FREQUENCY:          ; This is were we will jump back to 2000 times.

MOV     AX, BX           ; Move our Frequency value into AX.

OUT     42H, AL          ; Send LSB to port 42H.
MOV     AL, AH           ; Move MSB into AL  
OUT     42H, AL          ; Send MSB to port 42H.

IN      AL, 61H          ; Get current value of port 61H.
OR      AL, 00000011B    ; OR AL to this value, forcing first two bits high.
OUT     61H, AL          ; Copy it to port 61H of the PPI Chip
                         ; to turn ON the speaker.

MOV     CX, 100          ; Repeat loop 100 times
DELAY_LOOP:              ; Here is where we loop back too.
LOOP    DELAY_LOOP       ; Jump repeatedly to DELAY_LOOP until CX = 0


INC     BX               ; Incrementing the value of BX lowers 
                         ; the frequency each time we repeat the
                         ; whole routine

DEC     DX               ; Decrement repeat routine count

CMP     DX, 0            ; Is DX (repeat count) = to 0
JNZ     NEXT_FREQUENCY   ; If not jump to NEXT_FREQUENCY
                         ; and do whole routine again.

                         ; Else DX = 0 time to turn speaker OFF

IN      AL, 61H          ; Get current value of port 61H.
AND     AL, 11111100B    ; AND AL to this value, forcing first two bits low.
OUT     61H, AL          ; Copy it to port 61H of the PPI Chip
                         ; to turn OFF the speaker.

Here is a detailed description of how it works.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question