URL
https://opencores.org/ocsvn/tinycpu/tinycpu/trunk
Subversion Repositories tinycpu
[/] [tinycpu/] [trunk/] [docs/] [assembler.txt] - Rev 39
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, 0x0Fmov r1, 0x1Cand 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, 10mov r1, 20cmpgt r0, r1 #reads as TR=r0 > r1if_tr_set{mov r0, 40}Also, for here is a quick lookup table for the assembly words that aren't obvious:rsh -- right shiftlsh -- left shiftrro -- right rotatelro -- left rotatecmpgt -- compare greater thancmpgte -- compare greater than or equalcmplt -- compare less thancmplte -- compare less than or equalcmpeq -- compare equalcmpneq -- compare not equalTo avoid all sorts of hell with Ruby, some assembler words must be suffixed with a _These are listed below:or_and_xor_not_
