示例#1
0
from inst import Inst, asm, print_asm, print_ihex

program = [
Inst.LUI(5, 0x10000000), # memory = 0x10000000
Inst.ADD(6, 0, 0), # x6 = 0 (counter)
'loop',
Inst.SW(5, 6, 0x100), # memory[x5+0x100] = x6
Inst.ADDI(6, 6, 1), # x6++
Inst.LJAL(0, 'loop') # goto loop
]

r = asm(program)
print_asm(r)
print()
print_ihex(r)
示例#2
0
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'),
示例#3
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')
示例#4
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]
示例#5
0
_score2		= 22
_counterX	= 23
_intervalX	= 24
_counterY	= 25
_intervalY	= 26

_memAddr	= 27
_memBase	= 28
_count		= 29
_tmp2		= 30

# 初期化部分
sys_init = [

Inst.LUI(_addrBase, 0x0400_0000),			# addrBase = [0x0400_0000]
Inst.ADDI(_wr, _num0, 1),					# wr = 1
Inst.SLLI(_wr, _wr, 14),					# wr <<= 14
Inst.ADDI(_barY1u, _num0, 1),				# barY1u = 1
Inst.ADDI(_barY1d, _num0, 2),				# barY1d = 2
Inst.ADDI(_barY2u, _num0, 1),				# barY2u = 1
Inst.ADDI(_barY2d, _num0, 2),				# barY2d = 2
Inst.ADDI(_velX, _num0, 1),					# velX = 1
Inst.ADDI(_velY, _num0, 1),					# velY = 1
Inst.ADDI(_score1, _num0, 0),				# score1 = 0
Inst.ADDI(_score2, _num0, 0),				# score2 = 0
Inst.ADDI(_counterX, _num0, 0),				# counterX = 0
Inst.ADDI(_counterY, _num0, 0),				# counterY = 0
Inst.ADDI(_intervalX, _num0, 3),			# interval = 1
Inst.ADDI(_intervalY, _num0, 3),			# interval = 1
Inst.ADDI(_num1, _num0, 1),					# num1 = 1
示例#6
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)
示例#7
0
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),
    Inst.SB(rd[6],rs[9],0x000),
    Inst.ADDI(rd[7],rs[7],1),
示例#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)