Hacker News new | past | comments | ask | show | jobs | submit login

I see this more as a) an example of how well humans can learn to ignore misdirection (the word 'move' hints at src, dest arguments) and b) the first small step towards C:

- read "mov X,Y" as "X = Y"

- adjust syntax so that it allows "X = Y" (what you see is what you think)

- similarly, replace obscure syntax for indexed memory acces by such things as "X = Y[3]"

- getting annoyed with the seemingly random limitations of the language, add an expression parser that translates "X = 2 * Y + 3" into "X = 2 * Y" and "X = X + 3", each of which gets assembled into one instruction. For now, only allow expressions that get away with only using the result register for temporaries.

- use existing macro capabilities to build a library of control flow statements such as IF and WHILE.

- introduce standard way to call subroutines.

- introduce shorthand method for doing such calls: one for the call site that takes a couple of expressions as argument, and one for function entry that uses macros such as 'int' and 'char' to pop arguments from the call stack.

By that time, one almost has K&R C.




I wrote my first compiler in M68000 assembler in a similar fashion to your steps. I started by allowing it to recognize M68000 assembler opcodes, and when found it'd just copy the line to output, otherwise it'd parse and compile the line. You could use register names and sizes directly in the statements.

So e.g.

    D0.W = 5
Would translate into:

    MOVE.W #5, D0
I didn't use macros though - handling basic argument passing is simple enough.

As soon as I had the basics of procedures/functions, simple expressions and argument passing in place I started rewriting the compiler using it.


Back in the 90's TI had a processor, maybe a DSP, I am not sure about it, which used a form of light C as their assembler.

There wasn't an Assembly language available as we tend to know.

I don't remember the name of the processor, though.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: