Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

/PROG/ Challenge Number 8 - Virtual Machine

Name: Anonymous 2007-10-09 18:31

Make virtual machine and compiler for the following instruction set.

LOD - Load into accumulator
STR - Store into memory
ADD - Add acc+mem
NEG - accumulator=accumulator*-1
INP - Input number to accumulator
OUT - Output
JMP - Jump to memory location
JNZ - Jump if accumulator non zero

If you do this, I WILL be impressed.

Name: Anonymous 2007-10-09 18:35

If you do this, I WILL be impressed.
And you'll probably pass whatever this is homework for. Which really shouldn't happen.

Name: Anonymous 2007-10-09 18:48

>>2

Name: Anonymous 2007-10-09 19:11

*sigh*

Name: Anonymous 2007-10-09 19:17

Sage for invalid challenge.

Name: Anonymous 2007-10-09 19:18

>>1
And the rest of the specifications, faggot?

Name: Anonymous 2007-10-09 19:19

>>1

That's debatable...

Name: Anonymous 2007-10-09 19:25

>>1
:facepalm:

Name: Anonymous 2007-10-09 19:53

>>1 see >>6
There are so many missing implementation details that, with the right assumptions, the assignment is trivial. In which case you're just an idiot.

Name: Anonymous 2007-10-09 20:04

>>9

Make up the rest of it.

Name: Anonymous 2007-10-09 20:17

>>1
Virtual machines are not hard. I have implemented a few now (register based, stack based, fixed length instructions, variable length instructions, etc). Then again, I'm quite interested in this topic, so I guess I would look into such things. I also do compiler construction in uni.

Name: Anonymous 2007-10-09 20:46

>>11
Stack based? Sounds interesting. Mind sharing a bit of your code?

Name: Anonymous 2007-10-09 20:53

>>12
How the hell is that interesting? Naive stack based virtual machines are just about the easiest programmable thing you can code.

Name: Anonymous 2007-10-09 23:32

>>13
Naive
Is that a typo of ``Native''? If not, what are ``Naive'' virtual machines? Google doesn't seem to turn up anything.

Name: Anonymous 2007-10-10 1:12

>>14
Forth?

Name: Anonymous 2007-10-10 1:51

>>14
gb2learning your mother tongue

Name: Anonymous 2007-10-10 2:07

I already did, when I bored.

It's the little man machine.

I still got it somewhere, even a compiler for it.

Name: Anonymous 2007-10-10 2:50

This reminds me of the time when I assigned almost the exact same assignment to my languages class. More than half of the class didn't finish, some barely finished, and one guy wrote a full assembler, disassembler, compiler, and decompiler for the virtual machine in the same amount of time.

Name: Anonymous 2007-10-10 5:14

why would you be impressed this is trivial.

Name: Anonymous 2007-10-10 5:19

>>19
because this is /prog/

Name: Anonymous 2007-10-10 7:42

>>20
my point exactly, /prog/ is saturated with EXPERT PROGRAMMERS discussing ''ABSTRACT BULLSHITE``, not writing silly little compilers (I wrote an ANSI C compiler when I was 12).

Name: Anonymous 2007-10-10 11:06

>>1
Great, you missed 90% of the specifications you faggot!

>>12
Stackfag

Name: Anonymous 2007-10-10 11:09

>>21
when you were 12 the standards for ANSI C were probably just the specifications for ``printf''

Name: Anonymous 2007-10-10 12:49

>>12 (Im >>11)
Its fairly simple actually. I did two, a forth-like interpreter and a stack based virtual machine.

The firth-like one simply read in a word at a time and performed some stack operation (though i had multiple stacks, I cant remember exactly, maybe 8). So, it reads a word from standard input and does something. For example, if it reads "+" it pops the top two values off the stack, adds them and pushes the result to the stack. Very simple. It only worked with integers too, because I was lazy.

The virtual machine one executed bytecode. Instead of operating on virtual registers however, it operates on a stack. So, the instruction set consisted of stack operations and other operations, the others operating on the top values of the stack.

Personally, I think stack based interpreters and VM's are easier to write than VM ones. Not that register based ones are hard. The hard part is ensuring that it's all efficient and performance is reasonable.. If performance doesn't matter, it's all extremely easy.

Name: Anonymous 2007-10-10 14:04

I have a much more challenging project for you, but only enterprise programmers can solve it. /prog/ doesn't seem to have many.

Name: Anonymous 2007-10-10 14:10

Now ITT we're discussing implementation of LISP-machines.

Name: Anonymous 2007-10-10 14:28

Here is your project:

1. Design a language M that is capable of describing any virtual machine.

2. Put the description of a virtual machine written in M at the beginning of the file, followed by the virtual machine program, and XOR the entire file with a key, the length of which is divisible by the length of the entire file. This will be the key to decrypt the file so the program can run.

Get coding, 'experts'.

Name: Anonymous 2007-10-10 21:24

Ok, I have designed such a language

X,Y,Z can be any of these addressing modes : absolute, indirect, register (including instruction pointer), or immediate

NOP - Do nothing

MOVE X,Y - Copy data from X to Y

AND X,Y,Z
OR X,Y,Z
NOT X,Z
Logical operation, result stored in Z

IFZ X
Execute next instruction only if X is zero

The End.  Touring-Complete.

Name: Anonymous 2007-10-10 21:25

Oh, and throw in an XOR

Name: Anonymous 2007-10-10 21:40

this is trivial if you've read sicp.

No, it's not just another pointless reference. I'm telling the truth!

Name: Anonymous 2007-10-10 21:55

don't forget the <=> operator.

Name: Anonymous 2007-10-10 21:57

>>1

That's debatable.

Name: Anonymous 2007-10-10 22:02

>>28

Execute next instruction only if X is zero

what if x<>0? Does it just stop?

Name: Anonymous 2007-10-10 22:13

>>31
Oh lol, I'd forgotten about my old friend, the spaceship operator.

Name: Anonymous 2007-10-10 23:40

>>33
I presume it'd skip the next instruction and continue with the one after.

Name: Anonymous 2007-10-11 0:32

>>28
You have not thought carefully enough about the question.

Name: Anonymous 2007-10-11 1:19

>>28
Your operand order is reversed.

Name: Anonymous 2007-10-11 1:24

>>33
>>35 is right.  I envision the syntax would allow IFZ X to be specified on the same line as the instruction it "modifies"
i.e. IFZ A MOVE A,B


Name: Anonymous 2007-10-11 1:43

wow copypasta more fag.  jesus /prog/ has turned into such a fulking broken record.

Name: Anonymous 2007-10-11 11:42

>>39
Die.

Preferably, slowly and painful. Barbed wire is a good option to start unstoppable bleeding. Make sure to go slow so you will suffer the must amount of pain for the longest period of time.

Name: Anonymous 2007-10-11 13:24

>>39
HAHAHAHAHAHAHAHHAHAHAHAAHAHAAAA!!!
you think your funny huh?

Name: Anonymous 2007-10-11 16:07

>>40
Make sure to go slow so you will suffer the must amount of pain for the longest period of time.
suffer the must amount of pain
must

Name: Anonymous 2007-10-11 16:28

>>40

That's debatable.

Name: Anonymous 2007-10-11 16:32

>>42
Make sure to go slow so you will suffer the must amount of pain for the longest period of time.
suffer the must amount of pain
must

Name: Anonymous 2007-10-11 16:35

>>40
>>41
Internet Tough Programmer.

Name: Anonymous 2007-10-11 16:38

Don't forget the ‫‬‭‮‪‫‬‭‮҉‬‬‬‬ operator.

Name: Anonymous 2007-10-12 20:10

>>46
Thats a pretty usefull opertater...

Name: Anonymous 2007-10-12 20:25

>>44
Must, as in force. Force is not always a bad thing.

Name: Anonymous 2007-10-13 0:35

Name: Anonymous 2007-10-13 0:36

50 GET

Name: Anonymous 2011-02-10 5:21

>>39
omg ur so right!! /prog/s full of faggots

Name: Anonymous 2011-02-10 8:47

i like this challenge, and will create a new challenge based on this one.

Name: Anonymous 2011-02-10 9:11

>>54
the challenge won't be to write a VM, the challenge will be to write a program in it. the program will control a robot in a battle to the death.

Name: Anonymous 2011-02-10 9:36

>>56
im not sure about making the VM too esoteric, ideally it would be reasonably easy to program in it.

im thinking of instructions to operate the engines (move and turn), sensors (copy input into memory somewhere) and actuator (interact with environment)..

Name: Anonymous 2011-02-10 9:41

What are the specifications of OUT, does it print the value of the accumulator?

Name: Anonymous 2011-02-10 9:46

>>58
outputs number->ascii-char(accumulator)

Name: Anonymous 2011-02-10 9:48

>>59

What an insanely ridiculous instruction, so you only get information from 8 bits?

Don't change these.
Name: Email:
Entire Thread Thread List