Server Help

Trash Talk - Code that does nothing forever...

k0zy - Wed Apr 07, 2004 2:10 pm
Post subject: Code that does nothing forever...
I was bored... so I coded a few programs or scripts that do nothing forever...

In c++:
Code: Show/Hide
int main() {
  while (1) { ; }
}


In python:
Code: Show/Hide
while 1: pass


In assembly (for MFA):
Code: Show/Hide
.org 0E00h
start: MVI C,0FFh
NOP
DCR C
JZ start
.end


What languages do you know?
And how do you make then do nothing forever?

Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole....
D1st0rt - Wed Apr 07, 2004 2:41 pm
Post subject:
java:

while(true)

or you could do like
for(int i = 1; i > 0; i++)
Anonymous - Wed Apr 07, 2004 2:49 pm
Post subject:
Code: Show/Hide
while(1);

Gravitron - Wed Apr 07, 2004 2:59 pm
Post subject:
Good ol' GWBasic:
Code: Show/Hide

100 Go 100

$
Dustpuppy - Wed Apr 07, 2004 3:36 pm
Post subject:
Befunge:

Code: Show/Hide
><

k0zy - Wed Apr 07, 2004 3:43 pm
Post subject:
Any other commands that do nothing? icon_wink.gif

c:
Code: Show/Hide
;

python:
Code: Show/Hide
pass

assembly:
Code: Show/Hide
NOP

Dustpuppy - Wed Apr 07, 2004 3:49 pm
Post subject:
Does continue (C++) count? tongue.gif
k0zy - Wed Apr 07, 2004 3:59 pm
Post subject:
continue actually does something icon_razz.gif
Mr Ekted - Wed Apr 07, 2004 4:34 pm
Post subject:
Code: Show/Hide
HANDLE h;

h = CreateObject(CONTINUUM_40);
WaitForSingleEvent(h, INFINITE);

Mine GO BOOM - Wed Apr 07, 2004 5:11 pm
Post subject:
Mr Ekted wrote:
Code: Show/Hide
HANDLE h;

h = CreateObject(CONTINUUM_39_OFFICIAL);
WaitForSingleEvent(h, INFINITE);

Fixed it for you.

And for asmembly, jumping to the jump command is a much faster nothingness.
Anonymous - Wed Apr 07, 2004 5:27 pm
Post subject:
EB FE

icon_biggrin.gif
50% Packetloss - Wed Apr 07, 2004 6:22 pm
Post subject:
Every program does something, even NOP increments the program counter

-ASM for the Motorola 6800
0000 BRA (20)
0001 02

-C
Bob:
goto Bob;
liito-orava - Wed Apr 07, 2004 6:25 pm
Post subject:
50% Packetloss wrote:

-C
Bob:
goto Bob;

That's so ugly. :/
k0zy - Wed Apr 07, 2004 6:50 pm
Post subject:
50% Packetloss wrote:
Every program does something, even NOP increments the program counter


Would be painfull if it didn't increase the program counter! icon_wink.gif
Usually NOP is used to wait 4 cpu clock cycles... which is nothing...

Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole....
Helicon - Wed Apr 07, 2004 8:00 pm
Post subject:
D1st0rt wrote:
for(int i = 1; i > 0; i++)


this just runs until the int ceiling value... it stops
Mr Ekted - Wed Apr 07, 2004 10:40 pm
Post subject:
50% Packetloss wrote:
Every program does something, even NOP increments the program counter


EB FE doesn't increment the program counter.
Anonymous - Thu Apr 08, 2004 3:12 am
Post subject:
BASIC:
Code: Show/Hide

DO
LOOP

k0zy - Thu Apr 08, 2004 7:11 am
Post subject:
Mr Ekted wrote:
[..]



EB FE doesn't increment the program counter.


What's EB FE?
Mr Ekted - Thu Apr 08, 2004 11:59 am
Post subject:
Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole.... wrote:
What's EB FE?


It's Intel machine code for:

label: jmp label
Mr Ekted - Thu Apr 08, 2004 1:52 pm
Post subject:
Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole.... wrote:
Usually NOP is used to wait 4 cpu clock cycles...Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole....


NOP has never taken 4 clock cycles. Pentium it is less than 1, 486 was 1, 386/286/86 was 3. Writing code that assumes a certain number of cpu clocks is very bad.
Mine GO BOOM - Thu Apr 08, 2004 4:23 pm
Post subject:
Mr Ekted wrote:
Writing code that assumes a certain number of cpu clocks is very bad.

I see no problem when playing DigDug. You just have to be a better player.
Dr Brain - Thu Apr 08, 2004 4:49 pm
Post subject:
Or, do what normal people do, underclock their CPU.
k0zy - Thu Apr 08, 2004 4:58 pm
Post subject:
Mr Ekted wrote:
[..]



NOP has never taken 4 clock cycles. Pentium it is less than 1, 486 was 1, 386/286/86 was 3. Writing code that assumes a certain number of cpu clocks is very bad.


We learned assembly at school for programming MFAs (8085). And I'm sure that NOP just waits a few clock cycles. I thought it was 4, I have to look it up in my book.

EDIT: Yeah, my books says: NOP / No operation / 1 byte / 4 clock cycles

Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole....
pixelsoft - Sun Apr 11, 2004 5:59 am
Post subject:
php:
Code: Show/Hide
<?php
//
?>

Sercit - Sun Apr 11, 2004 6:25 am
Post subject:
You know your a coder with too much time on your hands, and no porn at the ready, when you type up codes that do nothing, forever. tongue.gif
1stStrike - Sun Apr 11, 2004 9:10 am
Post subject:
Programming is one of the most boring, annoying and pain in the ass things out there. I get no joy whatsoever from it and hate every class I'm forced to go to.
Cyan~Fire - Sun Apr 11, 2004 10:17 am
Post subject:
Awww 1st, you're no fun!
ExplodyThingy - Sun Apr 11, 2004 1:04 pm
Post subject:
while(first.patrypooper()) { ; }
Cyan~Fire - Sun Apr 11, 2004 2:27 pm
Post subject:
biggrin.gif
Dustpuppy - Sun Apr 11, 2004 3:33 pm
Post subject:
Code: Show/Hide

int i = 3324;

i = 15;
i /= 3;
i *= 4;
i /= 10;
i--;

while (i == 1)
{
   char moo[20];
   char *a;
   strcpy(moo, "Mooo!");
   a = &*moo;
   a += i;
   itoa(*a, moo, 10);
   a = &*moo;
   for (int x=0;x<=1;x++)
      a++;

   i = atoi(a);
}   

Solo Ace - Thu Apr 15, 2004 1:50 pm
Post subject:
Helicon wrote:
[..]

this just runs until the int ceiling value... it stops


for ( ; ; )

icon_smile.gif
CypherJF - Thu Apr 15, 2004 3:18 pm
Post subject:
^_^ ugg
Mr Ekted - Thu Apr 15, 2004 4:26 pm
Post subject:
Of course, most of the examples posted so far would use 100% CPU, so they do far from nothing. icon_smile.gif
Dr Brain - Thu Apr 15, 2004 4:48 pm
Post subject:
But technicly, even code that is doing nothing is doing something. It's doing nothing, and nothing is something.

Everything is something, even nothing.

And if you think I have a lot of things (like nothing, everything, and something) in this post, you have another thing coming.
Cyan~Fire - Thu Apr 15, 2004 6:01 pm
Post subject:
Thing count: 13 icon_biggrin.gif
k0zy - Thu Apr 15, 2004 8:10 pm
Post subject:
Dr Brain wrote:
But technicly, even code that is doing nothing is doing something. It's doing nothing, and nothing is something.

Everything is something, even nothing.

And if you think I have a lot of things (like nothing, everything, and something) in this post, you have another thing coming.


Nothing can have no properties, cuz no porperty is a property and nothing is something! That's some weired stuff...

Anyways, back to topic...
@ekted:
Which codes of the ones posted does not use 100% of the cpu?

Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole....
Mr Ekted - Thu Apr 15, 2004 9:07 pm
Post subject:
As far as the "doing nothing forever" topic, only mine uses 0% CPU:

WaitForSingleEvent();

as long as the event never triggers.
Cyan~Fire - Thu Apr 15, 2004 10:17 pm
Post subject:
It's impossible that a loop can use 0% CPU... it has to be doing something somewhere...

Err and interesting title, MGB icon_eek.gif
Mr Ekted - Fri Apr 16, 2004 12:33 am
Post subject:
WaitForSingleEvent() is a Windows function that suspends your thread until the specified event occurs. It does not run. It does not execute any instructions. It does not take any CPU.
Cyan~Fire - Fri Apr 16, 2004 8:14 am
Post subject:
Wacky. icon_razz.gif
Grelminar - Mon Apr 19, 2004 4:40 am
Post subject:
The purest infinite loop uses no looping constructs or explicit recursion, only the idea of self-application:

((lambda (x) (x x)) (lambda (x) (x x)))

And this one makes your head explode when you try to figure out how it works:

((call/cc (lambda (x) (x x))) (call/cc (lambda (x) (x x))))

Finally, if you're looking for something to make your CPU actually do nothing, as opposed to looping infinitely, the best method is to remove the power cord from the back of your box. It saves more energy than just putting your thread to sleep, too!
Maucaub - Sat Apr 24, 2004 12:52 am
Post subject:
Grelminar wrote:
((call/cc (lambda (x) (x x))) (call/cc (lambda (x) (x x))))

Ugh, that's just .... evil ....

And just to be anal for those who care about such things, a NOP truly does nothing while EB FE actually does alter the program counter. Instructions are pre-incremented by the hardware in the CPU, hence a NOP does nothing but wait for the next instruction while EB FE substracts 2 from the instruction pointer (that's what the FE part is for!). Of course, all of these details become blurred when considering modern superscalar pipelined architectures with dynamic scheduling and branch prediction, anyway ...
Mr Ekted - Sat Apr 24, 2004 1:10 am
Post subject:
Well, the RESULT of a NOP is that the PC in incremented. The RESULT of EB FE is that the PC does not change.
D1st0rt - Sat Apr 24, 2004 10:15 am
Post subject:
oh I just thought of how to do it on a TI-83

Lbl A
Goto A

or you could just do

While(1)
End
Smong - Sat Apr 24, 2004 10:43 am
Post subject:
If the PC does not change with EB FE how do you break out of it? Are you supposed to put stuff between the EB and FE?
50% Packetloss - Sat Apr 24, 2004 1:38 pm
Post subject:
What is a EB FE anyway? A Wait for Interupt?
k0zy - Sat Apr 24, 2004 1:41 pm
Post subject:
Why would
Code: Show/Hide
lbl: jmp lbl

ever inc the PC?
There's no sense in it... I think... icon_wink.gif

Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole....
k0zy - Sat Apr 24, 2004 1:43 pm
Post subject:
50% Packetloss wrote:
What is a EB FE anyway? A Wait for Interupt?


Mr Ekted wrote:
It's Intel machine code for:

label: jmp label

Mr Ekted - Sat Apr 24, 2004 3:29 pm
Post subject:
Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole.... wrote:
Why would
Code: Show/Hide
lbl: jmp lbl

ever inc the PC?
There's no sense in it... I think... icon_wink.gif
Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole....


Well, internally what happens is once an instruction is loaded--in this case 2 bytes--the program counter (called EIP in Intel) is advanced 2 bytes. Then the instruction is executed. This instruction basically says EIP = EIP - 2. So the actual increment and decrement does occur in the micro-code.

To answer the other question: If you indeed had EB FE in your program and the CPU "found" it, your program would go 100% CPU and "lock up", requiring a kill. It is not a naturally occurring instruction, unless you wrote some C code like:

Code: Show/Hide
Here: goto Here;

k0zy - Sat Apr 24, 2004 4:30 pm
Post subject:
Mr Ekted wrote:
[..]Well, internally what happens is once an instruction is loaded--in this case 2 bytes--the program counter (called EIP in Intel) is advanced 2 bytes. Then the instruction is executed. This instruction basically says EIP = EIP - 2. So the actual increment and decrement does occur in the micro-code.


Yeah, acutally all that "jmp lbl" does is to decrement the eip to the point where the lbl is...
Which is, in this case, the same as it has been before jmp.

I'm going to write my A-level exam on monday, and a part of it will be assembler for 8085. Interupt aso...

Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole....
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group