/
op_jc.go
172 lines (140 loc) · 4.58 KB
/
op_jc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package procbuilder
// TODO This is the ROM, change it to halndle also the RAM case
import (
"errors"
"math/rand"
"strconv"
"github.com/BondMachineHQ/BondMachine/pkg/bmline"
"github.com/BondMachineHQ/BondMachine/pkg/bmmeta"
"github.com/BondMachineHQ/BondMachine/pkg/bmreqs"
)
type Jc struct{}
func (op Jc) Op_get_name() string {
return "jc"
}
func (op Jc) Op_get_desc() string {
return "Jump to a program location if carry-bit is 0"
}
func (op Jc) Op_show_assembler(arch *Arch) string {
opbits := arch.Opcodes_bits()
result := "jc [" + strconv.Itoa(int(arch.O)) + "(Location)] // Jcump to a program location [" + strconv.Itoa(opbits+int(arch.O)) + "]\n"
return result
}
func (op Jc) Op_get_instruction_len(arch *Arch) int {
opbits := arch.Opcodes_bits()
return opbits + int(arch.O) // The bits for the opcode + bits for a location
}
func (op Jc) OpInstructionVerilogHeader(conf *Config, arch *Arch, flavor string, pname string) string {
result := ""
setflag := conf.Runinfo.Check("carryflag")
if setflag {
result += "\treg carryflag;\n"
}
return result
}
func (Op Jc) Op_instruction_verilog_reset(arch *Arch, flavor string) string {
return ""
}
func (Op Jc) Op_instruction_verilog_internal_state(arch *Arch, flavor string) string {
return ""
}
func (Op Jc) Op_instruction_verilog_default_state(arch *Arch, flavor string) string {
return ""
}
func (op Jc) Op_instruction_verilog_state_machine(conf *Config, arch *Arch, rg *bmreqs.ReqRoot, flavor string) string {
rom_word := arch.Max_word()
opbits := arch.Opcodes_bits()
result := ""
result += " JC: begin\n"
if arch.O == 1 {
result += " if(carryflag == 'b0) begin\n"
result += NextInstruction(conf, arch, 6, "current_instruction["+strconv.Itoa(rom_word-opbits-1)+"]")
result += " $display(\"JC \", current_instruction[" + strconv.Itoa(rom_word-opbits-1) + "]);\n"
result += " end \n"
} else {
result += " if(carryflag == 'b0) begin\n"
result += NextInstruction(conf, arch, 6, "current_instruction["+strconv.Itoa(rom_word-opbits-1)+":"+strconv.Itoa(rom_word-opbits-int(arch.O))+"]")
result += " $display(\"JC \", current_instruction[" + strconv.Itoa(rom_word-opbits-1) + ":" + strconv.Itoa(rom_word-opbits-int(arch.O)) + "]);\n"
result += " end \n"
}
result += " end\n"
return result
}
func (op Jc) Op_instruction_verilog_footer(arch *Arch, flavor string) string {
return ""
}
func (op Jc) Assembler(arch *Arch, words []string) (string, error) {
opbits := arch.Opcodes_bits()
rom_word := arch.Max_word()
if len(words) != 1 {
return "", Prerror{"Wrong arguments number"}
}
result := ""
if partial, err := Process_number(words[0]); err == nil {
result += zeros_prefix(int(arch.O), partial)
} else {
return "", Prerror{err.Error()}
}
for i := opbits + int(arch.O); i < rom_word; i++ {
result += "0"
}
return result, nil
}
func (op Jc) Disassembler(arch *Arch, instr string) (string, error) {
value := get_id(instr[:arch.O])
result := strconv.Itoa(value)
return result, nil
}
func (op Jc) Simulate(vm *VM, instr string) error {
value := get_id(instr[:vm.Mach.O])
if value < len(vm.Mach.Slocs) {
vm.Pc = uint64(value)
} else {
vm.Pc = vm.Pc + 1
}
return nil
}
func (op Jc) Generate(arch *Arch) string {
max_value := 1 << arch.O
value := rand.Intn(max_value)
return zeros_prefix(int(arch.O), get_binary(value))
}
func (op Jc) Required_shared() (bool, []string) {
return false, []string{}
}
func (op Jc) Required_modes() (bool, []string) {
return false, []string{}
}
func (op Jc) Forbidden_modes() (bool, []string) {
return false, []string{}
}
func (Op Jc) Op_instruction_verilog_extra_modules(arch *Arch, flavor string) ([]string, []string) {
return []string{}, []string{}
}
func (Op Jc) AbstractAssembler(arch *Arch, words []string) ([]UsageNotify, error) {
result := make([]UsageNotify, 1)
newnot := UsageNotify{C_OPCODE, "jc", I_NIL}
result[0] = newnot
return result, nil
}
func (Op Jc) Op_instruction_verilog_extra_block(arch *Arch, flavor string, level uint8, blockname string, objects []string) string {
result := ""
switch blockname {
default:
result = ""
}
return result
}
func (Op Jc) HLAssemblerMatch(arch *Arch) []string {
result := make([]string, 0)
return result
}
func (Op Jc) HLAssemblerNormalize(arch *Arch, rg *bmreqs.ReqRoot, node string, line *bmline.BasmLine) (*bmline.BasmLine, error) {
return nil, errors.New("HL Assembly normalize failed")
}
func (Op Jc) ExtraFiles(arch *Arch) ([]string, []string) {
return []string{}, []string{}
}
func (Op Jc) HLAssemblerInstructionMetadata(arch *Arch, line *bmline.BasmLine) (*bmmeta.BasmMeta, error) {
return nil, nil
}