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)
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'), Inst.LJAL(x_0, 'loop'), 'reset', Inst.ADDI(20, x_0, 0xFC), Inst.SB(seg, 20, 0), Inst.LJAL(x_0, 'main') ] program.extend(program_main) r = asm(program) print_asm(r) print()
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] Inst.SB(6, 9, 0), Inst.ADDI(7, 7, 1), # x7++ Inst.LJAL(0, ’loop’) # goto loop ] r = asm(program) print_asm(r) print() print_ihex(r)
game_loop = [ # スコア表示 Inst.ADD(_memAddr, _score1, _memBase), Inst.LB(_tmp, _memAddr, 0), Inst.SB(_addrBase, _tmp, 0x21), Inst.ADD(_memAddr, _score2, _memBase), Inst.LB(_tmp, _memAddr, 0), Inst.SB(_addrBase, _tmp, 0x2E), # パターン初期化 Inst.ADDI(_pattern0, _num0, 0), # pattern0 = 0 Inst.ADDI(_pattern1, _num0, 0), # pattern1 = 0 Inst.ADDI(_pattern2, _num0, 0), # pattern2 = 0 Inst.ADDI(_pattern3, _num0, 0), # pattern3 = 0 # ボールがある列にボールを表示 Inst.ADDI(_tmp, _num0, 0), Inst.BNE(_posY, _tmp, 8), # if posY == 0 Inst.ORI(_pattern0, _num0, 1), # pattern0 = 1 Inst.SLL(_pattern0, _pattern0, _posX), # pattern0 <<= posX Inst.ADDI(_tmp, _num0, 1), Inst.BNE(_posY, _tmp, 8), # if posY == 1 Inst.ORI(_pattern1, _num0, 1), # pattern1 = 1 Inst.SLL(_pattern1, _pattern1, _posX), # pattern1 <<= posX Inst.ADDI(_tmp, _num0, 2), Inst.BNE(_posY, _tmp, 8), # if posY == 2 Inst.ORI(_pattern2, _num0, 1), # pattern2 = 1 Inst.SLL(_pattern2, _pattern2, _posX), # pattern2 <<= posX Inst.ADDI(_tmp, _num0, 3), Inst.BNE(_posY, _tmp, 8), # if posY == 3 Inst.ORI(_pattern3, _num0, 1), # pattern3 = 1 Inst.SLL(_pattern3, _pattern3, _posX), # pattern3 <<= posX # 左側のバーの表示 Inst.ADDI(_tmp, _num0, 0), Inst.BNE(_barY1u, _tmp, 4), # if barY1 == 0 Inst.ORI(_pattern0, _pattern0, 2), # pattern0 += 2 Inst.ADDI(_tmp, _num0, 1), Inst.BNE(_barY1u, _tmp, 4), # if barY1 == 1 Inst.ORI(_pattern1, _pattern1, 2), # pattern1 += 2 Inst.ADDI(_tmp, _num0, 2), Inst.BNE(_barY1u, _tmp, 4), # if barY1 == 2 Inst.ORI(_pattern2, _pattern2, 2), # pattern2 += 2 Inst.ADDI(_tmp, _num0, 3), Inst.BNE(_barY1u, _tmp, 4), # if barY1 == 3 Inst.ORI(_pattern3, _pattern3, 2), # pattern3 += 2 Inst.ADDI(_tmp, _num0, 0), Inst.BNE(_barY1d, _tmp, 4), # if barY1 == 0 Inst.ORI(_pattern0, _pattern0, 2), # pattern0 += 2 Inst.ADDI(_tmp, _num0, 1), Inst.BNE(_barY1d, _tmp, 4), # if barY1 == 1 Inst.ORI(_pattern1, _pattern1, 2), # pattern1 += 2 Inst.ADDI(_tmp, _num0, 2), Inst.BNE(_barY1d, _tmp, 4), # if barY1 == 2 Inst.ORI(_pattern2, _pattern2, 2), # pattern2 += 2 Inst.ADDI(_tmp, _num0, 3), Inst.BNE(_barY1d, _tmp, 4), # if barY1 == 3 Inst.ORI(_pattern3, _pattern3, 2), # pattern3 += 2 # 右側のバーの表示 Inst.ADDI(_tmp, _num0, 0), Inst.BNE(_barY2u, _tmp, 4), # if barY2 == 0 Inst.OR(_pattern0, _pattern0, _wr), # pattern0 += wr Inst.ADDI(_tmp, _num0, 1), Inst.BNE(_barY2u, _tmp, 4), # if barY2 == 1 Inst.OR(_pattern1, _pattern1, _wr), # pattern1 += wr Inst.ADDI(_tmp, _num0, 2), Inst.BNE(_barY2u, _tmp, 4), # if barY2 == 2 Inst.OR(_pattern2, _pattern2, _wr), # pattern2 += wr Inst.ADDI(_tmp, _num0, 3), Inst.BNE(_barY2u, _tmp, 4), # if barY2 == 3 Inst.OR(_pattern3, _pattern3, _wr), # pattern3 += wr Inst.ADDI(_tmp, _num0, 0), Inst.BNE(_barY2d, _tmp, 4), # if barY2 == 0 Inst.OR(_pattern0, _pattern0, _wr), # pattern0 += wr Inst.ADDI(_tmp, _num0, 1), Inst.BNE(_barY2d, _tmp, 4), # if barY2 == 1 Inst.OR(_pattern1, _pattern1, _wr), # pattern1 += wr Inst.ADDI(_tmp, _num0, 2), Inst.BNE(_barY2d, _tmp, 4), # if barY2 == 2 Inst.OR(_pattern2, _pattern2, _wr), # pattern2 += wr Inst.ADDI(_tmp, _num0, 3), Inst.BNE(_barY2d, _tmp, 4), # if barY2 == 3 Inst.OR(_pattern3, _pattern3, _wr), # pattern3 += wr # ドットマトリックスLEDの発光 Inst.SH(_addrBase, _pattern0, 0x40), # [addrBase + 0x40] = pattern0 Inst.SH(_addrBase, _pattern1, 0x42), # [addrBase + 0x42] = pattern1 Inst.SH(_addrBase, _pattern2, 0x44), # [addrBase + 0x44] = pattern2 Inst.SH(_addrBase, _pattern3, 0x46), # [addrBase + 0x46] = pattern3 # 得点処理 Inst.ADDI(_tmp, _num0, 0), Inst.BNE(_posX, _tmp, 4 * 5), # if posX == 0 Inst.ADDI(_score2, _score2, 1), # score2 += 1 Inst.ADDI(_tmp, _num0, 400), Inst.SUB(_tmp, _tmp, _num1), Inst.BNE(_tmp, _num0, -8), Inst.JAL(0, -4 * 87), Inst.ADDI(_tmp, _num0, 15), Inst.BNE(_posX, _tmp, 4 * 5), # if posX == 15 Inst.ADDI(_score1, _score1, 1), # score1 += 1 Inst.ADDI(_tmp, _num0, 400), Inst.SUB(_tmp, _tmp, _num1), Inst.BNE(_tmp, _num0, -8), Inst.JAL(0, -4 * 94), Inst.ADDI(_counterX, _counterX, 1), Inst.BNE(_counterX, _intervalX, 4 * 30), Inst.ADDI(_counterX, _num0, 0), # ボールの反射 # ボールの左バーでの反射 Inst.LB(_input, _addrBase, 0x49), # input = [addrBase + 0x48] Inst.ANDI(_input, _input, 0b0000_0001), # input &= 0b0000_0001
Inst.SB(5, 6, 0x6), Inst.SB(5, 6, 0x7), #dummySB Inst.ADDI(6, 0, 0b11100000), # 7 Inst.SB(5, 6, 0x7), Inst.SB(5, 6, 0x8), #dummySB Inst.ADDI(6, 0, 0b11111110), # 8 Inst.SB(5, 6, 0x8), Inst.SB(5, 6, 0x9), #dummySB Inst.ADDI(6, 0, 0b11110110), # 9 Inst.SB(5, 6, 0x9), Inst.SB(5, 6, 0xa), #dummySB # Main Inst.LUI(6, 0x04000000), Inst.ADDI(7, 0, 0), # x7 = 0 (counter) 'loop', Inst.ADD(8, 7, 5), # address of memory[x7] Inst.LBU(9, 8, 0), # x9 = memory[x7] Inst.SB(6, 9, 0), #dummySB Inst.SB(6, 9, 0), Inst.LBEQ(7, 9, 'reset'), 'add_1', Inst.ADDI(7, 7, 1), # x7++ Inst.LJAL(0, 'loop'), # goto loop 'reset', Inst.ADDI(7, 0, 0), Inst.LJAL(0, 'loop') # goto loop ] r = asm(program) print_asm(r) print()
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), Inst.LJAL(0,'mainloop'), 'dontpush', Inst.SB(rd[6],rs[9],0x000), Inst.LJAL(0,'mainloop') ]