Hello World, using only C syscalls

I’m currently working on implementing system calls in BlarbVM (see my previous post on it), so I am trying to get comfortable using only syscalls.

In Linux, you can change the heap size through brk (syscall #12). To write a string to standard output, you must provide a pointer to a location on the heap.

The following code:

  1. Get’s the end of the heap address
  2. Increments the end of the heap address by 6 bytes
  3. Set’s the value of those 6 bytes to a null terminated “hello\n” string
  4. Runs a syscall on the desired heap position to print “hello\n”

WearHacks Toronto 2016 Project: InfraViewer

At WearHacks Toronto 2016, we were trying to think of project ideas, but nothing came to mind that we all agreed on. So Adrian, Austin and I went out for coffee to take a mental break. While at the coffee shop, we were talking about all the types of light humans are blind to. Wouldn’t it be amazing if we could the whole spectrum of light, including infra red and ultra violet? … maybe we can!

When we got back to the Bitmaker offices (where the hackathon was held), we checked out the available hardware to see if there were any IR cameras. Unfortunately, the only IR camera we could find was on the Kinect, and it’s IR camera only has intensity (not spectrum data). So we made due with what we had and decided to use both the IR and RGB cameras of the Kinect to render both layers on top of each other.

Josh, Austin and I worked on the translation algorithm while Kulraj and Nick created an SFML GUI. The colorspace transformation algorithm we ended up designing and implemented was to shift the visible light by 10 degrees (hue), then shift the IR spectrum into the first 10 degrees of red hue. Essentially, we squeezed the visible light from the non-IR camera so there was no red left, then put a red layer on top of that image to display the infra red data.

The hardware turned out to be pretty difficult to overlay. The IR camera and visible light cameras had significantly different resolutions and aspect ratios. So we had to program some magic to translate the IR data to fit on top of the RGB data. Because of this, the IR layer was slightly offset from where it should have been. For instance, a slight red glow would appear around our bodies (from our body heat), but it would be shifted one side, since the camera perspectives were not identical.

IMG_20160326_230643

You can check out the project here: InfraViewer. But be warned, the code base is pretty messy!

BlarbVM/BlarbLang

Esoteric programming languages are awesome. So I decided to create one, which I call BlarbLang.

The goal of this language is to be the simplest possible systems programming language. It uses a stack for parameters, and every function must destruct its own stack frame, and push a return value, manually. The language “doesn’t care” about performance, only simplicity. It currently supports only 5 operations:

  • a b ~ Store the value of a in register b
  • a $ Push register a onto the stack
  • b a ! NANDS index a with index b and stores the result in index b
  • a ^ pop ‘a’ elements
  • a ? if index a is true (non-zero), execute the rest of the line

In one of my CS lectures (CSC258) I remembered learning that every gate can be created using NAND gates, so that is the only type of logical operation in the language! Using the above 5 operations, tons of different operations can be created, including adders, shifters, comparison operators, and more. https://github.com/elimirks/BlarbVM/blob/master/lib.blarb

There are 8 registers available for users. The 0th register is the line pointer, registers 1-3 are temporary registers (for swapping and stuff), and the 4-7 registers are “long term” registers, meant to be used outside of the standard library (by the user).

Labels allow creation of functions. For instance, the following code creates a function called “nandi” which NANDs two immediate stack values:

In the future, I want to add one more operation: the system call operation. Currently, the language can only modify data within the VM. That is, on the stack and in registers. However, using system calls, users will be able to allocate heap memory and perform useful tasks such as reading from STDIN and writing to STDOUT.