News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Newbie can't make the computer go 'Beep!'

Started by Nicole74, May 31, 2015, 12:44:24 AM

Previous topic - Next topic

Nicole74

So here is my story.  I am using something called HLA, High Level Assembler, which is associated with an online book called 'The Art of Assembly Language' by Randall Hyde.  I do actually intend to learn the lowest level assembly too, but the book is designed for teaching, with the idea that you don't have to rewrite the same stuff over and over again, you just use their functions in the library.

The reason this has anything to do with MASM is because actually, it uses MASM and I have MASM on my computer.  I don't remember exactly how it works, but you start off writing things in HLA, and then it actually assembles it using MASM.  So, you can write a program using all the MASM syntax and it will understand what you mean, but you can also use the high level functions too.

Well, I was doing fine through the very beginning of the book.  I was working on this last year.  I worked on it for a few weeks, and then all of a sudden I got to an input-output chapter where they mentioned a function that makes it go beep.  I tried to tell it to go beep, and it did not go beep.  The perfection of my universe was shattered, and I took a break from the book to go curl up in a ball and cry. 

Now that I have recovered from this trauma, I'm wondering how I can directly use MASM to make the computer go beep, instead of using the HLA function.  This HLA and the book was written a long-ish time ago, like 2000, and so maybe something has changed so that my little netbook doesn't know what to do.  It says that the beep comes from printing an ASCII character.

I am able to make my computer beep if, for instance, I have a key pressed down while the computer is starting up.  I assume that's the type of beep that this is supposed to make. 

Dell Inspiron mini, Windows 7 starter, Intel chip... but I'm not sure what would be relevant.  And it's a couple years old so all the writing is worn off the little stickers underneath it that have all the specifications on them. 

Here is what the book says: "In addition to the nl constant, the HLA standard I/O library module defines several other useful character constants. They are: stdio.bell - The ASCII bell character. Beeps the speaker when printed."  Etc.

So here's the type of thing you see with HLA.  By my understanding, I can just start talking to MASM directly if I want to at any point in the program, instead of using HLA.  Any suggestions for what I can say to MASM to try to make the thing beep?

program Bell2;

#include( "stdlib.hhf" );
#include( "stdio.hhf" );

begin Bell2;

stdout.put( "Why won't this beep?", stdio.bell );

end Bell2;

(Note: I keep calling them 'functions,' but actually I'm not clear on what's a function, what's a macro, what's a constant, and so on - I think he said the stdio.bell was a CONSTANT, now that I look again.)

hutch--

You real problem is that HLA is no longer properly supported where MASM is much better understood and has a much larger user base. You need to know what OS platform you want to use (DOS versus Windows) and learn the details of what you want to eventually write. Windows has a function "PlaySound" that can run a WAV file that can be anything you like from music to beeps.

Now among other things you computer may not have the hardware to sound an ascii bell character as it would be very rarely used these days. If you go for the later stuff using MASM you can do almost anything but its more work to learn it and you also need to learn the Windows API function.

Nicole74

I do know it has the hardware to beep, because it beeps if I hold down a key while the computer is turning on.  That beep comes from the internal computer speaker. That's the one I'm trying to make beep.  It says you use an ASCII character that causes this speaker to beep when printed.  It isn't a .wav file type of sound.  HLA is based on MASM and uses MASM as its assembler, and I am able to write a program using MASM syntax within an HLA program, so I'm actually looking for MASM code, not HLA code.  The HLA program allows you to write something either in MASM or HLA.

Nicole74

Actually, you might be right, I just looked it up in Wikipedia and did what they said.  It's the bell character in ASCII.  Wikipedia said you can also get this by typing 'echo ^G' in a command prompt, and I did that, and it did not make the noise.  So, apparently that's not the same thing as the other alarm that I hear if I hold down a button while turning the computer on.

I don't actually mind if HLA is no longer supported.  The book eventually gets around to directly teaching assembly language with MASM.

hutch--

You have not told us yet whether you are writing 16 or 32 bit code. In 16 bit code you send an ASCII bell to STDOUT and you get a BEEP, 32 bit code does not work that way. Win7 in 64 bit does not support 16 bit DOS so anything you need to write will have to be 32 bit or later. Windows does not support the 16 bit interrupt and if you want to make a sound, you will have to use a Windows API function and play the default sound for a beep set up in your control panel.

dedndave

very few members have played with HLA, much   :P
might as well be greek to most of us - lol

but, it's fairly simple if you have the masm32 package installed
;###############################################################################################

        INCLUDE    \Masm32\Include\Masm32rt.inc

;###############################################################################################

        .CODE

;***********************************************************************************************

main    PROC

        INVOKE  Beep,800,100
        INVOKE  ExitProcess,0

main    ENDP

;###############################################################################################

        END     main


Vista had problems with Beep, as i recall, but it should do MessageBeep...
;###############################################################################################

        INCLUDE    \Masm32\Include\Masm32rt.inc

;###############################################################################################

        .CODE

;***********************************************************************************************

main    PROC

        INVOKE  MessageBeep,-1
        INVOKE  ExitProcess,0

main    ENDP

;###############################################################################################

        END     main


as i recall, the user must have a sound selected for "Default Beep" (control panel, sounds)

because of the "Vista problem", many of us prefer to use PlaySound, as Hutch suggested
that's a bit more complicated because it involves carrying a sound file as resource

this post in the "old forum" has an attachment....

http://www.masmforum.com/board/index.php?topic=15882.msg131239#msg131239

hutch--

You can try this from a CMD prompt.

Type "echo" then 1 space then ALT + 7 then hit enter.

jj2007

As Hutch & Dave already mentioned, HLA is not the best option. Masm32 with PlaySound from the Windows API is the way to go if you want to know what's going on under the hood. If you care a bit less, you can use a library, too:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  Sound "880:500"             ; plays frequency 880Hz for 500 ms; allowed separators are space, tab, / and :
  Sound 111                   ; plays a wav resource with ID 111 (in rc file: 111 WAVE "hello.wav")
  Sound "hello.wav"           ; plays a file directly (wav only)
  Sound "hello.mp3"           ; plays a file in its associated player
  Sound "大桥在混乱的水.mp3"    ; Unicode names are allowed
  Sound Utf8$(wCL$())         ; even if passed via the commandline
  Exit
end start


Note this does build fine if MasmBasic is installed, even with \Masm32\qEditor.exe, but of course, the mp3 and wav files must be present in the executable's path, and resource #111 must be included; comment out what is not needed or not possible.

Zen

#8
NICOLE74,
This might help: Waveform Audio, MSDN
As HUTCH mentioned in his first post, PlaySound is the simplest audio function to use. There's also: MessageBeep.

...By the way,...I should warn you about DAVE. He's our official MASM Forum Joker. Very knowledgeable programmer, though,...
(PullMyFinger by DednDave) is one of his better apps. It's designed to drive newbies crazy:

;PullMyFinger by DednDave - Jan 2011

        include    \masm32\include\masm32rt.inc
        include    \masm32\include\winmm.inc
        includelib \masm32\lib\winmm.lib

IDS_PMF EQU     1000

        .DATA?

hInstance dd ?

        .CODE

_main   PROC

        INVOKE  GetModuleHandle,NULL
        mov     hInstance,eax
        print   chr$('Esc to Exit, Any Other Key to Pull My Finger'),13,10
        jmp short loop01

loop00: INVOKE  PlaySound,IDS_PMF,hInstance,SND_RESOURCE

loop01: call    crt__kbhit
        or      eax,eax
        jnz     loop02

        INVOKE  Sleep,50
        jmp     loop01

loop02: call    crt__getch
        cmp     eax,1Bh
        jnz     loop00

        exit

_main   ENDP

        END     _main


rrr314159

Hi Nicole,

Everybody's already told you what I can tell you, but it might be confusing, some extraneous info ... As a previous post put it,

Quote from: Nicole74So that's more than anybody wanted to know

So here's my take on it.

First, Randall Hyde and HLA is (partly) obsolete. This beep is a good example: that technique doesn't work on your computer; there will be more like that. So I'm afraid u need a different tutorial, more on that later.

Second, if you haven't downloaded masm32 package, and installed it, you should. That's the best way to move ahead, especially if you use this board. Go to www.masm32.com, click on "download" at the top, etc. Ask if any problems.

As for "beep"ing - once you have masm32 installed dedndave's first program is the quickest way to beep. Here it is again but with a longer beep (note to dedndave, some computers don't do 100 ms right)

;###############################################################################################

        INCLUDE    \Masm32\Include\Masm32rt.inc

;###############################################################################################

        .CODE

;***********************************************************************************************

main    PROC

        INVOKE  Beep,440,1000
        INVOKE  ExitProcess,0

main    ENDP

;###############################################################################################

        END     main


That's great but how do you run this code? I'm going to assume you don't already know (if you do please excuse my "talking down" at you). Here's a quick precis of the steps involved, ask if trouble occurs (do NOT

Quote from: Nicole74...curl up in a ball and cry

)!

1. Make a new folder anywhere u want
2. Make a new text document (not rtf or anything, straight text) in your new folder
3. Name it beep.asm (you'll have to change the file extension, it will ask r u sure, say yes)
4. Now double-click and it will come up blank in masm32's Qeditor (assuming you installed it right)
5. Grab the code above by clicking on Code:[select], which will Copy it to the clipboard
6. Paste it into beep.asm, and save it (from the file menu, or hit CTRL-S)
7. From "Project" Menu: Console Assemble & Link (towards the bottom)
8. Then Project: Run Program
9. DOS window will flash and it will beep 1 second, concert-pitch A
10. If you're lucky

After that the world's your oyster ... but you'll need a bit more guidance b4 comfortable with masm32 environment. Perhaps jj2007's tutorial would be right for you. May be a bit intimidating for beginner, there are other options.

Randall Hyde's book (1st edition anyway) is full of good info and your time hasn't been wasted, but as I say u need to get away from HLA. Once u get masm32 working recommend continuing with the parts that are applicable but ignore those that aren't :biggrin:

Good luck, c u later
I am NaN ;)

Nicole74

My frustration tolerance is increased when I can complain to this support group. So I will just take a walk and get some fresh air and when I come back I will try some of these things.  I did try alt-7 (typo, I didn't mean alt-F7), and that didn't work either, but I want to try it again because a google search made it seem like there was more than one way to do it, with the details differing. I'm not sure if I'm programming in 16 bit or 32 bit, because that makes it sound like I have a choice or it's a mode or something - but my operating system itself says that it's 32 bit, which doesn't necessarily mean anything to me. I have a hunch that 'pullmyfinger' might result in a low frequency buzz. I will be back.

rrr314159

I sense you don't want to abandon Randall Hyde, after all u've been thru together .. ! There is a masm32 forum for Randall Hyde's HLA specifically but as you see there's almost no activity. Recommend u try our approach a bit, can always go back. I did some research on this topic ...

Found this site, asmcommunity.net where Mr Hyde himself was a member, in 2003. Here's what Randy Hyde (that's his handle) says:

Quote from: Randy HydeI would comment that in one sense, HLA is *inappropriate* for advanced assembly programmers. Because advanced assembly programmers already know an assembly language and have some strong expectations about what an assembler should look like. Regardless of the features HLA supports, the fact that its syntax is radically different than a traditional assembler is going to create problems for them ...

- so if this were 2003 u should definitely go post your questions there. But 8 years later that site decided HLA was obsolete. Here's relevant thread, about porting HLA to MASM (the guy was giving up on HLA) and a quote, from 2011, with my italics:

Quote from: HomerHistorical note, after he [Randall Hyde] failed and went his way ...  not that I don't think you are a legend Randy, you opened my eyes!

- This supports our view that HLA is basically dead. But at least asmcommunity.net has had MUCH more interest in it, so you should explore that site. We'll be happy to "support" you whatever road u decide on ...

Finally, ALT-7 and 16 vs 32 bit are very good examples of what I mentioned b4, "too much information"; you're using 32 bit, BTW, and ALT-7 bell won't work on your computer. 

Historical note, in the past, my advice has often turned out to be wrong ;)
I am NaN ;)

Nicole74

Quote from: dedndave on May 31, 2015, 02:28:55 AM##############################################

        INCLUDE    \Masm32\Include\Masm32rt.inc

Okay... Before I tried this, I looked in the masm include folder to make sure I had this.  I don't.  I just have masm32.inc, but not masm32rt.inc.  I had actually tried to download and install the latest MASM, but it told me it was already installed (due to my having installed HLA), so I have an older version.  I googled 'how to uninstall MASM,' because it wasn't listed in the control panel's 'uninstall a program' screen, and I discovered that MASM has to be just sort of... deleted, somehow, which I am kind of scared to do.  They said that it was a small thing that doesn't attach itself to stuff all over your computer and it was supposed to be sort of independent somehow, so you were able to delete it. 

Anyway, now that I'm thinking about this, would it be possible to just download the masm32rt.inc include file, and then just put it into the include folder with all the other include files?

I could also just try to follow the advice about how to uninstall (delete) MASM, but I'd have to google it again, and then install the new version that I downloaded.

So... I didn't get to test this yet.

rrr314159

If it ain't one thing it's another! Probably more hiccups coming up, too.

masm32 is in fact a very "small thing" which doesn't modify the registry or any of that garbage (which is very good). Don't think it best to just get masm32rt.inc; how many more incompatibilities are there? People like hutch could answer that q. BTW, but not me. However don't blame u not wanting to delete the old one, what if u want to go back to HLA?

So, two solutions. One, change the name of the masm32 folder to masm32_HLA, then install masm32 latest version. Should work without a hitch. Later, can just delete that folder (or, call it masm32_NEW) and rename the old one back.

Or, here's the file, you can try putting masm32rt.inc in your include folder as u said.

comment * «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    The MASM32 Runtime Library include file.

    Differing from most compilers, MASM does not contain any built in
    run time library so it is difficult for a programmer starting with
    MASM to to get any code up and running without having to learn a lot
    of extra information just to do basic things.
   
    This file simplifies entry into assembler programming by making the
    full capacity of the MASM32 library, macro system and include files
    available to programmers undertaking this quest.

    It specifies the normal conditions for building a 32 bit Windows
    program with the minimum processor type, memory model and the need
    for case sensitive capacity.

    The include files are declared in the correct order so that the
    windows.inc file is always first followed by static libraries and
    import libraries for Windows API functions.

    Where there is a corresponding library for either static or import
    libraries, it is included after the include files.

    NOTE : It is to the advantage of the programmer once they have their
    basic code up and running to properly understand the architecture
    of a MASM executable file so that they can construct their own
    projects to more accurately reflect their own application design.

  ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««« *

      .486                                      ; create 32 bit code
      .model flat, stdcall                      ; 32 bit memory model
      option casemap :none                      ; case sensitive

;     include files
;     ~~~~~~~~~~~~~
      include \masm32\include\windows.inc       ; main windows include file
      include \masm32\include\masm32.inc        ; masm32 library include

    ; -------------------------
    ; Windows API include files
    ; -------------------------
      include \masm32\include\gdi32.inc
      include \masm32\include\user32.inc
      include \masm32\include\kernel32.inc
      include \masm32\include\Comctl32.inc
      include \masm32\include\comdlg32.inc
      include \masm32\include\shell32.inc
      include \masm32\include\oleaut32.inc
      include \masm32\include\ole32.inc
      include \masm32\include\msvcrt.inc

      include \masm32\include\dialogs.inc       ; macro file for dialogs
      include \masm32\macros\macros.asm         ; masm32 macro file

;     libraries
;     ~~~~~~~~~
      includelib \masm32\lib\masm32.lib         ; masm32 static library

    ; ------------------------------------------
    ; import libraries for Windows API functions
    ; ------------------------------------------
      includelib \masm32\lib\gdi32.lib
      includelib \masm32\lib\user32.lib
      includelib \masm32\lib\kernel32.lib
      includelib \masm32\lib\Comctl32.lib
      includelib \masm32\lib\comdlg32.lib
      includelib \masm32\lib\shell32.lib
      includelib \masm32\lib\oleaut32.lib
      includelib \masm32\lib\ole32.lib
      includelib \masm32\lib\msvcrt.lib

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««


Now, I could put this in a zip file for u but didn't for a couple reasons. There may be copyright issues - can't imagine hutch would care, but I want it to be visible so everyone sees what I'm doing. Also, so u can see how simple the file is, and read the comments. Finally, I'm wondering if you'll have a little problem putting this into a file. So, make new text file, rename it masm32rt.inc, copy this code into it, put it into include directory. If it works, great, if not, might be one or two simple fixes needed.

If you do it this way instead of installing new masm32, expect something else to go wrong sooner or later ..

Good luck, !
I am NaN ;)

Nicole74

So, I do already have QuickEditor, which was mentioned somewhere when I was doing HLA, so I already knew that existed and have been using it.  I just looked in the 'help' button there, and there's a bunch of stuff that I should read.  I don't yet know the basics of how to use QEditor to assemble and run the programs, so, no, @rrr, you're not talking down to me if you assume the worst - I don't actually know what buttons to push in QEditor yet.  What I was doing before was using notepad, then using a command line to run HLA.  Now I'm going to start attempting to use QEditor and try to interact with MASM directly and bypass HLA, so I'm at the very beginning of learning how to do that - I also just downloaded three volumes of pdf files from Intel, the reference manuals, but those will be probably too hardcore for me as of now, although I didn't actually start reading them yet. 

So, my goal right now is simply to start using MASM directly without using HLA.  I did want to stay attached to the HLA book, and I might keep reading it just because I like the writing style.  He was a teacher, so he had a lot of experience explaining it to the students, I guess.