Browse files

readme for github

  • Loading branch information...
bartman committed Apr 7, 2012
1 parent fdc93ef commit 89745c5bc02ac8ddc3098ba03633235e91a6f8d1
Showing with 19 additions and 0 deletions.
  1. +19 −0
@@ -0,0 +1,19 @@
+# About
+So far, this project has a working assembler for Notch's new DCPU-16 processor.
+I intend to work on a VM next.
+# Assembler
+Because lua lacks a builtin facility for generating binaries, I am currently

bartman Apr 7, 2012


I don't think what I wrote is what I meant :)

Unless you use lpack (or equivalent), there is no good way to go from "0x2000" to the binary representation { 0x00, 0x20 } and write that to a file.

Because out of tree lua dependencies tend to be a pain for users, I didn't go there.



bartman via email Apr 7, 2012


bartman Apr 9, 2012


I should do what you suggest for bit conversions. The problem I was complaining about is how do I write raw bytes into a file?

In C, I would do

uint16_t op_code[2] = { 0x7c11, 0xf100 };
int fd = open("output.dcpu16", O_RDWR, 0644);
write(fd, op_code, sizeof(op_code);

In lua, with lpack, I think I would do something like:

require "pack"
local f ="output.dcpu16", "w+")

Is there a way to write this in pure lua?


agladysh Apr 9, 2012

Hmm... As long as you write uint16_t only, just split each into two bytes with luabit, and then do string.char() on each.


bartman Apr 9, 2012


For some reason I didn't think that would have worked... but clearly I was wrong :-) Thanks.

lua <<<'io.write(string.char(0)..string.char(1)..string.char(2)..string.char(3))' | hexdump
0000000 0100 0302                              
+generating text output.
+./0x10c.lua -a sample.asm -o -
+0000: 7c01 0030 7de1 1000 0020 7803 1000 c00d
+0008: 7dc1 001a a861 7c01 2000 2161 2000 8463
+0010: 806d 7dc1 000d 9031 7c10 0018 7dc1 001a
+0018: 9037 61c1 7dc1 001a
+sample.asm is a file obtained from the DCPU-16 documentation. It is used to
+verify that the code generated by this tool is correct.

0 comments on commit 89745c5

Please sign in to comment.