summaryrefslogtreecommitdiff
path: root/pyscv/baseassembler.py
blob: e65a5bd68881bd3ff8654db7d687d0c6cc17f6dc (plain)
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
from registers.RV32I import *
from InstructionSets.RV64I import *


Regs = RegistersRV32I()

def x(registerName):
    return Regs.getPos(registerName)

def compileBigEndian(instruction):
    hexrepr = hex(instruction.compile().value)
    hexval = hexrepr[2:]
    if len(hexval) < 8:
        hexval = "0" * (8 - len(hexval)) + hexval

    final = ""
    for i in range(0,8,2):
        final += hexval[i:i+2] + " "
    return final.rstrip().upper()

def compileLittleEndian(instruction):
    hexrepr = hex(instruction.compile().value)
    hexval = hexrepr[2:]
    if len(hexval) < 8:
        hexval = "0" * (8 - len(hexval)) + hexval

    final = ""
    for i in range(0,8,2):
        final += hexval[i:i+2] + " "
    final = final.rstrip().upper()
    return " ".join(reversed(final.split(" ")))