URL
https://opencores.org/ocsvn/tinycpu/tinycpu/trunk
Subversion Repositories tinycpu
Compare Revisions
- This comparison shows the changes necessary to convert path
/tinycpu
- from Rev 35 to Rev 36
- ↔ Reverse comparison
Rev 35 → Rev 36
/trunk/assembler/asm.rb
1,23 → 1,63
PREFIX = "MemIn <= x\""; |
SUFFIX = "\";"; |
SEPERATOR = "\n"; |
|
|
|
class OpcodeByte1 |
attr_accessor :op, :register, :cond; |
def to_hex |
s = (op << 4 | register.number << 1 | cond).to_s(16); |
if s.length == 1 |
"0"+s; |
elsif s.length == 0 |
"00"; |
else |
s |
end |
end |
end |
|
|
class Register8 |
attr_accessor :number |
def initialize(num) |
@number=num |
end |
|
end |
|
$iftr = 0; #0 for no condition, 1 for if TR, 2 for if not TR |
|
def mov_r8_imm8(reg,imm) |
p (0xB0+reg.number).to_s(16)+' '+(imm.to_s) |
o = OpcodeByte1.new(); |
o.op = 0; |
o.register=reg; |
if $iftr<2 then |
o.cond=$iftr; |
else |
raise "if_tr_notset is not allowed with this opcode"; |
end |
puts PREFIX + o.to_hex + imm.to_s(16) + SUFFIX; |
puts SEPERATOR; |
end |
|
def mov(arg1,arg2) |
if arg1.kind_of? Register8 and arg2.kind_of? Integer and arg2<0x100 then mov_r8_imm8 arg1,arg2 end |
|
end |
def if_tr_set |
$iftr = 1 |
yield |
$iftr = 0 |
end |
|
ax=Register8.new(0) |
bx=Register8.new(3) |
cx=Register8.new(1) |
dx=Register8.new(2) |
|
mov ax,0x10 |
r0=Register8.new(0) |
r1=Register8.new(1) |
r2=Register8.new(2) |
r3=Register8.new(3) |
|
#test code follows. Only do it here for convenience.. real usage should prefix assembly files with `require "asm.rb"` |
if_tr_set{ |
mov r1,0x10 |
} |
mov r1,0x20 |