PDA

View Full Version : Loop FOR Beep


jackall
June 11th, 2008, 14:20
While trying to familiarize with the FOR Loop, using different values for variables i found at certain values a beep sound is produced when trying to open the executable. (That EXE is attached.)

It was not done intentionally...just happened.

When I change the string value the beep gets stopped at certain values.

Why does this happen; what causes it?
A little extension on this subject, i wonder if one could possibly to get a specific number of beeps instead of one that it produces right now....

Just Curious!!

naides
June 11th, 2008, 18:34
I am too drunk too do an in depth analysis, but:

There is an ASCII value, 0x07, that used to produce a "bell" or "beep" in the old computers when you "wrote" such character to the screen. that was what happened when computers had a pitiful speaker connected almost directed to the CPU.
How this "sound character" became emulated in the current day computer which comes equipped with a windows sound library and a sound card that plays Dolby 5.1 streams, I am not sure. But I can tell you this much: writing to the console the char with the value "0x07" in your loop experiments is bound to to produce a beep. What you are seeing, or listening or experiencing is the fuck up of the sound card emulation, which fucks up if you try to trace such an old and elementary IO in a current day computer.

ZaiRoN
June 12th, 2008, 08:05
Just to confirm naides's words, 0x07 byte & fwrite:
Code:

004113A1 MOV DWORD PTR SS:[ESP+4],EDX // Size in bytes of each element: 1
004113A5 MOV DWORD PTR SS:[ESP+C],EAX // Pointer to a FILE object that specifies an output stream
004113A9 MOV EAX,DWORD PTR SS:[EBP+10]
004113AC MOV DWORD PTR SS:[ESP+8],EAX // Number of elements: 1
004113B0 MOV EAX,DWORD PTR SS:[EBP+C]
004113B3 MOV DWORD PTR SS:[ESP],EAX // Pointer to 0x07 byte
004113B6 CALL <JMP.&msvcrt.fwrite>
You have the source and you should be able to reproduce the annoying beep as many times as you need...

Maximus
June 12th, 2008, 08:22
...from the old time, when monitors where black and green...

open your dos console (cmd in windows :P ), press control+G [you'll see ^G], and then hit the magic enter.

Enjoy your beeps

jackall
June 12th, 2008, 08:47
Very informative response from naides...ZaiRoN. and Maximus …Thank you.

naides observes:
Code:
writing to the console the char with the value "0x07" in your loop experiments
is bound to produce a beep.


Well ! this is the code fragment that caused the issue …

{
char base[6]="12345";
char exponent[6]="22222";

for(int x=0;x<5;x++)
{
base[x]= base[x]^exponent[x];
cout<< base[x]<<endl;
}

Where in the code the perpetrator 0x 07 exists ?
Moreover, when the variable ‘exponent’ is altered to ' 77777 ' the ‘Bell’ stays silent.

ZaiRonN’s comments need to be studied …need more time.

Well ! Maximus’s contribution is interesting...

Regards….

Admiral
June 12th, 2008, 12:57
It seems your code is a little confused, jackall. In C++ (and C), the ^ operator performs an XOR, not exponentiation, so either your variable nomenclature is extremely perverse or you should be using the pow function via floats (though you'd probably want to use a bespoke modular exponentiation function for anything serious).

Anyway, your base and exponent arrays are initialised as strings, with the chars taking the values of the ASCII values corresponding to the digits 1 through 5. What's really happening is this:

char base[5] = {49, 50, 51, 52, 53};
char exponent[5] = {50, 50, 50, 50, 50};

Expressed in binary, these two arrays look like:

00110001 00110010 00110011 00110100 00110101
00110010 00110010 00110010 00110010 00110010

And XORing them together gives:

00000011 00000000 00000001 00000110 00000111

So by the time each element reaches cout the values are:

03 00 01 06 07

That last value accounts for one beep by the previous dialogue, but I couldn't say where the rest are coming from. Considering how far separated we are from those old days, I wouldn't be surprised if any unprintable ASCII values (which include all those above except the 0) resulted in a beep. That's a guess.

By the way, whose idea was it to disallow the <tt> tag in our posts ?
Do we have an alternative ([code] excluded)?

TBone
June 12th, 2008, 14:34
If you enable hidden devices in the device manager, you'll see that there's actually a device called "beep" with a Device Instance Id of "ROOT\LEGACY_BEEP\000". It binds to the "Beep" service, which seems to be implemented in beep.sys.

Beep.sys in turn imports a function called HalMakeBeep from hal.dll. I'm not much at interpreting system code, but it appears to accept one parameter for the frequency. Calling HalMakeBeep will make the speaker emit the chosen frequency until it is called again with a different frequency or 0 to make it stop.

I don't know why, but it amuses me that there's an entire driver devoted to making the old system speaker go "FEEEP!". I'm even more amused that something as simple as the system speaker is still subject to hardware abstraction .

Kayaker
June 12th, 2008, 15:21

<div style="margin:20px; margin-top:5px; "><div class="smallfont" style="margin-bottom:2px">Quote:</div><table cellpadding="6" cellspacing="0" border="1" width="90%"><tr><td class="alt2" style="border:1px inset"><i>[Originally Posted by Admiral;75110]

By the way, whose idea was it to disallow the &lt;tt&gt; tag in our posts 

Do we have an alternative ([code] excluded)?</i></td></tr></table></div>



Ahah, caught you again 



I had to put in a script modification to the imported blog rssfeed so vBulletin could deal with those tags.  Somebody kept using them in their blogs..



 
       // Ring3 Circus uses these!



        // Regex for &lt;tt&gt;&lt;/tt&gt; tags

        $ttstart = '%&lt;tt&gt;%sim';            

        $ttend = '%&lt;/tt&gt;%sim'; 



vBulletin doesn't handle those tags, among others, so for imported blog posts only I replace the block of text with a Courier New FONT tag.



Regular forum posts don't handle &lt;tt&gt; tags either, but it might be possible to add a new bbcode for it, I'll take a look.



K.


Admiral
June 12th, 2008, 16:12
I'm not sure whether to feel good for being important enough for my own script entry, or bad for being a pain in the ass
But don't worry too much about the bbcode - I'm sure can live in the absence of fixed-pitch formatting. What I can't guarantee, though, is that it won't anger me to the point of becoming the next LLXX

Admiral

naides
June 12th, 2008, 16:26
Admiral, just come to grips with it. . . admit it.
You are the next LLXX:
Talented, deranged and insanely wound up about nothing important

dELTA
June 13th, 2008, 08:21
...so now all you gotta do is to not get laid for five years, and start being a real asshole to everyone, and you will be fully trained.

Silver
June 13th, 2008, 12:54
dELTA, showing us the way!

jackall
June 14th, 2008, 11:37
Code:
It seems your code is a little confused, jackall. In C++ (and C), the ^ operator
performs an XOR, not exponentiation, so either your variable nomenclature
is extremely perverse.

Admiral…
" I'm not confused, I'm just well mixed. " - Robert Frost .
So, i got a little mix up of all these alien concepts.

My pale familiarity with the ^ operator led me to a wrong supposition.
The Nomenclature abnormality is caused by lack of awareness in the required field.
Don’t misunderstand … 'am not applauding ignorance …

Well... Your illumination on these two points has produced enough details in shadows and it is noted with appreciation.

Next ..still better ... the enrichment in plain words … answer to my query.

Code:
char base [5] = {49, 50, 51, 52, 53};
char exponent[5] = {50, 50, 50, 50, 50};

Expressed in binary, these two arrays look like:
00110001 00110010 00110011 00110100 00110101
00110010 00110010 00110010 00110010 00110010

And XORing them together gives:
00000011 00000000 00000001 00000110 00000111

So by the time each element reaches cout the values are:
03 00 01 06 07

Thank you for your taking the time to give details readily.

Regards .

Admiral
June 14th, 2008, 12:49
Jackall - you're welcome to the help, and please don't take my formal and condescending tone personally
There's nothing wrong with your notation at all, given that you misunderstood the (admittedly rather deceptive) ^ operator.

May I ask what it is that the code is trying to achieve? There are a few 'gotchas' in C (far more in C++), and you seem to have stumbled upon several of them in a very short code snippet :P. Perhaps if you explained what the program is supposed to do (assuming that you had a goal) we could help point you in the right direction.

Admiral

Woodmann
June 14th, 2008, 15:58
Admiral,

That last post offering help is so anti-LLXX.

Woodmann