《電子技術應用》
您所在的位置:首頁 > 嵌入式技術 > 解決方案 > 匯編源代碼之MAKE SOUNDS(發聲)

匯編源代碼之MAKE SOUNDS(發聲)

2017-07-23
關鍵詞: 匯編語言

INTRODUCTION

This code example provides a set of keyboard routines to control sound output while waiting for a user to enter a keyboard character. The advantage to this method is that a main routine can call these sound routines to play a sound sequence, and the sound routines will return control back to the main routine whenever the user enters keyboard data so that the main routine can continue computing while the sound plays in the background. The code example has two different code entry points for getting keyboard data. One code entry point is a standard get_keyinput call which will wait for a key and update the sound data until a key code is found. The other code entry point is the get_keyinput_to call, which will wait a set amount of time for a key code and if none is found, return with a no key code found condition. The calling routine puts a timeout counter value in register AX on entry. The counter value is based on the system clock which ticks at 18.2 times per second. The entry point start_table_sound is used to begin a background sound sequence. On entry, the register BX indexes a table of sound data. The table has a format of four byte entries and is terminated by a data word of zero. The four bytes are used as two words: the first is a duration count and the second is a tone value. There are two code entry points for turning the background sound off and on. There is also a utility to flush out the keyboard buffer that can be executed with a call to flush_keyboard.

;Set of keyboard routines with sound outputs
.MODEL small
.STACK 500
.DATA
 ;define table for sound output
;sample_sounds   dw  8,45000  ;long low sound
;       dw  2,2000     ;short high sound
;       dw  0       ;end of sample sound table
sound_table  dw  0
sound_time_m  dw  0
sound_time_l  dw  0
sound_flag   db  0
sound_on_flag db  0,0
key_time_out_m dw  0
key_time_out_l dw  0
.CODE
;************ ^^^^^^^^^^ *************
;### code entry point #####
get_keyinput  proc near
;this routine checks for keyboard data in BIOS buffer
; and returns with data if there
;else it updates sound output data and loops to check for
; keyboard data again until keyboard data found
;on exit AX has keyboard data
   public  get_keyinput
   push bx
   push cx
   push dx
get_keyinput_loop:
     mov ah,1  ;set AH for scan
     int 16H  ;BIOS Call
      ;branch if no keyboard data
     jz  sound_update
     mov ah,0  ;set AH for get key
     int 16H  ;BIOS Call
   pop dx
   pop cx
   pop bx
   ret
;******* -------- *******
sound_update:
   cmp sound_flag,0    ;check for sound on????
   jz  get_keyinput_loop  ;branch out if sound off
   mov cx,sound_time_m   ;else check for sound update
   mov ax,sound_time_l
   call test_current_time  ;is it time for update ??
   jc  get_keyinput_loop  ;branch if not time
   mov bx,sound_table
   mov ax,[bx]       ;get next sound update value
   or  ax,ax        ;?? end of sound ??
   jz  turn_sound_off   ;branch if end sound
   call get_time_plus_ax  ;reset sound duration
   mov sound_time_m,cx
   mov sound_time_l,ax
   inc bx
   inc bx
   mov ax,[bx]
   inc bx
   inc bx
   mov sound_table,bx
   call sound_out_ax    ;go set sound frequency
   jmp get_keyinput_loop ;branch to keyboard loop
turn_sound_off:
   call sound_off
   mov sound_flag,0
   jmp get_keyinput_loop ;branch to keyboard loop
get_keyinput  endp
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
;************ ########## *************
;### code entry point #####
get_keyinput_to   proc near
;get keyboard data with timeout if no data available
;on entry AX has time duration in 18 ticks per second
;on exit if carry clear then AX has keyboard data
   public  get_keyinput_to
   push bx
   push cx
   push dx
   call get_time_plus_ax   ;add duration to current time
   mov key_time_out_m,cx  ;set timeout value
   mov key_time_out_l,ax
get_keyinput_to_loop:
   mov ah,1        ;ready to scan keyboard data
   int 16H         ;BIOS Call
   jz  sound_update_to   ;branch if no keyboard data
   mov ah,0        ;ready to get key data
   int 16H          ;BIOS Call
   pop dx
   pop cx
   pop bx
   clc            ;set keyboard data flag
   ret
get_keyinput_to_1:
   mov cx,key_time_out_m   ;check for timeout
   mov ax,key_time_out_l
   call test_current_time
   jc  get_keyinput_to_loop ;branch if no timeout
   xor ax,ax         ;else timeout return condition
   pop dx
   pop cx
   pop bx
   stc            ;set no keyboard data flag
   ret
; ******** %%%%%%% ********
sound_update_to:
   cmp sound_flag,0    ;check for sound on????
   jz  get_keyinput_to_1  ;branch if sound off
   mov cx,sound_time_m   ;else check for sound update
   mov ax,sound_time_l
   call test_current_time
   jc  get_keyinput_to_1  ;branch if not ready for update
   mov bx,sound_table
   mov ax,[bx]
   or  ax,ax        ;test for end of table
   jz  turn_sound_off_to  ;branch if end of table data
   call get_time_plus_ax
   mov sound_time_m,cx
   mov sound_time_l,ax
   inc bx
   inc bx
   mov ax,[bx]
   inc bx
   inc bx
   mov sound_table,bx
   call sound_out_ax
   jmp get_keyinput_to_1
turn_sound_off_to:
   call sound_off
   mov sound_flag,0
   jmp get_keyinput_to_1
get_keyinput_to   endp
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
;************ @@@@@@@@@@ ************
;### code entry point #####
start_table_sound  proc near
;subroutine to start background sound output
;on entry BX indexes sound data table
   public  start_table_sound
   push ax
   push bx
   mov ax,[bx]
   call get_time_plus_ax
   mov sound_time_m,cx
   mov sound_time_l,ax
   inc bx
   inc bx
   mov ax,[bx]
   inc bx
   inc bx
   mov sound_table,bx
   call sound_out_ax
   mov sound_flag,0FFH
   pop bx
   pop ax
   ret
start_table_sound  endp
;************ ========== *************
;### code entry point #####
flush_keyboard proc near
 ;utility to flush contents of keyboard buffer
   public  flush_keyboard
   mov ah,1
   int 16H    ;BIOS Call ;scan for keyboard data
   jz  flush_keyboard_x   ;branch if no keyboard data
   mov ah,0         ;else get keyboard data
   int 16H    ;BIOS Call
   jmp flush_keyboard
flush_keyboard_x:
   ret
flush_keyboard endp
;************* ----------- **************
sound_out_ax  proc near
 ;set sound out frequency to data value in AX
   push ax
   push ax
   cmp sound_on_flag,0
   jne sound_out_1
   in  al,61H     ;input port 61h
   or  al,3
   out 61H,al     ;output port 61h
sound_out_1:
   mov al,0B6H
   out 43H,al     ;output port 43h
   pop ax
   out 42H,al     ;output port 42h
   xchg al,ah
   out 42H,al     ;output port 42h
   mov sound_on_flag,0FFH
   pop ax
   ret
sound_out_ax  endp
;*********** $$$$$$$$$$ ************
;###### code entry point #######
sound_off proc near
  ;turn sound port off
   public  sound_off
   push ax
   cmp sound_on_flag,0
   je  sound_off_exit
   in  al,61H     ;input port 61h
   and al,0FCH
   out 61H,al     ;output port 61h
   mov sound_on_flag,0
sound_off_exit:
   pop ax
   ret
sound_off endp
;************** %%%%%%%%%% ***************
;with all CX:AX time values, CX is most significant
; and AX is least significant
get_current_time  proc near
;on exit CX:AX has 32 bit day clock value
; in 18.2 ticks per second
   push dx
     xor ax,ax   ;set AH to zero
     int 1AH    ;BIOS Call get time
     mov ax,dx
   pop dx
   ret
get_current_time  endp
;****************************
get_time_plus_ax  proc near
;on entry AX has 16 bit value to add to current clock time
;on exit CX:AX has new 32 bit clock value
   push dx
   push ax
   xor ax,ax
   int 1AH      ;BIOS Call
   pop ax
   add ax,dx
   adc cx,0
   pop dx
   ret
get_time_plus_ax  endp
;************ ######## ************
test_current_time  proc near
;on entry CX:AX has time value
; to be subtracted from the current time
;on exit if carry set then current time
; is less than CX:AX time
   push dx
   push cx
   push ax
   xor ax,ax
   int 1AH      ;BIOS Call
   cmp dx,18
   jb  test_current_time_2
test_current_time_1:
   pop ax
   sub dx,ax
   pop dx
   sbb cx,dx
   mov cx,dx
   pop dx
   ret
test_current_time_2:
   or  cx,cx
   jnz test_current_time_1
   pop ax   ;this is fix code for midnight factor
   pop dx
   pop dx
   clc     ;clear carry condition
   ret
test_current_time  endp
;*****************************************
   end


本站內容除特別聲明的原創文章之外,轉載內容只為傳遞更多信息,并不代表本網站贊同其觀點。轉載的所有的文章、圖片、音/視頻文件等資料的版權歸版權所有權人所有。本站采用的非本站原創文章及圖片等內容無法一一聯系確認版權者。如涉及作品內容、版權和其它問題,請及時通過電子郵件或電話通知我們,以便迅速采取適當措施,避免給雙方造成不必要的經濟損失。聯系電話:010-82306118;郵箱:aet@chinaaet.com。
亚洲一区二区欧美_亚洲丝袜一区_99re亚洲国产精品_日韩亚洲一区二区
亚洲小少妇裸体bbw| 亚洲综合精品四区| 国产精品高潮呻吟久久av黑人| 久久综合99re88久久爱| 先锋影院在线亚洲| 亚洲天堂av在线免费| 亚洲精品一区二| 亚洲第一毛片| 久久国产精品第一页| 亚洲欧美在线aaa| 亚洲小说区图片区| 亚洲午夜精品久久久久久浪潮| 亚洲美女视频网| 亚洲人成网站在线观看播放| 亚洲国产精品一区制服丝袜| 午夜国产精品视频免费体验区| 最新国产の精品合集bt伙计| 亚洲电影自拍| 亚洲国产精品成人久久综合一区| 亚洲高清资源| 亚洲激情成人网| 亚洲每日更新| 中文无字幕一区二区三区| 这里只有精品视频在线| 亚洲素人在线| 亚洲一区www| 亚洲欧美在线播放| 久久精品一区二区| 亚洲欧洲久久| 一区二区三区色| 亚洲女人天堂av| 欧美尤物一区| 久久婷婷色综合| 欧美高清在线| 欧美日韩在线视频一区二区| 欧美一区二区网站| 久久av一区二区三区| 久久久99久久精品女同性| 久久久久久久波多野高潮日日| 久久色在线播放| 欧美成人亚洲成人日韩成人| 欧美日韩精品| 国产精品毛片大码女人| 国产亚洲一二三区| 亚洲国产老妈| 一区二区三区 在线观看视频| 亚洲愉拍自拍另类高清精品| 欧美影院视频| 91久久精品一区二区别| 一区二区国产精品| 午夜精品美女自拍福到在线| 久久精品主播| 欧美理论电影在线观看| 国产精品免费看片| 一区二区在线视频播放| 亚洲精品视频一区二区三区| 亚洲一区二区3| 亚洲第一精品久久忘忧草社区| 99精品热视频| 欧美在线观看你懂的| 欧美1区视频| 国产精品高潮久久| 狠狠色狠狠色综合系列| 亚洲美女在线一区| 西西裸体人体做爰大胆久久久| 亚洲激情婷婷| 亚洲欧美日本国产有色| 美女黄毛**国产精品啪啪 | 欧美成人免费播放| 欧美性一二三区| 樱桃国产成人精品视频| 中国成人亚色综合网站| 亚洲第一搞黄网站| 亚洲欧美日韩国产| 欧美国产日韩二区| 国产日韩欧美一区二区| 亚洲精品久久久一区二区三区| 亚洲欧美综合精品久久成人| 亚洲精选一区二区| 久久国产精品一区二区| 欧美少妇一区二区| **性色生活片久久毛片| 亚洲尤物在线| 一个人看的www久久| 久久免费国产精品| 国产精品试看| 日韩午夜在线| 亚洲激情一区| 久久精品视频免费| 国产精品国产一区二区| 91久久午夜| 亚洲国产成人午夜在线一区| 亚洲欧美日韩综合一区| 欧美精品免费在线| 黄色成人av在线| 亚洲一区激情| 亚洲视频综合在线| 亚洲综合色在线| 欧美激情一区二区三区蜜桃视频| 国产在线视频欧美| 亚洲欧美日韩精品久久久久| 亚洲午夜精品17c| 欧美精品色一区二区三区| 在线播放中文字幕一区| 欧美在线观看网站| 欧美专区18| 国产精品揄拍500视频| 亚洲免费观看高清在线观看| 亚洲国产91精品在线观看| 久久黄色网页| 国产欧美一区二区精品性| 亚洲性人人天天夜夜摸| 中文在线一区| 欧美日韩蜜桃| 99国产麻豆精品| 一本一本久久a久久精品综合麻豆| 欧美韩国一区| 亚洲国产成人在线| 91久久精品日日躁夜夜躁欧美 | 欧美性大战久久久久久久蜜臀| 亚洲韩国青草视频| 亚洲欧洲一区二区三区久久| 另类尿喷潮videofree| 国内精品国产成人| 久久国产精品久久国产精品| 久久精品视频在线看| 国产视频自拍一区| 久久大综合网| 久久综合网络一区二区| 精品成人免费| 亚洲精品一区二区三区婷婷月| 欧美成人综合网站| 亚洲人体1000| 一区二区三区视频在线播放| 欧美视频日韩视频在线观看| 在线一区观看| 欧美一级视频免费在线观看| 亚洲男人的天堂在线| 亚洲一区日韩在线| 欧美少妇一区| 亚洲一区亚洲| 久久国产精品久久w女人spa| 国产在线拍偷自揄拍精品| 亚洲高清视频在线观看| 男女视频一区二区| 亚洲欧洲午夜| 中文av一区特黄| 国产精品亚洲一区| 欧美一级在线亚洲天堂| 久久综合九色综合网站| 亚洲国产精品久久人人爱蜜臀| 亚洲精品视频在线观看免费| 欧美日韩国产精品一卡| 亚洲视频精选| 久久久99精品免费观看不卡| 亚洲电影在线| 一区二区三区偷拍| 国产精品免费一区豆花| 欧美专区在线观看一区| 欧美成人精品激情在线观看| 日韩午夜免费视频| 久久成人18免费观看| 在线精品一区二区| 在线亚洲精品| 国产毛片精品国产一区二区三区| 久久精品99国产精品酒店日本| 欧美激情女人20p| 一区二区三区日韩欧美| 久久精品免费看| 亚洲国产裸拍裸体视频在线观看乱了中文| 夜夜嗨一区二区| 国产视频一区二区在线观看| 亚洲精品久久久久久久久久久久久 | 欧美一区二区在线免费观看| 精品999在线观看| 一区二区三区日韩欧美精品| 国产美女精品在线| 亚洲精品久久7777| 国产精品无人区| 亚洲肉体裸体xxxx137| 国产精品毛片在线| 亚洲欧洲在线免费| 国产精品羞羞答答| 亚洲欧洲综合| 国产精品一区免费观看| 亚洲精品免费在线| 国产欧美精品日韩| 99在线|亚洲一区二区| 国产色爱av资源综合区| 一区二区三区高清不卡| 狠狠色狠狠色综合| 亚洲欧美综合国产精品一区| 亚洲国产精选| 久久久精品动漫| 一区二区三区国产盗摄| 免费不卡中文字幕视频| 亚洲欧美视频一区| 欧美日韩在线播放一区| 亚洲高清在线观看一区| 国产精品试看|