x86 Assembly

Moderators: None (Apply to moderate this forum)
Number of threads: 4556
Number of posts: 16011

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
assembly and sound Posted by marie1no on 10 Dec 2004 at 7:01 AM
Hi!

Do somebody have a link for some codes so I can make music in assebley?

Report
Re: assembly and sound Posted by jeffleyda on 10 Dec 2004 at 7:59 AM
: Hi!
:
: Do somebody have a link for some codes so I can make music in assebley?
:
:

What operating system?
What hardware?
Do you want to just play music on something like a soundblaster, or actually MAKE music like with a midi editor?

Assembly is a very detail oriented language. Your questions need to be likewise.


(shameless self plug)
Here's links to 2 .wav players that work in DOS:
http://www.programmersheaven.com/search/download.asp?FileID=30034
http://www.programmersheaven.com/search/download.asp?FileID=23237

-jeff!
Report
Re: assembly and sound Posted by marie1no on 10 Dec 2004 at 11:46 AM
: : Hi!
: :
: : Do somebody have a link for some codes so I can make music in assebley?
: :
: :
:
: What operating system?
: What hardware?
: Do you want to just play music on something like a soundblaster, or actually MAKE music like with a midi editor?
:
: Assembly is a very detail oriented language. Your questions need to be likewise.
:
:
: (shameless self plug)
: Here's links to 2 .wav players that work in DOS:
: http://www.programmersheaven.com/search/download.asp?FileID=30034
: http://www.programmersheaven.com/search/download.asp?FileID=23237
:
: -jeff!
:
Hi!

Thanks a lot for replying, I'll try to make it clearer. I just got a home-exame at school, where the teacher want us to get the computer to play an easy song. For that I need some notes (A, C, E osv) like playing a gitar? I know this must sound very crazy but I realy need help.
We are going to make it on a boot-disket, the computer have intel-cpu and the os is XP(but do the os mather?)
I'll also admitt that I'm verry new to assembly so please don't tell me that it's to dificult.


Report
Re: assembly and sound Posted by CroW on 10 Dec 2004 at 3:09 PM
: : : Hi!
: : :
: : : Do somebody have a link for some codes so I can make music in assebley?
: : :
: : :
: :
: : What operating system?
: : What hardware?
: : Do you want to just play music on something like a soundblaster, or actually MAKE music like with a midi editor?
: :
: : Assembly is a very detail oriented language. Your questions need to be likewise.
: :
: :
: : (shameless self plug)
: : Here's links to 2 .wav players that work in DOS:
: : http://www.programmersheaven.com/search/download.asp?FileID=30034
: : http://www.programmersheaven.com/search/download.asp?FileID=23237
: :
: : -jeff!
: :
: Hi!
:
: Thanks a lot for replying, I'll try to make it clearer. I just got a home-exame at school, where the teacher want us to get the computer to play an easy song. For that I need some notes (A, C, E osv) like playing a gitar? I know this must sound very crazy but I realy need help.
: We are going to make it on a boot-disket, the computer have intel-cpu and the os is XP(but do the os mather?)
: I'll also admitt that I'm verry new to assembly so please don't tell me that it's to dificult.
:
:
:

ok,do i understand it right?you want create a disk which plays a song when booting from it?

a good oldschool way to play simple sounds is the adlib,which should be supported by most today cards(is this still true?hard to test this under todays XP-enviroments).this chip let you create a ton by specifing frequency,length,vibrato and few other sound-parameters to make the sound instruments-like.you can setup a guitar-like sound,too.

i assume you have some basic assembly-knowledge,this is surely not that hard to do,but you need some assembly-practice to code.i suggest you try to write this code under win9x and not XP.XP will not allow you to control the adlib directly.search this site or the web for adlib,there should be good descriptions for this chip or send me a private message

when you played your first notes successfully you can try to change your code to a bootable version.


Report
Re: assembly and sound Posted by pmcastillo on 9 Oct 2005 at 7:22 AM
: : : : Hi!
: : : :
: : : : Do somebody have a link for some codes so I can make music in assebley?
: : : :
: : : :
: : :
: : : What operating system?
: : : What hardware?
: : : Do you want to just play music on something like a soundblaster, or actually MAKE music like with a midi editor?
: : :
: : : Assembly is a very detail oriented language. Your questions need to be likewise.
: : :
: : :
: : : (shameless self plug)
: : : Here's links to 2 .wav players that work in DOS:
: : : http://www.programmersheaven.com/search/download.asp?FileID=30034
: : : http://www.programmersheaven.com/search/download.asp?FileID=23237
: : :
: : : -jeff!
: : :
: : Hi!
: :
: : Thanks a lot for replying, I'll try to make it clearer. I just got a home-exame at school, where the teacher want us to get the computer to play an easy song. For that I need some notes (A, C, E osv) like playing a gitar? I know this must sound very crazy but I realy need help.
: : We are going to make it on a boot-disket, the computer have intel-cpu and the os is XP(but do the os mather?)
: : I'll also admitt that I'm verry new to assembly so please don't tell me that it's to dificult.
: :
: :
: :
:
: ok,do i understand it right?you want create a disk which plays a song when booting from it?
:
: a good oldschool way to play simple sounds is the adlib,which should be supported by most today cards(is this still true?hard to test this under todays XP-enviroments).this chip let you create a ton by specifing frequency,length,vibrato and few other sound-parameters to make the sound instruments-like.you can setup a guitar-like sound,too.
:
: i assume you have some basic assembly-knowledge,this is surely not that hard to do,but you need some assembly-practice to code.i suggest you try to write this code under win9x and not XP.XP will not allow you to control the adlib directly.search this site or the web for adlib,there should be good descriptions for this chip or send me a private message
:
: when you played your first notes successfully you can try to change your code to a bootable version.
:
:
:
Ummmm... I'm a noob... What's the syntax? or the INT? or the sub-function? Or a link to tutorial site?
Report
Re: assembly and sound Posted by shaolin007 on 10 Oct 2005 at 5:38 AM

Might be an easier task to do it with the PC speaker being a novice even though the PC speaker is inferior now days.

http://fly.cc.fer.hr/GDM/articles/sndmus/speaker1.html




Report
Re: assembly and sound Posted by pmcastillo on 10 Oct 2005 at 7:44 AM
:
: Might be an easier task to do it with the PC speaker being a novice even though the PC speaker is inferior now days.
:
: http://fly.cc.fer.hr/GDM/articles/sndmus/speaker1.html
:
:

:
:
:
Ummmm.... I'm using TASM 2.0... Can't understand, especially the "OUT" thing...
Report
Re: assembly and sound Posted by shaolin007 on 10 Oct 2005 at 7:57 AM
: :
: : Might be an easier task to do it with the PC speaker being a novice even though the PC speaker is inferior now days.
: :
: : http://fly.cc.fer.hr/GDM/articles/sndmus/speaker1.html
: :
: :

: :
: :
: :
: Ummmm.... I'm using TASM 2.0... Can't understand, especially the "OUT" thing...
:


Are talking about the instructions 'out' and 'in' for port access?


Report
Re: assembly and sound Posted by pmcastillo on 10 Oct 2005 at 6:12 PM
: : :
: : : Might be an easier task to do it with the PC speaker being a novice even though the PC speaker is inferior now days.
: : :
: : : http://fly.cc.fer.hr/GDM/articles/sndmus/speaker1.html
: : :
: : :

: : :
: : :
: : :
: : Ummmm.... I'm using TASM 2.0... Can't understand, especially the "OUT" thing...
: :
:
:
: Are talking about the instructions 'out' and 'in' for port access?
:

:
:
YES! YES! YES! =) That's what I pertaining to! Here's the story:

I'm new to Assembly Language. Then our teacher gave us an assignment to make a program that produce sounds using TASM. All I could understand for today is the "INT xxh" and "MOV AH, xxh" thing (or some like STOSB). Hope you could help me...
Report
Re: assembly and sound Posted by shaolin007 on 11 Oct 2005 at 5:37 AM
: : : :
: : : : Might be an easier task to do it with the PC speaker being a novice even though the PC speaker is inferior now days.
: : : :
: : : : http://fly.cc.fer.hr/GDM/articles/sndmus/speaker1.html
: : : :
: : : :

: : : :
: : : :
: : : :
: : : Ummmm.... I'm using TASM 2.0... Can't understand, especially the "OUT" thing...
: : :
: :
: :
: : Are talking about the instructions 'out' and 'in' for port access?
: :

: :
: :
: YES! YES! YES! =) That's what I pertaining to! Here's the story:
:
: I'm new to Assembly Language. Then our teacher gave us an assignment to make a program that produce sounds using TASM. All I could understand for today is the "INT xxh" and "MOV AH, xxh" thing (or some like STOSB). Hope you could help me...
:


Those instruction aren't difficult to learn. They both can either take a immediate operand of size byte or for ports greater than 255 you must use the dx register.

in = in from port
out= out to port

mov dx, 1234
mov al, 32
out dx, al     ;send the number 32 to port 1234

or

mov al, 32
out 42, al     ;send the number 32 to port 42

mov dx, 1234
in al, dx      ;copy byte in port 1234 to al

or

in al, 42      ;copy byte in port 42 to al


What I suggest you do is at least download the instruction set reference from intel. That will give you a full explanation on how to use the instructions.


Report
Re: assembly and sound Posted by pmcastillo on 12 Oct 2005 at 5:22 AM
This message was edited by pmcastillo at 2005-10-12 5:37:21

I DID IT! I DID IT! I DID IT! I tried to find some sample source code from the Internet and I found this : I've found it from : http://www.talkaboutprogramming.com/group/alt.lang.asm/messages/73981.html

;
; PIANO.ASM  [ - For DOS - ]
; Simple PC Speaker Piano Keyboard
; Freeware from Evenbit
;
;
.model tiny
.code
        org     100h

main: jmp start
;
stor    dw      0               ;our memory location storage
;
; Turn the cursor off.
;
start:
        call    curs_off        ;go turn off cursor
;
; Get a keypress from the user, and act accordingly.
; (We're checking U.S. keyboard scan codes here.)
;
get_key:
        mov     ah,0            ;function 0 - wait for keypress
        int     16h             ;call ROM BIOS keyboard services
        cmp     ah,1            ;ESC key pressed?
        je      exit            ;yes, so go exit
        cmp     ah,02h
        je      tone_1
        cmp     ah,03h
        je      tone_2
        cmp     ah,04h
        je      tone_3
        cmp     ah,05h
        je      tone_4
        cmp     ah,06h
        je      tone_5
        cmp     ah,07h
        je      tone_6
        cmp     ah,08h
        je      tone_7
        cmp     ah,09h
        je      tone_8
        cmp     ah,0ah
        je      tone_9
        cmp     ah,0bh
        je      tone_0
;
        jmp     get_key         ;go get another keypress
;
exit:
        call    curs_on         ;go turn cursor on
        int     20h             ;exit to DOS
;
tone_1:
        mov     ax, 272
        mov     stor, ax
        call    sounder         ;go generate the tone
        jmp     get_key         ;go get another keypress
tone_2:
        mov     ax, 294
        mov     stor, ax
        call    sounder         ;go generate the tone
        jmp     get_key         ;go get another keypress
tone_3:
        mov     ax, 314
        mov     stor, ax
        call    sounder         ;go generate the tone
        jmp     get_key         ;go get another keypress
tone_4:
        mov     ax, 330
        mov     stor, ax
        call    sounder         ;go generate the tone
        jmp     get_key         ;go get another keypress
tone_5:
        mov     ax, 350
        mov     stor, ax
        call    sounder         ;go generate the tone
        jmp     get_key         ;go get another keypress
tone_6:
        mov     ax, 370
        mov     stor, ax
        call    sounder         ;go generate the tone
        jmp     get_key         ;go get another keypress
tone_7:
        mov     ax, 392
        mov     stor, ax
        call    sounder         ;go generate the tone
        jmp     get_key         ;go get another keypress
tone_8:
        mov     ax, 419
        mov     stor, ax
        call    sounder         ;go generate the tone
        jmp     get_key         ;go get another keypress
tone_9:
        mov     ax, 440
        mov     stor, ax
        call    sounder         ;go generate the tone
        jmp     get_key         ;go get another keypress
tone_0:
        mov     ax, 475
        mov     stor, ax
        call    sounder         ;go generate the tone
        jmp     get_key         ;go get another keypress



;
;****************************************
; Our sub-routines start here.
;****************************************
;
; Turn cursor off.
;
curs_off:
        mov     ch,10h          ;set bits to turn cursor off
        mov     ah,1            ;function 1 - cursor control
        int     10h             ;call ROM BIOS video services
        ret                     ;return to caller
;
; Turn cursor on.
;
curs_on:
        mov     cx,0506h        ;set bits to turn cursor on
        mov     ah,1            ;function 1 - cursor control
        int     10h             ;call ROM BIOS video services
        ret                     ;return to caller
;
; Generate sound through the PC speaker.
;

sounder:
        mov     al,10110110b    ;load control word
        out     43h,al          ;send it
        mov     ax,stor         ;tone frequency
        out     42h,al          ;send LSB
        mov     al,ah           ;move MSB to AL
        out     42h,al          ;save it
        in      al,61h          ;get port 61 state
        or      al,00000011b   ;turn on speaker
        out     61h,al          ;speaker on now
        call    delay           ;go pause a little bit
        and     al,11111100b   ;clear speaker enable
        out     61h,al          ;speaker off now
        call    clr_keyb        ;go clear the keyboard buffer
        ret                     ;return to caller

delay:
        mov     ah,00h          ;function 0 - get system timer tick
        int     01Ah            ;call ROM BIOS time-of-day services
        add     dx,4            ;add our delay value to DX
        mov     bx,dx           ;store result in BX
pozz:
        int     01Ah            ;call ROM BIOS time-of-day services
        cmp     dx,bx           ;has the delay duration passed?
        jl      pozz            ;no, so go check again
        ret                     ;return to caller
;
; Clear the keyboard buffer.
;
clr_keyb:
        push    es              ;preserve ES
        push    di              ;preserve DI
        mov     ax,40h          ;BIOS segment in AX
        mov     es,ax           ;transfer to ES
        mov     ax,1Ah          ;keyboard head pointer in AX
        mov     di,ax           ;transfer to DI
        mov     ax,1Eh          ;keyboard buffer start in AX
        mov     es: word ptr [di],ax   ;transfer to head pointer
        inc     di              ;bump pointer to...
        inc     di              ;...keyboard tail pointer
        mov     es: word ptr [di],ax   ;transfer to tail pointer
        pop     di              ;restore DI
        pop     es              ;restore ES
        ret                     ;return to caller 
; 
end main
end 


When you run the program, you'll just press (0-9) and the sound will produce, while ESC exits the program.


Here I learn something: (I'm referring to the RED code)

1.) OUT is putting something to the port while IN is getting something to the port.

2.) (10110110b = 182 = B6h) was sent to port 43h. According to http://fly.cc.fer.hr/GDM/articles/sndmus/speaker1.html, Port 43h is a System Timer 2, is used to control sound generation. And the number that was inputed to it is countdown value (is it the same with frequency?).

3.) Then the STOR was sent to AX (What will be put to AH and AL?).

4.) Then "something" (because I don't know what went to AL) was sent to Port 42h. It said Port 42h is used to set the LOW and HIGH byte (What is it? Is it the peaks and bottoms of the frequency?). Twice... (Can't understand this thing, will the second value OVERWRITE the first value?)

5.) What are these things:

        or      al,00000011b   ;turn on speaker
        and     al,11111100b   ;clear speaker enable


What's the meaning or OR and AND commands?

QUESTIONS: I summarized all here:

1.) Is countdown value the same with frequency?

2.) If I put 475 to AX, what will be put in AH and AL?

3.) Is the LOW and HIGH byte the peaks and bottoms of the frequency?

4.) If I sent two values in a port, will the second value OVERWRITE the first one? (Co'z that's my understanding, AX = VALUE1 then AX = VALUE 2, therefore AX is VALUE2)

5.) What's the meaning or OR and AND commands?

6.) I tried to find some manuals in Intel Processor in http://www.intel.com/ but all I could see is Processors and it's specs... Where can I get an Intel Documentation?
Report
Re: assembly and sound Posted by ASHLEY4 on 12 Oct 2005 at 5:46 AM
: This message was edited by pmcastillo at 2005-10-12 5:37:21

: I DID IT! I DID IT! I DID IT! I tried to find some sample source code from the Internet and I found this : I've found it from : http://www.talkaboutprogramming.com/group/alt.lang.asm/messages/73981.html
:
:
: ;
: ; PIANO.ASM  [ - For DOS - ]
: ; Simple PC Speaker Piano Keyboard
: ; Freeware from Evenbit
: ;
: ;
: .model tiny
: .code
:         org     100h
: 
: main: jmp start
: ;
: stor    dw      0               ;our memory location storage
: ;
: ; Turn the cursor off.
: ;
: start:
:         call    curs_off        ;go turn off cursor
: ;
: ; Get a keypress from the user, and act accordingly.
: ; (We're checking U.S. keyboard scan codes here.)
: ;
: get_key:
:         mov     ah,0            ;function 0 - wait for keypress
:         int     16h             ;call ROM BIOS keyboard services
:         cmp     ah,1            ;ESC key pressed?
:         je      exit            ;yes, so go exit
:         cmp     ah,02h
:         je      tone_1
:         cmp     ah,03h
:         je      tone_2
:         cmp     ah,04h
:         je      tone_3
:         cmp     ah,05h
:         je      tone_4
:         cmp     ah,06h
:         je      tone_5
:         cmp     ah,07h
:         je      tone_6
:         cmp     ah,08h
:         je      tone_7
:         cmp     ah,09h
:         je      tone_8
:         cmp     ah,0ah
:         je      tone_9
:         cmp     ah,0bh
:         je      tone_0
: ;
:         jmp     get_key         ;go get another keypress
: ;
: exit:
:         call    curs_on         ;go turn cursor on
:         int     20h             ;exit to DOS
: ;
: tone_1:
:         mov     ax, 272
:         mov     stor, ax
:         call    sounder         ;go generate the tone
:         jmp     get_key         ;go get another keypress
: tone_2:
:         mov     ax, 294
:         mov     stor, ax
:         call    sounder         ;go generate the tone
:         jmp     get_key         ;go get another keypress
: tone_3:
:         mov     ax, 314
:         mov     stor, ax
:         call    sounder         ;go generate the tone
:         jmp     get_key         ;go get another keypress
: tone_4:
:         mov     ax, 330
:         mov     stor, ax
:         call    sounder         ;go generate the tone
:         jmp     get_key         ;go get another keypress
: tone_5:
:         mov     ax, 350
:         mov     stor, ax
:         call    sounder         ;go generate the tone
:         jmp     get_key         ;go get another keypress
: tone_6:
:         mov     ax, 370
:         mov     stor, ax
:         call    sounder         ;go generate the tone
:         jmp     get_key         ;go get another keypress
: tone_7:
:         mov     ax, 392
:         mov     stor, ax
:         call    sounder         ;go generate the tone
:         jmp     get_key         ;go get another keypress
: tone_8:
:         mov     ax, 419
:         mov     stor, ax
:         call    sounder         ;go generate the tone
:         jmp     get_key         ;go get another keypress
: tone_9:
:         mov     ax, 440
:         mov     stor, ax
:         call    sounder         ;go generate the tone
:         jmp     get_key         ;go get another keypress
: tone_0:
:         mov     ax, 475
:         mov     stor, ax
:         call    sounder         ;go generate the tone
:         jmp     get_key         ;go get another keypress
: 
: 
: 
: ;
: ;****************************************
: ; Our sub-routines start here.
: ;****************************************
: ;
: ; Turn cursor off.
: ;
: curs_off:
:         mov     ch,10h          ;set bits to turn cursor off
:         mov     ah,1            ;function 1 - cursor control
:         int     10h             ;call ROM BIOS video services
:         ret                     ;return to caller
: ;
: ; Turn cursor on.
: ;
: curs_on:
:         mov     cx,0506h        ;set bits to turn cursor on
:         mov     ah,1            ;function 1 - cursor control
:         int     10h             ;call ROM BIOS video services
:         ret                     ;return to caller
: ;
: ; Generate sound through the PC speaker.
: ;
: 
: sounder:
:         mov     al,10110110b    ;load control word
:         out     43h,al          ;send it
:         mov     ax,stor         ;tone frequency
:         out     42h,al          ;send LSB
:         mov     al,ah           ;move MSB to AL
:         out     42h,al          ;save it
:         in      al,61h          ;get port 61 state
:         or      al,00000011b   ;turn on speaker
:         out     61h,al          ;speaker on now
:         call    delay           ;go pause a little bit
:         and     al,11111100b   ;clear speaker enable
:         out     61h,al          ;speaker off now
:         call    clr_keyb        ;go clear the keyboard buffer
:         ret                     ;return to caller
: 
: delay:
:         mov     ah,00h          ;function 0 - get system timer tick
:         int     01Ah            ;call ROM BIOS time-of-day services
:         add     dx,4            ;add our delay value to DX
:         mov     bx,dx           ;store result in BX
: pozz:
:         int     01Ah            ;call ROM BIOS time-of-day services
:         cmp     dx,bx           ;has the delay duration passed?
:         jl      pozz            ;no, so go check again
:         ret                     ;return to caller
: ;
: ; Clear the keyboard buffer.
: ;
: clr_keyb:
:         push    es              ;preserve ES
:         push    di              ;preserve DI
:         mov     ax,40h          ;BIOS segment in AX
:         mov     es,ax           ;transfer to ES
:         mov     ax,1Ah          ;keyboard head pointer in AX
:         mov     di,ax           ;transfer to DI
:         mov     ax,1Eh          ;keyboard buffer start in AX
:         mov     es: word ptr [di],ax   ;transfer to head pointer
:         inc     di              ;bump pointer to...
:         inc     di              ;...keyboard tail pointer
:         mov     es: word ptr [di],ax   ;transfer to tail pointer
:         pop     di              ;restore DI
:         pop     es              ;restore ES
:         ret                     ;return to caller 
: ; 
: end main
: end 
: 

:
: When you run the program, you'll just press (0-9) and the sound will produce, while ESC exits the program.
:
:
: Here I learn something: (I'm referring to the RED code)
:
: 1.) OUT is putting something to the port while IN is getting something to the port.
:
: 2.) (10110110b = 182 = B6h) was sent to port 43h. According to http://fly.cc.fer.hr/GDM/articles/sndmus/speaker1.html, Port 43h is a System Timer 2, is used to control sound generation. And the number that was inputed to it is countdown value (is it the same with frequency?).
:
: 3.) Then the STOR was sent to AX (What will be put to AH and AL?).
:
: 4.) Then "something" (because I don't know what went to AL) was sent to Port 42h. It said Port 42h is used to set the LOW and HIGH byte (What is it? Is it the peaks and bottoms of the frequency?). Twice... (Can't understand this thing, will the second value OVERWRITE the first value?)
:
: 5.) What are these things:
:
:
:         or      al,00000011b   ;turn on speaker
:         and     al,11111100b   ;clear speaker enable
: 

:
: What's the meaning or OR and AND commands?
:
: QUESTIONS: I summarized all here:
:
: 1.) Is countdown value the same with frequency?
:
: 2.) If I put 475 to AX, what will be put in AH and AL?
:
: 3.) Is the LOW and HIGH byte the peaks and bottoms of the frequency?
:
: 4.) If I sent two values in a port, will the second value OVERWRITE the first one? (Co'z that's my understanding, AX = VALUE1 then AX = VALUE 2, therefore AX is VALUE2)
:
: 5.) What's the meaning or OR and AND commands?
:
: 6.) I tried to find some manuals in Intel Processor in http://www.intel.com/ but all I could see is Processors and it's specs... Where can I get an Intel Documentation?
:
You could make it bootable with this program
http://alexfru.chat.ru/epm.html#bootprog
Report
Re: assembly and sound Posted by shaolin007 on 12 Oct 2005 at 6:34 AM
:
: ;
: ; PIANO.ASM  [ - For DOS - ]
: ; Simple PC Speaker Piano Keyboard
: ; Freeware from Evenbit
: ;
: ;
: .model tiny
: .code
:         org     100h
: 
: main: jmp start
: ;
: stor    dw      0               ;our memory location storage
: ;
: ; Turn the cursor off.
: ;
: start:
:         call    curs_off        ;go turn off cursor
: ;
: ; Get a keypress from the user, and act accordingly.
: ; (We're checking U.S. keyboard scan codes here.)
: ;
: get_key:
:         mov     ah,0            ;function 0 - wait for keypress
:         int     16h             ;call ROM BIOS keyboard services
:         cmp     ah,1            ;ESC key pressed?
:         je      exit            ;yes, so go exit
:         cmp     ah,02h
:         je      tone_1
:         cmp     ah,03h
:         je      tone_2
:         cmp     ah,04h
:         je      tone_3
:         cmp     ah,05h
:         je      tone_4
:         cmp     ah,06h
:         je      tone_5
:         cmp     ah,07h
:         je      tone_6
:         cmp     ah,08h
:         je      tone_7
:         cmp     ah,09h
:         je      tone_8
:         cmp     ah,0ah
:         je      tone_9
:         cmp     ah,0bh
:         je      tone_0
: ;
:         jmp     get_key         ;go get another keypress
: ;
: exit:
:         call    curs_on         ;go turn cursor on
:         int     20h             ;exit to DOS
: ;
: tone_1:
:         mov     ax, 272
:         mov     stor, ax
:         call    sounder         ;go generate the tone
:         jmp     get_key         ;go get another keypress
: tone_2:
:         mov     ax, 294
:         mov     stor, ax
:         call    sounder         ;go generate the tone
:         jmp     get_key         ;go get another keypress
: tone_3:
:         mov     ax, 314
:         mov     stor, ax
:         call    sounder         ;go generate the tone
:         jmp     get_key         ;go get another keypress
: tone_4:
:         mov     ax, 330
:         mov     stor, ax
:         call    sounder         ;go generate the tone
:         jmp     get_key         ;go get another keypress
: tone_5:
:         mov     ax, 350
:         mov     stor, ax
:         call    sounder         ;go generate the tone
:         jmp     get_key         ;go get another keypress
: tone_6:
:         mov     ax, 370
:         mov     stor, ax
:         call    sounder         ;go generate the tone
:         jmp     get_key         ;go get another keypress
: tone_7:
:         mov     ax, 392
:         mov     stor, ax
:         call    sounder         ;go generate the tone
:         jmp     get_key         ;go get another keypress
: tone_8:
:         mov     ax, 419
:         mov     stor, ax
:         call    sounder         ;go generate the tone
:         jmp     get_key         ;go get another keypress
: tone_9:
:         mov     ax, 440
:         mov     stor, ax
:         call    sounder         ;go generate the tone
:         jmp     get_key         ;go get another keypress
: tone_0:
:         mov     ax, 475
:         mov     stor, ax
:         call    sounder         ;go generate the tone
:         jmp     get_key         ;go get another keypress
: 
: 
: 
: ;
: ;****************************************
: ; Our sub-routines start here.
: ;****************************************
: ;
: ; Turn cursor off.
: ;
: curs_off:
:         mov     ch,10h          ;set bits to turn cursor off
:         mov     ah,1            ;function 1 - cursor control
:         int     10h             ;call ROM BIOS video services
:         ret                     ;return to caller
: ;
: ; Turn cursor on.
: ;
: curs_on:
:         mov     cx,0506h        ;set bits to turn cursor on
:         mov     ah,1            ;function 1 - cursor control
:         int     10h             ;call ROM BIOS video services
:         ret                     ;return to caller
: ;
: ; Generate sound through the PC speaker.
: ;
: 
: sounder:
:         mov     al,10110110b    ;load control word
:         out     43h,al          ;send it
:         mov     ax,stor         ;tone frequency
:         out     42h,al          ;send LSB
:         mov     al,ah           ;move MSB to AL
:         out     42h,al          ;save it
:         in      al,61h          ;get port 61 state
:         or      al,00000011b   ;turn on speaker
:         out     61h,al          ;speaker on now
:         call    delay           ;go pause a little bit
:         and     al,11111100b   ;clear speaker enable
:         out     61h,al          ;speaker off now
:         call    clr_keyb        ;go clear the keyboard buffer
:         ret                     ;return to caller
: 
: delay:
:         mov     ah,00h          ;function 0 - get system timer tick
:         int     01Ah            ;call ROM BIOS time-of-day services
:         add     dx,4            ;add our delay value to DX
:         mov     bx,dx           ;store result in BX
: pozz:
:         int     01Ah            ;call ROM BIOS time-of-day services
:         cmp     dx,bx           ;has the delay duration passed?
:         jl      pozz            ;no, so go check again
:         ret                     ;return to caller
: ;
: ; Clear the keyboard buffer.
: ;
: clr_keyb:
:         push    es              ;preserve ES
:         push    di              ;preserve DI
:         mov     ax,40h          ;BIOS segment in AX
:         mov     es,ax           ;transfer to ES
:         mov     ax,1Ah          ;keyboard head pointer in AX
:         mov     di,ax           ;transfer to DI
:         mov     ax,1Eh          ;keyboard buffer start in AX
:         mov     es: word ptr [di],ax   ;transfer to head pointer
:         inc     di              ;bump pointer to...
:         inc     di              ;...keyboard tail pointer
:         mov     es: word ptr [di],ax   ;transfer to tail pointer
:         pop     di              ;restore DI
:         pop     es              ;restore ES
:         ret                     ;return to caller 
: ; 
: end main
: end 
: 

:
: When you run the program, you'll just press (0-9) and the sound will produce, while ESC exits the program.
:
:
: Here I learn something: (I'm referring to the RED code)
:
: 1.) OUT is putting something to the port while IN is getting something to the port.


Correct


: 2.) (10110110b = 182 = B6h) was sent to port 43h. According to http://fly.cc.fer.hr/GDM/articles/sndmus/speaker1.html, Port 43h is a System Timer 2, is used to control sound generation. And the number that was inputed to it is countdown value (is it the same with frequency?).

This only sets up the speaker for sound generation

:
: 3.) Then the STOR was sent to AX (What will be put to AH and AL?).

If you look at the tone section depending on the tone the frequency is stored to stor.

: 4.) Then "something" (because I don't know what went to AL) was sent to Port 42h. It said Port 42h is used to set the LOW and HIGH byte (What is it? Is it the peaks and bottoms of the frequency?). Twice... (Can't understand this thing, will the second value OVERWRITE the first value?)

No, port 42h is 8bit but you must send a 16bit value to it so how do you do that? You send the LSB(Least Significant Byte) and then the MSB(Most Significant Byte). Since the instruction 'out' can only take a 8bit value from AL, you must plug in the LSB into AL first and send it then plug in the MSB into AL next and send it


:
: 5.) What are these things:
:
:
:         or      al,00000011b   ;turn on speaker
:         and     al,11111100b   ;clear speaker enable
: 


The 1st one makes sure bits 1 and 0 are on no matter what. The second clears bits 1 and 0 because anything 'anded' with 0 is false.


: What's the meaning or OR and AND commands?

'Or' is to set bits 'on' and 'and' is usually used to check a bit for truth or clear bits.


: QUESTIONS: I summarized all here:
:
: 1.) Is countdown value the same with frequency?

No

: 2.) If I put 475 to AX, what will be put in AH and AL?

Register AX=AH+AL

        AX
    AH     +      AL   =475
0000 0001     1101 1011


: 3.) Is the LOW and HIGH byte the peaks and bottoms of the frequency?

No, its just a frequency value from 0-65536


: 4.) If I sent two values in a port, will the second value OVERWRITE the first one? (Co'z that's my understanding, AX = VALUE1 then AX = VALUE 2, therefore AX is VALUE2)

I explained why you must send 2 bytes to this port earlier


: 5.) What's the meaning or OR and AND commands?

Already answered


: 6.) I tried to find some manuals in Intel Processor in http://www.intel.com/ but all I could see is Processors and it's specs... Where can I get an Intel Documentation?
:
[/green]
http://www.fh-bochum.de/fb3/meva-lab/docu/

Download the intel vol 1 and 2. Vol 3 is for system programming which you don't need yet. Also, download the dosints.pdf.
[/green]

Report
Re: assembly and sound Posted by pmcastillo on 13 Oct 2005 at 5:30 AM
Thanks man, for helping me... =)


OK, NOW I LEARNED:

1.) To make it simple, sending B6h to Port 43h "sets up the speaker for sound generation".

2.) The LSB (Least Significant Byte) and the MSB (Most Significant Byte) is almost the same as AL(LSB) and AH(MSB).

3.) The reason why Port 42h needs two values is because "Port 42 is 8bit, but it needs 16bit value"

4.) "OR" and "AND" commands are Bit Wise Operators, they are used to manipulate bits (at first I thought it was like "C", the "Logical" Operators). So in the code:

(1)         in      al,61h          ;get port 61 state
(2)         or      al,00000011b    ;turn on speaker
(3)         out     61h,al          ;speaker on now
(4)         call    delay           ;go pause a little bit
(5)         and     al,11111100b    ;clear speaker enable
(6)         out     61h,al          ;speaker off now


(1) It gets the state value of the port (I'm curious, then what is the value of AL now?), then (2) it changes it values to set to turn on the speaker, then (3) it sends it back again, then (4) just delay for a moment, then (5) it changes the value again to set to turn the speaker off, then (6) send it back again to "shut" it down. Ryt? Is there any site that I could have a documentation of Ports?

I tried to visit: http://www.fh-bochum.de/fb3/meva-lab/docu/ for documentations but it's "server down" (maybe). I also tried to visit http://www.intel.com/ and download the Instruction Set and WHOA! 1000+ pages! And quite yet complicated.


QUESTIONS I'M JUST CURIOUS ABOUT:

1.) If I typed "IN AL,61H", what would be the value of AL?

2.) Where can I find a documentation about Ports?


BTW, thanks for your support you've been a great help for me... =)
Report
Re: assembly and sound Posted by pmcastillo on 13 Oct 2005 at 5:32 AM
Thanks man, for helping me... =)


OK, NOW I LEARNED:

1.) To make it simple, sending B6h to Port 43h "sets up the speaker for sound generation".

2.) The LSB (Least Significant Byte) and the MSB (Most Significant Byte) is almost the same as AL(LSB) and AH(MSB).

3.) The reason why Port 42h needs two values is because "Port 42 is 8bit, but it needs 16bit value"

4.) "OR" and "AND" commands are Bit Wise Operators, they are used to manipulate bits (at first I thought it was like "C", the "Logical" Operators). So in the code:

(1)         in      al,61h          ;get port 61 state
(2)         or      al,00000011b    ;turn on speaker
(3)         out     61h,al          ;speaker on now
(4)         call    delay           ;go pause a little bit
(5)         and     al,11111100b    ;clear speaker enable
(6)         out     61h,al          ;speaker off now


(1) It gets the state value of the port (I'm curious, then what is the value of AL now?), then (2) it changes it values to set to turn on the speaker, then (3) it sends it back again, then (4) just delay for a moment, then (5) it changes the value again to set to turn the speaker off, then (6) send it back again to "shut" it down. Ryt? Is there any site that I could have a documentation of Ports?

I tried to visit: http://www.fh-bochum.de/fb3/meva-lab/docu/ for documentations but it's "server down" (maybe). I also tried to visit http://www.intel.com/ and download the Instruction Set and WHOA! 1000+ pages! And quite yet complicated.


QUESTIONS I'M JUST CURIOUS ABOUT:

1.) If I typed "IN AL,61H", what would be the value of AL?

2.) Where can I find a documentation about Ports?


BTW, thanks for your support you've been a great help for me... =)
Report
Re: assembly and sound Posted by shaolin007 on 13 Oct 2005 at 7:44 AM
Thanks man, for helping me... =)


OK, NOW I LEARNED:

1.) To make it simple, sending B6h to Port 43h "sets up the speaker for sound generation".

Correct from what I have read.



2.) The LSB (Least Significant Byte) and the MSB (Most Significant Byte) is almost the same as AL(LSB) and AH(MSB).

In regards to register AX then AL would be the LSB and AH would be the MSB. But LSB and MSB could also mean 'bit' which is what it usually means.


3.) The reason why Port 42h needs two values is because "Port 42 is 8bit, but it needs 16bit value"

yep

4.) "OR" and "AND" commands are Bit Wise Operators, they are used to manipulate bits (at first I thought it was like "C", the "Logical" Operators). So in the code:

(1)         in      al,61h          ;get port 61 state
(2)         or      al,00000011b    ;turn on speaker
(3)         out     61h,al          ;speaker on now
(4)         call    delay           ;go pause a little bit
(5)         and     al,11111100b    ;clear speaker enable
(6)         out     61h,al          ;speaker off now




(1) It gets the state value of the port (I'm curious, then what is the value of AL now?), then (2) it changes it values to set to turn on the speaker, then (3) it sends it back again, then (4) just delay for a moment, then (5) it changes the value again to set to turn the speaker off, then (6) send it back again to "shut" it down. Ryt? Is there any site that I could have a documentation of Ports?

(1)You must get the state of which that port is in to know whats in it and to do that you must use a 'in' instruction to read the port and then modify the bits 0 and 1 while leaving the other bits unchanged.



I tried to visit: http://www.fh-bochum.de/fb3/meva-lab/docu/ for documentations but it's "server down" (maybe). I also tried to visit http://www.intel.com/ and download the Instruction Set and WHOA! 1000+ pages! And quite yet complicated.


Hmm the link works for me. Yes the manuals are very large but only concern yourself with the instruction set explanations.

Read up on these instructions X=b-byte, w-word, d-dword

add, sub, mul, div, stosX, lodsX, xor, and, or, not, neg, shr, shl, rol, ror, in, out, insX, outsX, rep, lea, mov, jxx, jmp, cld, std, clc, stc, call, ret, cli, and sti.

Looks like alot but its alot of the same stuff just a little different for each variation. Thats the bulk of what you will use in your programming.


QUESTIONS I'M JUST CURIOUS ABOUT:

1.) If I typed "IN AL,61H", what would be the value of AL?

Whatever the state of that port is at the time. Could be different from time to time. The only concern for you here is to make sure bits 0 and 1 are enabled. The other bits are useless to you and should be untouched and left alone in their current state.


2.) Where can I find a documentation about Ports?

http://www.clipx.net/norton.php

good site




BTW, thanks for your support you've been a great help for me... =)
Report
Re: assembly and sound Posted by pmcastillo on 14 Oct 2005 at 1:38 AM
Ok, now I have a good foundation for assembly =) And I was able to visit again http://www.fh-bochum.de/fb3/meva-lab/docu/ and download dosints.pdf, and this thing ROCKS! COOL! Simple, Summarized, and "NOOB"-friendly, more easier for me to understand than Ralph Brown's Interrupt List (http://www.ctyme.com/rbrown.htm). I also tried to visit http://www.clipx.net/norton.php and it's COOL! =) Has tutorials in different programming languages, especially in Assembly Language, and has a Port Listing! Now I will have a good grade from my professor for this =) Wait for my next thread soon =), it's more about File Operations. Coz' I stumbled to this site: http://short.stop.home.att.net/freesoft/sound.htm#soundplay (The SBPlay) and I found a WAV player for DOS playing through Internal Speaker! And it has a source code (C Language) COOL! And I want to know how to run program (with their parameters) on Assembly


HERE'S MY NEW QUEST

         in      al,61h          ;get port 61 state


(1) I want to write the value of AL to the screen in Binary form, how? Is it Complicated?
Report
Re: assembly and sound Posted by shaolin007 on 14 Oct 2005 at 5:09 AM
(1) I want to write the value of AL to the screen in Binary form, how? Is it Complicated?


Not as hard as you would think. Just brainstorm on ways you can convert it to a binary string format and post your results here, good luck.


Report
Re: assembly and sound Posted by pmcastillo on 14 Oct 2005 at 5:19 AM
Ok, thanks! =)
Report
Re: assembly and sound Posted by pmcastillo on 15 Oct 2005 at 4:10 AM
I've made another thread coz my topic is out of the thread, its called "Assembly and Ports" especially Port 61h, check it out here:
http://www.programmersheaven.com/c/msgboard/read.asp?Board=1&MsgID=318499&Setting=A9999F0001



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.