Last active
April 26, 2020 07:41
-
-
Save Arham4/298ba46aedbec9dc477a7e47cb63a161 to your computer and use it in GitHub Desktop.
SE 3340 - Homework 8: MMIO with MARS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.eqv WIDTH 64 | |
.eqv HEIGHT 64 | |
.eqv RED 0x00FF0000 | |
.eqv GREEN 0x0000FF00 | |
.eqv BLUE 0x000000FF | |
.eqv WHITE 0x00FFFFFF | |
.eqv YELLOW 0x00FFFF00 | |
.eqv CYAN 0x0000FFFF | |
.eqv MAGENTA 0x00FF00FF | |
.eqv SLEEP_TIME 50 | |
.data | |
colors: .word MAGENTA, CYAN, YELLOW, BLUE, GREEN, RED | |
.macro exit | |
li $v0, 10 | |
syscall | |
.end_macro | |
.macro set_registers_to_dimensions (%rw, %rh) | |
# %rw = the register to assign the width, %rh = the register to assign the height | |
addi %rw, $zero, WIDTH | |
addi %rh, $zero, HEIGHT | |
sra %rw, %rw, 1 | |
sra %rh, %rh, 1 | |
.end_macro | |
.macro pause (%time_ms) | |
# %time_ms = the amount of milliseconds to sleep for | |
move $t4, $a0 | |
li $v0, 32 | |
li $a0, %time_ms | |
syscall | |
move $a0, $t4 | |
.end_macro | |
.macro pause # helper macro to call the pause macro with a predefined (.eqv) SLEEP_TIME amount | |
pause SLEEP_TIME | |
.end_macro | |
.text | |
# In order to visualize this program, one must use the Bitmap Display tool in MARS 4.5. To access the tool, one must open MARS, click | |
# the "Tools" menu on the top, and select "Bitmap Display." For ease in programming, this program writes to the base address $gp. Additionally, | |
# this program is made optimized for certain settings. The settings are as follows: | |
# | |
# - Set the "Unit Width in Pixels" to 4. | |
# - Set the "Unit Height in Pixels" to 4. | |
# - Set the "Display Width in Pixels" to 256. | |
# - Set the "Display Height in Pixel" to 256. | |
# - Set the "Base address for display" to be using "0x10008000 ($gp)." | |
# | |
# Once this is set up, the program is ready to be run. Select the "Connect to MIPS" button on the bottom left of the Bitmap Display screen. Then, | |
# click, as standard, the Assemble and Run buttons in the main MARS editor menu. The program should display in the Bitmap Display if the instructions | |
# are followed properly. For multiple runs, click the "Reset" button on the bottom of the Bitmap Display screen before re-executing. | |
la $s0, colors # $s0 = where the colors array is stored in memory | |
li $t7, 20 # $t7 = the offset of the colors array | |
set_registers_to_dimensions $t0, $t1 # $t0 = the x counter, $t1 = the y counter | |
addi $s1, $t0, 8 # $s1 = the x point to stop at | |
addi $s2, $t1, 9 # $s2 = the y point to stop at | |
add $a1, $zero, $t1 | |
top: | |
add $a0, $zero, $t0 | |
addi $t0, $t0, 1 | |
jal draw_marquee_pixel | |
pause | |
bne $t0, $s1, top | |
addi $t1, $t1, 1 | |
right: | |
add $a1, $zero, $t1 | |
addi $t1, $t1, 1 | |
jal draw_marquee_pixel | |
pause | |
bne $t1, $s2, right | |
add $t0, $zero, $a0 # readjust $t0 to be where the last pixel was placed horizontally | |
add $t1, $zero, $a1 # readjust $t1 to be where the last pixel was placed vertically | |
set_registers_to_dimensions $s1, $s2 # new x and y points to stop at | |
# some visual changes to above new limitations | |
subi $s1, $s1, 2 | |
subi $s2, $s2, 1 | |
bottom: | |
add $a0, $zero, $t0 | |
subi $t0, $t0, 1 | |
jal draw_marquee_pixel | |
pause | |
bne $t0, $s1, bottom | |
left: | |
add $a1, $zero, $t1 | |
subi $t1, $t1, 1 | |
jal draw_marquee_pixel | |
pause | |
bne $t1, $s2, left | |
exit | |
draw_marquee_pixel: | |
# $a0 = the x coordinate, $a1 = the y coordinate | |
mul $t9, $a1, WIDTH | |
add $t9, $t9, $a0 | |
mul $t9, $t9, 4 | |
add $t9, $t9, $gp | |
# goes to the next available color | |
add $t5, $s0, $t7 | |
lw $t6, ($t5) | |
# assigns the color to the memory bit | |
sw $t6, ($t9) | |
# moves to the next color | |
subi $t7, $t7, 4 | |
# if we have hit a negative color index, reset back to 20 (for red) | |
bge $t7, $zero, return | |
addi $t7, $t7, 20 | |
return: | |
jr $ra |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment