#! /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')
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)
Inst.ADDI(_tmp, 0, 0b1110_0000), # 7 Inst.SB(_memBase, _tmp, 0x7), Inst.ADDI(_tmp, 0, 0b1111_1110), # 8 Inst.SB(_memBase, _tmp, 0x8), Inst.ADDI(_tmp, 0, 0b1111_0110), # 9 Inst.SB(_memBase, _tmp, 0x9), Inst.ADDI(_tmp, 0, 0xF2), # 7seg: 0 Inst.ADDI(_count, _num0, 64), Inst.ADDI(_tmp2, _addrBase, 0), Inst.SB(_tmp2, _tmp, 0), Inst.ADDI(_tmp2, _tmp2, 1), Inst.SUB(_count, _count, _num1), Inst.BEQ(_count, _num0, 4), Inst.JAL(0, -4 * 5), Inst.ADDI(_tmp, 0, 0xDA), # 7seg: 0 Inst.ADDI(_count, _num0, 64), Inst.ADDI(_tmp2, _addrBase, 0), Inst.SB(_tmp2, _tmp, 0), Inst.ADDI(_tmp2, _tmp2, 1), Inst.SUB(_count, _count, _num1), Inst.BEQ(_count, _num0, 4), Inst.JAL(0, -4 * 5), Inst.ADDI(_tmp, 0, 0x60), # 7seg: 0 Inst.ADDI(_count, _num0, 64), Inst.ADDI(_tmp2, _addrBase, 0), Inst.SB(_tmp2, _tmp, 0), Inst.ADDI(_tmp2, _tmp2, 1),
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)