diff --git a/20display_num.asm b/20display_num.asm new file mode 100644 index 0000000..ce755f5 --- /dev/null +++ b/20display_num.asm @@ -0,0 +1,139 @@ +.text + #initialize $sp + lui $sp, 0x4000 + addi $sp, $sp, 0x7ff + + # load digit to mem + lui $s0, 0x4000 + addi $s0, $s0, 0x20 + #0 + addi $s1, $zero, 0x3f + sw $s1, 0($s0) + #1 + addi $s1, $zero, 0x6 + sw $s1, 4($s0) + #2 + addi $s1, $zero, 0x5b + sw $s1, 8($s0) + #3 + addi $s1, $zero, 0x4f + sw $s1, 12($s0) + #4 + addi $s1, $zero, 0x66 + sw $s1, 16($s0) + #5 + addi $s1, $zero, 0x6d + sw $s1, 20($s0) + #6 + addi $s1, $zero, 0x7d + sw $s1, 24($s0) + #7 + addi $s1, $zero, 0x7 + sw $s1, 28($s0) + #8 + addi $s1, $zero, 0x7f + sw $s1, 32($s0) + #9 + addi $s1, $zero, 0x6f + sw $s1, 36($s0) + #A + addi $s1, $zero, 0x77 + sw $s1, 40($s0) + #B + addi $s1, $zero, 0x7c + sw $s1, 44($s0) + #C + addi $s1, $zero, 0x58 + sw $s1, 48($s0) + #D + addi $s1, $zero, 0x5e + sw $s1, 52($s0) + #E + addi $s1, $zero, 0x79 + sw $s1, 56($s0) + #F + addi $s1, $zero, 0x71 + sw $s1, 60($s0) + + lui $s1, 0x4000 + addi $s1, $s1, 0x10 + addi $s0, $zero, 0xa80 +main_loop: + addi $s0, $s0, 1 + addi $a0, $s0, 0 + addi $a1, $s1, 0 + jal display_number + j main_loop + + + # a0 is the number to be displayed, a1 is the bcd control addr +display_number: + addi $sp, $sp, -32 + sw $ra, 4($sp) + sw $s0, 8($sp) + sw $s1, 12($sp) + sw $s2, 16($sp) + sw $s3, 20($sp) + sw $s4, 24($sp) + sw $s5, 28($sp) + sw $s6, 32($sp) + + # s0 is the number to be displayed + addi $s0, $a0, 0 + + # s1 is the bcd_control addr + addi $s1, $a1, 0 + + # s2 is the base addr for display digit + lui $s2, 0x4000 + addi $s2, $s2, 0x20 + + # s3 is the counter for a complete scan of 4 digit + addi $s3, $zero, 0x2ed4 +all_digit_scan_loop: + # s4 is the num being shifted gradually + addi $s4, $s0, 0 + # s6 is the enable digit + addi $s6, $zero, 0x100 + + addi $s5, $zero, 4 +single_digit_loop: + # get a digit + andi $t0, $s4, 0xf + # digit * 4 is the memory shift + sll $t0, $t0, 2 + add $t0, $s2, $t0 + lw $t0, 0($t0) + or $t0, $t0, $s6 + sw $t0, 0($s1) + + srl $s4, $s4, 4 + sll $s6, $s6, 1 + # jal wait_for_digit_time + + addi $t0, $zero, 0x00ff +wait_time_loop: + addi $t0, $t0, -1 + bgtz $t0, wait_time_loop + + addi $s5, $s5, -1 + bgtz $s5, single_digit_loop + # end of single digit loop + + # ** depends on the clock ** + # four digit, 83.42us. + # 1s / 83.42us = 11988 = (2ed4)hex + + addi $s3, $s3, -1 + bgtz $s3, all_digit_scan_loop + + lw $ra, 4($sp) + lw $s0, 8($sp) + lw $s1, 12($sp) + lw $s2, 16($sp) + lw $s3, 20($sp) + lw $s4, 24($sp) + lw $s5, 28($sp) + lw $s6, 32($sp) + addi $sp, $sp, 32 + jr $ra diff --git a/20display_num.txt b/20display_num.txt new file mode 100644 index 0000000..d6276e3 --- /dev/null +++ b/20display_num.txt @@ -0,0 +1,86 @@ +20'd0: instruction <= 32'h3c1d4000; +20'd1: instruction <= 32'h23bd07ff; +20'd2: instruction <= 32'h3c104000; +20'd3: instruction <= 32'h22100020; +20'd4: instruction <= 32'h2011003f; +20'd5: instruction <= 32'hae110000; +20'd6: instruction <= 32'h20110006; +20'd7: instruction <= 32'hae110004; +20'd8: instruction <= 32'h2011005b; +20'd9: instruction <= 32'hae110008; +20'd10: instruction <= 32'h2011004f; +20'd11: instruction <= 32'hae11000c; +20'd12: instruction <= 32'h20110066; +20'd13: instruction <= 32'hae110010; +20'd14: instruction <= 32'h2011006d; +20'd15: instruction <= 32'hae110014; +20'd16: instruction <= 32'h2011007d; +20'd17: instruction <= 32'hae110018; +20'd18: instruction <= 32'h20110007; +20'd19: instruction <= 32'hae11001c; +20'd20: instruction <= 32'h2011007f; +20'd21: instruction <= 32'hae110020; +20'd22: instruction <= 32'h2011006f; +20'd23: instruction <= 32'hae110024; +20'd24: instruction <= 32'h20110077; +20'd25: instruction <= 32'hae110028; +20'd26: instruction <= 32'h2011007c; +20'd27: instruction <= 32'hae11002c; +20'd28: instruction <= 32'h20110058; +20'd29: instruction <= 32'hae110030; +20'd30: instruction <= 32'h2011005e; +20'd31: instruction <= 32'hae110034; +20'd32: instruction <= 32'h20110079; +20'd33: instruction <= 32'hae110038; +20'd34: instruction <= 32'h20110071; +20'd35: instruction <= 32'hae11003c; +20'd36: instruction <= 32'h3c114000; +20'd37: instruction <= 32'h22310010; +20'd38: instruction <= 32'h20100a80; +20'd39: instruction <= 32'h22100001; +20'd40: instruction <= 32'h22040000; +20'd41: instruction <= 32'h22250000; +20'd42: instruction <= 32'h0c00002c; +20'd43: instruction <= 32'h08000027; +20'd44: instruction <= 32'h23bdffe0; +20'd45: instruction <= 32'hafbf0004; +20'd46: instruction <= 32'hafb00008; +20'd47: instruction <= 32'hafb1000c; +20'd48: instruction <= 32'hafb20010; +20'd49: instruction <= 32'hafb30014; +20'd50: instruction <= 32'hafb40018; +20'd51: instruction <= 32'hafb5001c; +20'd52: instruction <= 32'hafb60020; +20'd53: instruction <= 32'h20900000; +20'd54: instruction <= 32'h20b10000; +20'd55: instruction <= 32'h3c124000; +20'd56: instruction <= 32'h22520020; +20'd57: instruction <= 32'h20132ed4; +20'd58: instruction <= 32'h22140000; +20'd59: instruction <= 32'h20160100; +20'd60: instruction <= 32'h20150004; +20'd61: instruction <= 32'h3288000f; +20'd62: instruction <= 32'h00084080; +20'd63: instruction <= 32'h02484020; +20'd64: instruction <= 32'h8d080000; +20'd65: instruction <= 32'h01164025; +20'd66: instruction <= 32'hae280000; +20'd67: instruction <= 32'h0014a102; +20'd68: instruction <= 32'h0016b040; +20'd69: instruction <= 32'h200800ff; +20'd70: instruction <= 32'h2108ffff; +20'd71: instruction <= 32'h1d00fffe; +20'd72: instruction <= 32'h22b5ffff; +20'd73: instruction <= 32'h1ea0fff3; +20'd74: instruction <= 32'h2273ffff; +20'd75: instruction <= 32'h1e60ffee; +20'd76: instruction <= 32'h8fbf0004; +20'd77: instruction <= 32'h8fb00008; +20'd78: instruction <= 32'h8fb1000c; +20'd79: instruction <= 32'h8fb20010; +20'd80: instruction <= 32'h8fb30014; +20'd81: instruction <= 32'h8fb40018; +20'd82: instruction <= 32'h8fb5001c; +20'd83: instruction <= 32'h8fb60020; +20'd84: instruction <= 32'h23bd0020; +20'd85: instruction <= 32'h03e00008; diff --git a/20display_num_mars.txt b/20display_num_mars.txt new file mode 100644 index 0000000..1494ae8 --- /dev/null +++ b/20display_num_mars.txt @@ -0,0 +1,86 @@ +3c1d4000 +23bd07ff +3c104000 +22100020 +2011003f +ae110000 +20110006 +ae110004 +2011005b +ae110008 +2011004f +ae11000c +20110066 +ae110010 +2011006d +ae110014 +2011007d +ae110018 +20110007 +ae11001c +2011007f +ae110020 +2011006f +ae110024 +20110077 +ae110028 +2011007c +ae11002c +20110058 +ae110030 +2011005e +ae110034 +20110079 +ae110038 +20110071 +ae11003c +3c114000 +22310010 +20100a80 +22100001 +22040000 +22250000 +0c00002c +08000027 +23bdffe0 +afbf0004 +afb00008 +afb1000c +afb20010 +afb30014 +afb40018 +afb5001c +afb60020 +20900000 +20b10000 +3c124000 +22520020 +20132ed4 +22140000 +20160100 +20150004 +3288000f +00084080 +02484020 +8d080000 +01164025 +ae280000 +0014a102 +0016b040 +200800ff +2108ffff +1d00fffe +22b5ffff +1ea0fff3 +2273ffff +1e60ffee +8fbf0004 +8fb00008 +8fb1000c +8fb20010 +8fb30014 +8fb40018 +8fb5001c +8fb60020 +23bd0020 +03e00008