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

Subversion Repositories tinycpu

[/] [tinycpu/] [trunk/] [docs/] [assembler.txt] - Blame information for rev 39

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 earlz
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.
2
So ruby does all the heavy syntax stuff, and I just do a bit more meta-programming than anyone probably should.
3
 
4
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..
5
 
6
A simple example file:
7
 
8
----
9
require "asm.rb"
10
 
11
mov r0, 0x0F
12
mov r1, 0x1C
13
and r0, r1
14
 
15
-----
16
 
17
And you run it by doing something like `ruby MyAssemblyFile.rb`.
18
 
19
If you're just wanting to write some assembly code and not worry about how my assembler works, then it's quite simple.
20
Just use the command above, make sure to use `require "asm.rb"` and make sure that asm.rb is in your working directory.
21
 
22
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.
23
However, because of our unique CPU architecture, there are some interesting looking constructs.
24
 
25
For instance, to use a block as `Only execute if TR is set` you'd use:
26
 
27
mov r0, 10
28
mov r1, 20
29
cmpgt r0, r1 #reads as TR=r0 > r1
30
if_tr_set{
31
  mov r0, 40
32
}
33
 
34
 
35
 
36
 
37
Also, for here is a quick lookup table for the assembly words that aren't obvious:
38
 
39
rsh -- right shift
40
lsh -- left shift
41
rro -- right rotate
42
lro -- left rotate
43
cmpgt -- compare greater than
44
cmpgte -- compare greater than or equal
45
cmplt -- compare less than
46
cmplte -- compare less than or equal
47
cmpeq -- compare equal
48
cmpneq -- compare not equal
49
 
50
To avoid all sorts of hell with Ruby, some assembler words must be suffixed with a _
51
These are listed below:
52
or_
53
and_
54
xor_
55
not_

powered by: WebSVN 2.1.0

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