NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: nobody on February 01, 2005, 09:17:19 AM
-
Hi
I want to produce a beep with int 10h
and function 0eh in Linux.
I try to print ascii 7 which is the bel
and everytime I run the file - I get a Segmentation fault...
I dont understand, it should be fairly simple
Here's my code:
section .data
section .text
global _start
_start:
mov ah,0eh ; Write Text in Teletype Mode
mov al,7 ; the bell ascii
mov bl,0 ; foreground pixel color
mov bh,0 ; page number
int 10h ; Call the kernel
mov eax,1 ; The system call for exit (sys_exit)
mov ebx,0 ; Exit with return code of 0 (no error)
int 80h
that's it...
Here's how i compile it, in case I make the mistake here:
#nasm -f elf beep.asm
#ld -s -o beep beep.o
and when i run it:
#./beep
I get:
Segmentation fault
Please help...
10x
-
I'm new to this myself, but I think BIOS interrupts can't be accessed in protected mode. Not sure on it, though..
-
Yes, you can not access to BIOS interruptions because
the OS does not use a real mode interrupt vector.
You would have to switch to kernel mode and change
the IDT (Interrupt Descriptor Table). Is very complex
and danger.
Maybe, write a kernel module to add a new entry in
the IDT.
-----
nmt
-
Yeah... the problem with int 10h (or any other real mode interrupt) is that it's 16-bit code, and there's no way it'll run with the processor in 32-bit mode.
There's a sys_vm86 old (113), and a sys_vm86 (166), used by dosemu, I think, that might allow you to do it. I have *no* idea how to use these - if anyone has an example, please post!
Sending ascii 7 (BELL) to stdout in the usual way (sys_write) beeps the speaker, if that'll satisfy you...
If you want a "fancier beep", I've got an example that gets permission to diddle the ports with sys_ioperm, and beeps the speaker (in a "tune", of sorts) using ports... I can post that, if anyone's interested.
Here's the "easy way"...
Best,
Frank
;--------------------------
; nasm -f elf beep.asm
; ld -s -o beep beep.o
global _start
section .text
_start:
mov eax,4 ; sys_write
mov ebx,1 ; stdout
mov ecx,beep ; buffer
mov edx, 1 ; length
int 80h
mov eax,1 ; sys_exit
xor ebx, ebx ; I didn't see an error, did you see an error? :)
int 80h
;section .data
; hell, put it in the code section...
beep db 7 ; "BELL"
;--------------------------