axyd

64-bit System Beep (Windows)

Aug 1st, 2017
1,024
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;-----------------------------------
  2. ;   App: 64-bit System Beep (WIN)   ;
  3. ;   Language: MASM                  ;
  4. ;   Version: 1.0                    ;
  5. ;-----------------------------------;
  6. ;   Date: 01 Aug 2017               ;
  7. ;   Author: Jose Madureira          ;
  8. ;   License: CC0 Public Domain      ;
  9. ;-----------------------------------;
  10.  
  11. ; ## Global constants ##
  12. TAB         EQU 09h     ;Tab
  13. NL          EQU 0Dh,0Ah ;New line
  14.  
  15. ExitProcess PROTO   ;quit program
  16.  
  17. ;WINAPI PRINTF TO DISPLAY MESSAGE
  18. includelib msvcrt.lib
  19. EXTRN printf:PROC
  20.  
  21. ;WINAPI SYSTEM BEEP
  22. includelib kernel32.lib
  23. EXTRN Beep:PROC
  24.  
  25. .data
  26. strFmt byte "%s",0
  27. msgDing byte NL,TAB,TAB," Beep me up scotty! ",NL,0
  28.  
  29. .code
  30. Main PROC
  31.     sub rsp,32  ;reserve shadow space
  32.     mov rax,1               ;1 argument
  33.     mov rcx,offset strFmt   ;printf format
  34.     mov rdx,offset msgDing  ;data to display
  35.     call printf
  36.     xor rax,rax
  37.     add rsp,32  ;clean up
  38.  
  39.     ;beepedy bop
  40.     call _Beep      ;kernel32 call
  41.  
  42.     mov rcx,0
  43.     call ExitProcess
  44. Main ENDP
  45.  
  46. ;####   Beep(frequency,ms)  ###
  47. ;https://msdn.microsoft.com/en-us/library/windows/desktop/ms679277(v=vs.85).aspx
  48. _Beep PROC
  49.     push rbp    ;align stack
  50.     mov rbp,rsp
  51.     sub rsp,32  ;reserve shadow space for Beep(frequency,duration)
  52.  
  53.     ;Example with english flute
  54.     ;http://www.contrabass.com/pages/frequency.html
  55. ;do
  56.     mov rcx,523     ;frequency
  57.     mov rdx,250     ;duration(ms)
  58.     call Beep       ;kernel32 call
  59. ;re
  60.     mov rcx,587     ;frequency
  61.     mov rdx,250     ;duration(ms)
  62.     call Beep       ;kernel32 call
  63. ;mi
  64.     mov rcx,659     ;frequency
  65.     mov rdx,250     ;duration(ms)
  66.     call Beep       ;kernel32 call
  67. ;mi
  68.     mov rcx,659     ;frequency
  69.     mov rdx,250     ;duration(ms)
  70.     call Beep       ;kernel32 call
  71. ;re
  72.     mov rcx,587     ;frequency
  73.     mov rdx,250     ;duration(ms)
  74.     call Beep       ;kernel32 call
  75. ;re
  76.     mov rcx,587     ;frequency
  77.     mov rdx,250     ;duration(ms)
  78.     call Beep       ;kernel32 call
  79. ;do
  80.     mov rcx,523     ;frequency
  81.     mov rdx,250     ;duration(ms)
  82.     call Beep       ;kernel32 call
  83. ;do
  84.     mov rcx,523     ;frequency
  85.     mov rdx,250     ;duration(ms)
  86.     call Beep       ;kernel32 call
  87. ;mi
  88.     mov rcx,659     ;frequency
  89.     mov rdx,250     ;duration(ms)
  90.     call Beep       ;kernel32 call
  91. ;fa
  92.     mov rcx,698     ;frequency
  93.     mov rdx,250     ;duration(ms)
  94.     call Beep       ;kernel32 call
  95. ;so
  96.     mov rcx,783     ;frequency
  97.     mov rdx,250     ;duration(ms)
  98.     call Beep       ;kernel32 call
  99. ;so
  100.     mov rcx,783     ;frequency
  101.     mov rdx,250     ;duration(ms)
  102.     call Beep       ;kernel32 call
  103. ;fa
  104.     mov rcx,698     ;frequency
  105.     mov rdx,250     ;duration(ms)
  106.     call Beep       ;kernel32 call
  107. ;fa
  108.     mov rcx,698     ;frequency
  109.     mov rdx,250     ;duration(ms)
  110.     call Beep       ;kernel32 call
  111. ;fa
  112.     mov rcx,698     ;frequency
  113.     mov rdx,250     ;duration(ms)
  114.     call Beep       ;kernel32 call
  115. ;fa
  116.     mov rcx,698     ;frequency
  117.     mov rdx,250     ;duration(ms)
  118.     call Beep       ;kernel32 call
  119. ;mi
  120.     mov rcx,659     ;frequency
  121.     mov rdx,250     ;duration(ms)
  122.     call Beep       ;kernel32 call
  123. ;mi
  124.     mov rcx,659     ;frequency
  125.     mov rdx,250     ;duration(ms)
  126.     call Beep       ;kernel32 call
  127. ;re
  128.     mov rcx,587     ;frequency
  129.     mov rdx,250     ;duration(ms)
  130.     call Beep       ;kernel32 call
  131. ;re
  132.     mov rcx,587     ;frequency
  133.     mov rdx,250     ;duration(ms)
  134.     call Beep       ;kernel32 call
  135. ;re
  136.     mov rcx,587     ;frequency
  137.     mov rdx,250     ;duration(ms)
  138.     call Beep       ;kernel32 call
  139. ;re
  140.     mov rcx,587     ;frequency
  141.     mov rdx,250     ;duration(ms)
  142.     call Beep       ;kernel32 call
  143. ;do
  144.     mov rcx,523     ;frequency
  145.     mov rdx,250     ;duration(ms)
  146.     call Beep       ;kernel32 call
  147. ;do
  148.     mov rcx,523     ;frequency
  149.     mov rdx,250     ;duration(ms)
  150.     call Beep       ;kernel32 call
  151.  
  152.     ;clean up
  153.     add rsp,32
  154.     pop rbp
  155.  
  156.     xor rax,rax
  157.     ret
  158. _Beep ENDP
  159.  
  160. END
Advertisement
Add Comment
Please, Sign In to add comment