-
Notifications
You must be signed in to change notification settings - Fork 0
/
Format.py
44 lines (30 loc) · 1006 Bytes
/
Format.py
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
class Format:
def __init__(self, opcode):
self.opcode = opcode
class RFormat(Format):
def __init__(self,opcode, rs, rt, rd, shamt, funct):
super().__init__(opcode)
self.rs = rs
self.rt = rt
self.rd = rd
self.shamt = shamt
self.funct = funct
self.bits = self.opcode + self.rs + self.rt + self.rd + self.shamt + self.funct
def __str__(self):
return 'R' + self.opcode + ':' + self.funct
class IFormat(Format):
def __init__(self, opcode, rs, rt, const):
super().__init__(opcode)
self.rs = rs
self.rt = rt
self.const = const
self.bits = self.opcode + self.rs + self.rt + self.const
def __str__(self):
return 'I' + self.opcode
class JFormat(Format):
def __init__(self, opcode, address):
super().__init__(opcode)
self.address = address
self.bits = self.opcode + self.address
def __str__(self):
return 'J' + self.opcode