作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在汇编程序内部发出哔哔声。
喜欢
beep()
section .data
cmp_BLANK: db 0x0a
cmp_interr: db "error, You have typed in a non-Integer Character!", 0x0a
cmp_interrlen: equ $-cmp_interr
cmp_buffer: times 9 db 0x00
cmp_beep: db 0x07
section .bss
section .text
global _start
_start:
call func_main
mov eax, 1
mov ebx, 0
int 80h
func_main:
mov eax, 4
mov ebx, 1
mov ecx, cmp_beep
mov edx, 1
int 80h
ret
最佳答案
好的,首先是引用文档:http://www.cs.binghamton.edu/~reckert/220/8254_timer.html
以C实现为例:https://github.com/torvalds/linux/blob/master/drivers/input/misc/pcspkr.c#L49
这是GNU asm中的提示音代码:
# send "set tune" command
movb $0xB6, %al
outb %al, $0x43
# nanosleep to let the IO complete
movl $0x1000, %eax
1: subl $1, %eax
cmpl $0, %eax
jne 1b
# set 220Hz, 0x152F == 1193180 / 220
movb $0x2F, %al
outb %al, $0x42
# nanosleep
movl $0x1000, %eax
1: subl $1, %eax
cmpl $0, %eax
jne 1b
movb $0x15, %al
outb %al, $0x42
# nanosleep
movl $0x1000, %eax
1: subl $1, %eax
cmpl $0, %eax
jne 1b
# turn on the speaker
inb $0x61, %al
movb %al, %ah
orb $0x3, %al
outb %al, $0x61
# sleep about 1 sec
movl $0x30000000, %eax
1: subl $1, %eax
cmpl $0, %eax
jne 1b
# turn off the speaker
movb %ah, %al
andb $0xfc, %al
outb %al, $0x61
该代码无法在用户空间程序中立即运行,因为内核禁止写入IO端口。为了允许该代码还需要
ioperm
调用:
ioperm(0x42, 32, 1)
并使用sudo运行。请参阅此
gist中的完整工作示例。
关于linux - 如何在Linux-Assembler中发出提示音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41165267/
我是一名优秀的程序员,十分优秀!