News for hackers. Stuff that matters.
Re:Ask HN: Tips for maintaining a C codebase? by tptacek on Wednesday May 29, 2013 @12:43PM (#5787373)
1) AVR

2) You'd compile simple C programs, of which there are zillions, rather than writing complex programs in assembly.

3) Make a struct that captures the state of the CPU: an array of integers for the register file, a flag word for the CPU flags, &c. Decode instructions (to a struct or something, which captures all the options of the instruction). Execute one instruction (pick it yourself): resolve its operands into temporary variables, execute the logic (almost invariably trivial), set the appropriate processor flags (overflow, zero, &c), and then store the result. Test lightly, and then repeat for all the other instructions. Most will be the same except for a single line of code. Make a big u_char array to represent memory. Write a HEX file loader, which will take a .hex file and populate memory with its contents; the GCC toolchain will compile C programs to HEX files. Now write the code to load an instruction, execute it, set the program counter appropriately, and repeat. Spend the next 2 weeks debugging.

4) I say, do it yourself. You can get yourself tied up in knots reading all the different ways to implement a VM. To start with, write a naive VM yourself with no help. Then go back and read that stuff if you want; it'll make much more sense.

Re:Ask HN: Tips for maintaining a C codebase? by mechanical_fish on Wednesday May 29, 2013 @01:05PM (#5787544)
Incidentally, "AVR" == "Arduino", so if you want a HEX file to execute you can have the Arduino toolkit drive the GCC cross-compiler for you, while you sit back sipping mojitos. Download the Arduino toolkit, open up the "Blink" demo, and press "Verify / Compile". Watch the little message window as your code compiles: Near the end of the process it will cough up a line like this:

/var/folders/4x/cwc9yvnx071_9whsft75cjvc0000gn/T/build8742301187783484704.tmp/Blink.cpp.hex

That file seems like it would be a fun thing to explore.

Re:Ask HN: Tips for maintaining a C codebase? by euroclydon on Wednesday May 29, 2013 @01:13PM (#5787599)
Scheew! I think I'll close the nongnu.org tab I have open and go get that mojito right now. Thanks!!!