6 ms·
I'm a self-taught programmer, and don't know much about CPUs. Would someone mind putting this into relatively plain english, I'm quite curious to know the prac
by wagabond 15y ago
I'm a self-taught programmer, and don't know much about CPUs. Would someone mind putting this into relatively plain english, I'm quite curious to know the practical implications of this. Can we expect to see Python running on it in the near future for example :) ?
- nknight 15y agoAlthough some of the implications require experience to understand, I'd say it already is in "relatively plain English", you simply haven't been exposed to the vocabulary and concepts necessary. Trying to explain in any detail would basically be reproducing Wikipedia, so here are some links: http://en.wikipedia.org/wiki/Program_counter http://en.wikipedia.org/wiki/Program_counter http://en.wikipedia.org/wiki/Word_(computer_architecture) http://en.wikipedia.org/wiki/Word_(computer_architecture) http://en.wikipedia.org/wiki/JMP_(x86_instruction) http://en.wikipedia.org/wiki/JMP_(x86_instruction) http://en.wikipedia.org/wiki/NOP http://en.wikipedia.org/wiki/NOP http://en.wikipedia.org/wiki/Orthogonal#Computer_science http://en.wikipedia.org/wiki/Orthogonal#Computer_science http://en.wikipedia.org/wiki/Address_space http://en.wikipedia.org/wiki/Address_space http://en.wikipedia.org/wiki/Memory-mapped_I/O http://en.wikipedia.org/wiki/Memory-mapped_I/O http://en.wikipedia.org/wiki/Interrupt http://en.wikipedia.org/wiki/Interrupt And no, don't expect Python anytime soon. Expect a C compiler, FORTH, possibly some sort of Pascal, but a highly dynamic language is unlikely. The system is too resource-constrained to make it practical. A static language that looks kind of like Python isn't out of the question, but it won't do a lot of the things you expect from Python, Ruby, PHP, or Perl.
- SoftwarePatent 15y agoReading all these wikipedia pages is going to kill at least an hour of productivity today :/
- akavel 15y ago> a highly dynamic language is unlikely Lua, perhaps? There was an article how to reduce its binary size, for an older version of the language (Lua 4.0): http://www.lua.org/notes/ltn002.html http://www.lua.org/notes/ltn002.html With no reductions, and for x86 assembly, it started at ~64KB, so not very useful here; but after dropping standard libraries and parser, they got to ~24KB. Now however, some further questions arise I'm not sure about: - whether such a virtual machine, when without parser, would be anyhow more useful than the underlying system alone? - how much the binary code would be bigger when compiled for the "DCPU-16" instruction set instead of x86?
- nknight 15y agoLua is a good place to start! And the VM minus parser is useful, though it may make debugging harder. You simply write out the bytecode and upload that. The VM is only part of the problem, though. I consider the bigger problem to be memory management. A garbage collected language operating reliably in 128KB? I'm deeply skeptical.
- quadhome 15y agoWhile I don't think Lua would be the choice, it's the quantity of garbage that matters: "Historically, languages intended for beginners, such as BASIC and Logo, have often used garbage collection for heap-allocated variable-length data types, such as strings and lists, so as not to burden programmers with manual memory management. On early microcomputers, with their limited memory and slow processors, BASIC garbage collection could often cause apparently random, inexplicable pauses in the midst of program operation. Some BASIC interpreters such as Applesoft BASIC on the Apple II family, had terribly inefficient garbage collectors for strings which repeatedly scanned the string descriptors for the string having the highest address in order to compact it toward high memory. This one-string-at-a-time processing loop resulted in O(N * N) time performance in the number of strings, which would introduce a pause more than one minute long into the execution of string-intensive programs. A replacement garbage collector for Applesoft BASIC published in Call-A.P.P.L.E. (January 1981, pages 40–45, Randy Wiggington) identified a group of strings in every pass over the heap, reducing a pause of two minutes into less than a second depending on the size of the group. Other approaches were published, but none ever made it into a new revision of the BASIC interpreter." http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)#Availability http://en.wikipedia.org/wiki/Garbage_collection_(computer_sc...
- ac 15y agoA smarter way might be just implementing a new LLVM backend (gives us C via Clang, some other languages). However, even with C, the standard library probably won't leave much space for the user code itself -- so you might need something slimmer. Also, some kind of simple RTOS (www.freertos.org, maybe?) to run all these programs (I assume people would really want to run several programs at a time). I wonder if the 128k limitation was intentional, to make programming the computers more interesting. Anyway, I'm actually looking forward to seeing what kind of clever solutions the players come up with.
- nknight 15y agoThe ANSI C library is quite small. It originates in an era when 128KB of RAM was reasonably roomy. To this day, there are C libraries designed to fit comfortably within that size. Most of the library code will never even be present anyway. Your (statically-linked) binary will simply contain those functions actually used, which is likely to be a small subset of what is available.
- jmaygarden 15y agoAn RTOS won't be of much use without interrupts. You could implement coroutines, but preemptive scheduling is not possible.
- javert 15y agoMoreover, it would be very surprising if low-latency or deterministic timing properties would actally be useful in the game.
- SoftwarePatent 15y agoGood question. To run python on this CPU, someone (you?) needs to port Cpython to it. A CPU runs assembly language, and it's not hard for a hacker to port C to a new CPU, because C is small. In addition, implementing C is the sort of thing that hackers like to do. So you can count on C running on any given CPU, virtual or real. http://en.wikipedia.org/wiki/CPython http://en.wikipedia.org/wiki/CPython
- Tuna-Fish 15y agoThis thing will have a total of 128kB directly addressable ram (as 64k 16b words). There's no way, no how that CPython would ever do anything remotely useful here.
- hythloday 15y agoIt depends what the purpose of the DCPU is. If it's the scripting engine, well, you can easily write an aimbot in 128KiB of .pyc files and the python VM. If your only access to the world is through the DCPU, yeah, you're probably out of luck, but the second scenario makes for a much smaller and less interesting game. It's also an obvious in-game/micropayment reward to expand the address space, somewhat analogously to the N64's memory expansion pack.
- phreeza 15y ago"real" python seems unlikely, given that the standard executable is well over 64KB in size. A variant like cython that compiles to this assembly? maybe...
- hythloday 15y agoYou don't need the full python repl/compiler/interpreter/libraries, you "just" need the python virtual machine. Once there's a C compiler for the platform that should be relatively straightforward, because I sincerely doubt that takes all 128KiB.
- enygmata 15y agoI wonder how hard would it be to get a working DCPU-16 backend for GCC or Clang.
- abrahamsen 15y agoGCC already has 4 other 16-bit backends (e.g. pdp11), so it should be achievable.
- Ralith 15y agoA Clang backend means a LLVM backend, which I believe is a lot easier than extending GCC, and gets you support for all sorts of languages.
- chrismsnz 15y agoRPython, perhaps?
- exch 15y agoI strongly recommend you to read the course book "The Elements of Computing Systems" [1]. This explains the whole principle in very plain English. It has an extremely intuitive and easy to follow logic and set of exercises you can do. It has completely demystified the whole low level world of computers for me. If you can't get the book, a number of exercises and chapters are available for free at this website[2]. [1]: http://www1.idc.ac.il/tecs/ http://www1.idc.ac.il/tecs/ [2]: http://diycomputerscience.com/courses/course/the-elements-of-computing-systems http://diycomputerscience.com/courses/course/the-elements-of...
- wglb 15y agoI would be astonished if there wasn't soon a FORTH running on it. And something like http://code.google.com/p/femtolisp/ http://code.google.com/p/femtolisp/ might not be totally out of the question. But who can say. The second Fortran compiler I used ran on an IBM 1800 (equivalent to the IBM 1130, but for process control) had something like 29 phases, and ran on a machine with a total of 4k 16-bit words.
- calebmpeterson 15y agoI wondered if I'd be the first to suggest a LISP implementation... glad to see I wasn't.
- ericbb 14y agoPico Lisp might be a good starting point. Its interpreter for x86-64 machines is written using a simplified custom assembler and already uses a reduced number of registers.