OpenCores
URL https://opencores.org/ocsvn/tinycpu/tinycpu/trunk

Subversion Repositories tinycpu

[/] [tinycpu/] [trunk/] [docs/] [assembler.txt] - Rev 40

Go to most recent revision | Compare with Previous | Blame | View Log

The assembler is really a big hack job. Basically, I didn't want to write a complex assembler in C or C++, so I decided to use Ruby's power as a DSL to create an assembler.
So ruby does all the heavy syntax stuff, and I just do a bit more meta-programming than anyone probably should. 

Anyway, Because of how it's made, you can of course use Ruby for any kind of assembler generation such as loops or whatever. Keep in mind, that after the program file runs, it outputs machine code though..

A simple example file:

----
require "asm.rb"

mov r0, 0x0F
mov r1, 0x1C
and r0, r1 

-----

And you run it by doing something like `ruby MyAssemblyFile.rb`. 

If you're just wanting to write some assembly code and not worry about how my assembler works, then it's quite simple. 
Just use the command above, make sure to use `require "asm.rb"` and make sure that asm.rb is in your working directory.

The asembler is definitely an `intel` style assembler. By that, I mean target registers are on the left, and source registers are on the right. 
However, because of our unique CPU architecture, there are some interesting looking constructs. 

For instance, to use a block as `Only execute if TR is set` you'd use:

mov r0, 10
mov r1, 20
cmpgt r0, r1 #reads as TR=r0 > r1
if_tr_set{
  mov r0, 40
}




Also, for here is a quick lookup table for the assembly words that aren't obvious:

rsh -- right shift
lsh -- left shift
rro -- right rotate
lro -- left rotate
cmpgt -- compare greater than
cmpgte -- compare greater than or equal
cmplt -- compare less than
cmplte -- compare less than or equal
cmpeq -- compare equal
cmpneq -- compare not equal

To avoid all sorts of hell with Ruby, some assembler words must be suffixed with a _
These are listed below:
or_
and_
xor_
not_

Go to most recent revision | Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.