from inst import Inst, asm, print_asm, print_ihex

seg_pattern = [0xFC, 0x60, 0xDA, 0xF2, 0x66, 0xB6, 0xBE, 0xE0, 0xFE, 0xF6]

x_0 = 0
pattern_mem = 5
pattern_tmp = 6

program = [Inst.LUI(pattern_mem, 0x10001000)]

for i in range(10):
    print(seg_pattern[i])
    program.append(Inst.ADDI(pattern_tmp, 0, seg_pattern[i]))
    program.append(Inst.SB(pattern_mem, pattern_tmp, i))

seg = 6
counter = 7
pattern_mem_addr = 8
pattern = 9
max = 15

program_main = [
    'main',
    Inst.LUI(seg, 0x04000000),
    Inst.ADDI(counter, x_0, 0),
    Inst.ADDI(max, x_0, 9), 'loop',
    Inst.ADD(pattern_mem_addr, counter, pattern_mem),
    Inst.LBU(pattern, pattern_mem_addr, 0),
    Inst.SB(seg, pattern, 0),
    Inst.ADDI(counter, counter, 1),
    Inst.LBEQ(counter, max, 'reset'),
Exemple #2
0
#! /usr/bin/env python3

from inst import Inst

filename = 'sample1_7seg.hex'

program = []
program.append(Inst.LUI(5, 0x04000000))
program.append(Inst.ADDI(10, 0, 0xff))
program.append(Inst.SB(5, 10, 0x00))
program.append(Inst.JAL(0, -4 * 2))

# generate assembly
#print('')
print('sample program 1')
for i in program:
    print('{:08x} | {}'.format(i.gen_code(), i.gen_mnemonic()))

# generate intel hex format
with open(filename, 'w', encoding='utf-8') as file:
    for offset, inst in enumerate(program):
        file.write(inst.gen_HEX(offset))
        file.write("\n")
    file.write(':00000001FF\n')
Exemple #3
0
from inst import Inst, asm, print_asm, print_ihex

program = [
# Store 7seg led patterns
Inst.LUI(5, 0x10001000), # memory = 0x10001000
Inst.ADDI(6, 0, 0b11111100), # 7seg: 0
Inst.SB(5, 6, 0x0),
Inst.ADDI(6, 0, 0b01100000), # 1
Inst.SB(5, 6, 0x1),
Inst.ADDI(6, 0, 0b11011010), # 2
Inst.SB(5, 6, 0x2),
Inst.ADDI(6, 0, 0b11110010), # 3
Inst.SB(5, 6, 0x3),
Inst.ADDI(6, 0, 0b01100110), # 4
Inst.SB(5, 6, 0x4),
Inst.ADDI(6, 0, 0b10110110), # 5
Inst.SB(5, 6, 0x5),
Inst.ADDI(6, 0, 0b10111110), # 6
Inst.SB(5, 6, 0x6),
Inst.ADDI(6, 0, 0b11100000), # 7
Inst.SB(5, 6, 0x7),
Inst.ADDI(6, 0, 0b11111110), # 8
Inst.SB(5, 6, 0x8),
Inst.ADDI(6, 0, 0b11110110), # 9
Inst.SB(5, 6, 0x9),
# Main
Inst.LUI(6, 0x04000000),
Inst.ADD(7, 0, 0), # x7 = 0 (counter)
’loop’,
Inst.ADD(8, 7, 5), # address of memory[x7]
Inst.LBU(9, 8, 0), # x9 = memory[x7]
Exemple #4
0
from inst import Inst, asm, print_asm, print_ihex

program = [
    Inst.LUI(5, 0x04000000),  # r5 に7 セグのアドレスを代入
    Inst.ADDI(10, 0, 0x60),  # セグ「1」のパタンをr10 に代入
    Inst.SB(5, 10, 0x00),  # r5[0] = 0x60 (7 セグのアドレスに0x60 をストア)
    Inst.JAL(0, -4 * 1)  # 1 命令前に無条件分岐
]

r = asm(program)
print_asm(r)
print()
print_ihex(r)
# 0~9をループするカウンタ
## わかっているクソ仕様
## SBを一回使用した後にADDIを実行すると機能しない。
## これを回避するためにはダミーのSBが必要。

from inst import Inst, asm, print_asm, print_ihex

program = [
    # Store 7seg led patterns
    Inst.LUI(5, 0x10001000),  # memory = 0x10001000
    Inst.ADDI(6, 0, 0b11111100),  # 7seg: 0
    Inst.SB(5, 6, 0x0),
    Inst.SB(5, 6, 0x1),  #dummySB
    Inst.ADDI(6, 0, 0b01100000),  # 1
    Inst.SB(5, 6, 0x1),
    Inst.SB(5, 6, 0x2),  #dummySB
    Inst.ADDI(6, 0, 0b11011010),  # 2
    Inst.SB(5, 6, 0x2),
    Inst.SB(5, 6, 0x3),  #dummySB
    Inst.ADDI(6, 0, 0b11110010),  # 3
    Inst.SB(5, 6, 0x3),
    Inst.SB(5, 6, 0x4),  #dummySB
    Inst.ADDI(6, 0, 0b01100110),  # 4
    Inst.SB(5, 6, 0x4),
    Inst.SB(5, 6, 0x5),  #dummySB
    Inst.ADDI(6, 0, 0b10110110),  # 5
    Inst.SB(5, 6, 0x5),
    Inst.SB(5, 6, 0x6),  #dummySB
    Inst.ADDI(6, 0, 0b10111110),  # 6
    Inst.SB(5, 6, 0x6),
    Inst.SB(5, 6, 0x7),  #dummySB
Exemple #6
0
from inst import Inst, asm, print_asm, print_ihex

rd = []
for i in range(50):
    rd.append(i)

rs = []
for i in range(50):
    rs.append(i)

seg_pattern = [0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0xFE,0xF6]

program = [
    Inst.LUI(5,0x10001000),
]

for i in range(10):
    program.append(Inst.ADDI(rd[6],rs[0],seg_pattern[i]))
    program.append(Inst.SB(rd[5],rs[6],i))

program_main = [    
    Inst.LUI(rd[6], 0x04000000),
    Inst.ADD(rd[7],rs[0],rs[0]), 
    Inst.LW(rd[10], rs[6], 0x48),
    'mainloop',
    Inst.ADD(rd[8],rs[7],rs[5]),
    Inst.ANDI(rd[11],rs[10],0x01),
    Inst.LBEQ(rd[11],0,'dontpush'),

    'push',
    Inst.LBU(rd[9],rs[8],0),
from inst import Inst, asm, print_asm, print_ihex

program = [
    Inst.LUI(5, 0x04000000),
    Inst.ADDI(6, 0, 0xFF),
    Inst.LW(10, 5, 0x48),
    Inst.ANDI(11, 10, 0x01),
    Inst.BEQ(11, 0, 0x08),
    Inst.SB(5, 6, 0x000),
    Inst.JAL(0, 4),
    Inst.SB(5, 0, 0x000),
    Inst.JAL(0, -28)
]

r = asm(program)
print_asm(r)
print()
print_ihex(r)