Hacker Virtual Machine IDE

Col. Dump
Posts: 10
Joined: Fri Oct 31, 2008 1:09 am

Hacker Virtual Machine IDE

Post by Col. Dump »

Hi all,

I wrote a prototypical IDE for the hacker virtual machine. It's a small java application available at http://sites.google.com/site/hvmide/.

Happy hacking,
Col. Dump
Allosentient
Posts: 273
Joined: Thu Apr 10, 2008 9:47 pm

Post by Allosentient »

Very nice of you to post this, thank you. I was just going to post JUST NOW that I am working on one not a full IDE, but a command line assembler. I dont know if this will ruin the challenges for everyone else though since the purpose of these is to be a challenge

Sample program:

start:
50>0; Initialize counter = 5 [a]
next:
6 [a, 6]
+; [a += 6]
0<; [a, counter]
1-; [a, --counter]
0^0>; [a, counter] (counter stored in mem)
jz end;
call next;
end:
!
User avatar
adum
Posts: 392
Joined: Thu Apr 19, 2007 12:49 pm
Contact:

Post by adum »

we actually have a policy of not allowing sharing of HVM assemblers. the IDE is just about the max we allow. it's so people get the joy of developing their own techniques =)
Allosentient
Posts: 273
Joined: Thu Apr 10, 2008 9:47 pm

Post by Allosentient »

I dont have any assemblers to share (only going to give a hint as to what a program should look like!), but that IDE he posted actually has a pretty nice debugger in it, so I dont know if that is allowed
Allosentient
Posts: 273
Joined: Thu Apr 10, 2008 9:47 pm

Post by Allosentient »

I have been using this, it got rid of my headaches.

Now I do have one question, the IDE throws an error if you try to read memory that isn't assigned, but I don't believe this is really illegal, as all memory has 0 by default. Is there a way to turn that off?

Few more things:
'do nothing' doesn't count toward program length

Able to put values into negative memory locations

would be nice to have a "run to X program cycles"

Great program!!
Col. Dump
Posts: 10
Joined: Fri Oct 31, 2008 1:09 am

Post by Col. Dump »

I'm happy to hear that my tool is actually of use for you. :)

You are right with respect to the machine behaviour: both negative memory addresses as well as memory initialization should work as you described. I will fix that briefly...

[Edit] I have to correct myself - write access to negative memory addresses results in an error of the reference implementation, too:

@0 1 [1]
@1 0 [1, 0]
@2 1 [1, 0, 1]
@3 - [1, -1]
@4 > !ERROR: exception while executing I=> PC=4 STACK_SIZE=1
memory write access violation @-1
Col. Dump
Posts: 10
Joined: Fri Oct 31, 2008 1:09 am

new version 0.9.2

Post by Col. Dump »

You can find a new release at the old location, which now
- has a new run command "run to cycle X"
- returns 0 for read operations on uninitialized memory instead of throwing an exception
- doesn't ignore whitespace outside of comments anymore, i.e. both spaces and newlines count to program length now
- initializes new VMs with the standard reference memory size (16384)
- has several GUI bugs fixed (confirm dialog now only pops up if really necessary, F8 doesn't jump to split pane any more, ...)

How would you implement access to negative memory addresses? Python-like, starting from the end of the memory? Or simply have one half of the memory in negative address space?
Allosentient
Posts: 273
Joined: Thu Apr 10, 2008 9:47 pm

Post by Allosentient »

Thanks for the update! I am not sure what you mean by your question, since negative memory addresses aren't supposed to work in HVM at all, but if I were to do it anyway, I would have half the memory in negative address space. It is hard to use HVM memory as storage when the challenge says that the first X number of memory spots is filled.

I stayed up nearly all night trying to finish King Mouse, but I am having a hard time. This is harder to me than the really small hello world problem.
User avatar
m!nus
Posts: 202
Joined: Sat Jul 28, 2007 6:49 pm
Location: Germany

Post by m!nus »

wow, this is really nice, the GUI makes it even better than mine (commandline and simple web interface)
http://minus.denn1s.cn/hacker.org/hvm.html that's what it looks like (goto parsing not yet really implemented)
line breaks are ignored, spaces aren't, comments work with ; at line ends, memory supports strings
~620 lines of code, ~15KB of PHP; not much yet.

as I can see from this VM a GUI really really helpful (especially the step-in/over) so i might also create one using PHP-Gtk2


btw, something seems to be wrong about your IDE Col. Dump: 005c!1^... -- program terminated by command "!" at instruction 4 which is obviously wrong since i call to position 5 before
EDIT: some very strange behavior: now: 005c!1^1^82**+0^ at the last ^ it says end of program reached at instruction 15. i am confused. really.
Allosentient
Posts: 273
Joined: Thu Apr 10, 2008 9:47 pm

Post by Allosentient »

The 005c!1^ code works correctly for me, maybe you have a leading space?
Mütze
Posts: 23
Joined: Sun Oct 26, 2008 2:39 pm

Post by Mütze »

I found out, that the hackvm.py script outputs -1 when executing "01-2/p".
Your ide outputs 0.
Last edited by Mütze on Mon Nov 24, 2008 9:43 am, edited 1 time in total.
Col. Dump
Posts: 10
Joined: Fri Oct 31, 2008 1:09 am

Post by Col. Dump »

Thank you for the tip! Looks like the result of -1/2 depends on how the languages treat rounding in integer division.

Python: result is the next smaller integer, positive and negative
>>> -1/2
-1

Java: result is the next smaller absolute integer with the corresponding sign
System.out.println(-1/2);
0

I changed the code so that the IDE behaves exactly like the reference implementation (i.e. "push((int)Math.floor((double)s1/s0));").

You can download the fixed version at the usual URL.

BTW: line breaks are now also ignored, spaces not.

EDIT: 005c!1^1^82**+0^ works in my 0.9.3 as expected, i.e. termination at 16...
Mütze
Posts: 23
Joined: Sun Oct 26, 2008 2:39 pm

Post by Mütze »

Thank you! That was fast.
sigi
Posts: 37
Joined: Sun Oct 26, 2008 4:58 pm

Post by sigi »

Whoa, that IDE looks like some serious amount of work already. You've even picked nice icons. Are you sharing the source code for it? We might want to plug in our own assemblers into the IDE.
Col. Dump
Posts: 10
Joined: Fri Oct 31, 2008 1:09 am

Post by Col. Dump »

If I find the time, I will make a code fork and clean it up so it can be released.
Post Reply