SuperHack

MerickOWA
Posts: 182
Joined: Mon Apr 07, 2008 5:54 pm
Location: HkRkoz al KuwaiT 2019 HaCkEr 101

SuperHack

Post by MerickOWA »

Just trying to understand the instructions.

The '@' instruction i have a little trouble understanding. In the following example.

Code: Select all

@\!
 $
I'm assume that the direction and PC stored by the first '@' is "right" and (0,1).. meaning the position stored is the position after the PC has been advanced.

After the '$' returns, we end up at (0,2) however? Its as if the PC gets advanced an extra time upon returning?

Theres no more drop top of the stack instruction?? Seems kinda cumbersome to try and get something off the stack now.
User avatar
adum
Posts: 392
Joined: Thu Apr 19, 2007 12:49 pm
Contact:

Re: SuperHack

Post by adum »

MerickOWA wrote:Just trying to understand the instructions.

The '@' instruction i have a little trouble understanding. In the following example.

Code: Select all

@\!
 $
I'm assume that the direction and PC stored by the first '@' is "right" and (0,1).. meaning the position stored is the position after the PC has been advanced.

After the '$' returns, we end up at (0,2) however? Its as if the PC gets advanced an extra time upon returning?

Theres no more drop top of the stack instruction?? Seems kinda cumbersome to try and get something off the stack now.
you can use '[' to get something off the stack (because stack and memory are the same thing.)

your @ example is right. the reason you advance a step on the $ is to avoid infinite loops.
User avatar
m!nus
Posts: 202
Joined: Sat Jul 28, 2007 6:49 pm
Location: Germany

Post by m!nus »

HackVM was fun, this isn't. Seriously, no.

edit: i take that back :)
Last edited by m!nus on Tue Dec 30, 2008 1:12 am, edited 1 time in total.
therethinker
Posts: 144
Joined: Fri Mar 28, 2008 11:29 pm
Location: #hacker.org on Freenode

Post by therethinker »

I'm excited for this :P

I already raved in the "String Reversal" Solved thread, but I'm becoming confused...

Here's how I'm interpreting it. Please correct me.

HVM had 3, 1D stacks: "the stack", memory, and the call stack (for use w/ c/$).

Now, there is a single 2D stack that is used for both "the stack" and memory.
Memory acts like a 2D stack, whereas "the stack" is only seen one dimension at a time, the 2nd dimension, the X coord., corresponds to the thread.
The call stack remains about the same.

Where is the top of "the stack" in memory? Is it at (0,0), or is it at the high end?
And what does the memory pointer do? How does [ take something off the stack?

And is there a way to drop the top value on the stack in a single instruction? I can only do it in 2...
User avatar
lechat
Posts: 12
Joined: Wed Feb 27, 2008 10:16 am

Post by lechat »

adum,
can you please make the implementation of the SuperHack VM available? I'm not always connected to the internet...
thx :-)
therethinker
Posts: 144
Joined: Fri Mar 28, 2008 11:29 pm
Location: #hacker.org on Freenode

Post by therethinker »

Download http://hacker.org/sh/index.html to your hard drive, and then you can open it up with a web browser and it will still work.
User avatar
adum
Posts: 392
Joined: Thu Apr 19, 2007 12:49 pm
Contact:

Post by adum »

therethinker -- you're pretty much on target.

yeah, a drop takes two instructions, but it's more flexible this way.

instead of trying to explain everything here, it's probably easiest just to read the javascript source for the VM. it will explain better than i can. i know it's a bit confusing -- it still confuses me =)
MerickOWA
Posts: 182
Joined: Mon Apr 07, 2008 5:54 pm
Location: HkRkoz al KuwaiT 2019 HaCkEr 101

Post by MerickOWA »

I see, user input is separate from memory where as in HVM user input was always in the first X locations of memory.
snibril
Posts: 31
Joined: Sun Oct 26, 2008 11:18 pm

Post by snibril »

Two things: with the g/w instruktions, you can modify your program at runtime?
Second, thee is no "drop" instruktion like "d" in HVM?
User avatar
adum
Posts: 392
Joined: Thu Apr 19, 2007 12:49 pm
Contact:

Post by adum »

you can use '[' to drop.

yes, you can modify code at runtime.
User avatar
m!nus
Posts: 202
Joined: Sat Jul 28, 2007 6:49 pm
Location: Germany

Post by m!nus »

how about changing & so that it doesnt throw an exception when 32 threads are reached.
if it just would continue (advance current thread 1 step and jsut create no new one) this would be a nice way to create lots of worker threads :)
MerickOWA
Posts: 182
Joined: Mon Apr 07, 2008 5:54 pm
Location: HkRkoz al KuwaiT 2019 HaCkEr 101

Post by MerickOWA »

I think theres a bug in how threads/memory pointers work.

In both examples
UserInput:

Code: Select all

97,98
Code:

Code: Select all

&},P!
Javascript implementation prints 'ab'
Php implementation prints 'bb'???

Theoretically, if I understand how this works. I created a new thread who then immedately shifts its memory/stack pointer down (giving it its own stack).

The 2 threads run the same code in parallel then which is effectively ",,PP" which should print 'ab'.
However it appears as tho the '}' instruction is affect thread 0 & 1??

That's my best guess anyway.
Last edited by MerickOWA on Tue Dec 30, 2008 8:10 pm, edited 1 time in total.
therethinker
Posts: 144
Joined: Fri Mar 28, 2008 11:29 pm
Location: #hacker.org on Freenode

Post by therethinker »

I think it makes sense... possibly the javascript version has thread 2 run before thread 1, whereas PHP does it the other way around?
MerickOWA
Posts: 182
Joined: Mon Apr 07, 2008 5:54 pm
Location: HkRkoz al KuwaiT 2019 HaCkEr 101

Post by MerickOWA »

If it simply executed the threads in a different order, then it should print 'ba' not 'bb'.

My guess is that the '}' instruction affects both threads, or possibly thread 0 is executing this instruction too?

If the code is

Code: Select all

& ,P!
Then both implementations give 'bb'. The two threads are overwriting each other's stack in memory, so thread 1's read of userinput overwrites thread '0' result. Since poping off the stack just adjusts the memory pointer they both pop off the same/only value.
User avatar
adum
Posts: 392
Joined: Thu Apr 19, 2007 12:49 pm
Contact:

Post by adum »

sorry, there was a bug in the PHP. should be fixed now. thanks!
Post Reply