Alright so I am coding MIPS assembly in the MARS IDE. I am trying to draw a circle to the bitmap display with a unit width and height of 8 and a display width and height of 512. I get the general idea and have coded a rectangle. But I was wondering what is the best way to try and code a circle? Say the center is in the middle of the display, how do I code this? Is there a way to know which row and which column I am in? Here is what I have so far.
.eqv GRAY 0x999997 #hex value for gray
.eqv BLACK 0x000000 #hex value for black
.eqv WHITE 0xFFFFFF #hex value for white
.text
.globl main
main:
li $s0, BASEADRESS #save in $s0
li $s1, GRAY #save green in s1
li $s2, BLACK #save black in s2
li $s3, WHITE #save white in s3
#Initialize
li $t0, 0 #load 0 into t0
li $t1, 4096 #load 4096 into t1
move $t3, $s0 #store baseaddress in t3
drawRectangle:
#if current pixel >= 2048 and <= 3000 draw the color
li $t6, 1023
li $t7, 1500
sgt $t4, $t0, $t6 #If greater than 2048 true
slt $t5, $t0, $t7 #If less than 3000 true
and $t4, $t4, $t5 #If both true 1
bnez $t4, drawPixel #Draw gray pixel
#False branch
sw $s2, 0($t3) #Stick black into the shape
addi $t3, $t3, 4
add $t0, $t0, 1
b drawRectangle
drawPixel:
sw $s1, 0($t3)
addi $t3, $t3, 4
add $t0, $t0, 1
b drawRectangle
startLoop:
#test
slt $t4, $t0, $t1 #test to see if we have colored all 256 bits
beqz $t4, endLoop #if we have, end program
#Write the color to the display memory
sw $s1, 0($t3) #Shove green into that value
#updates
addi $t3, $t3, 4 #increment the base address by 4 to point to next pixel
add $t0, $t0, 1 #Increment the index by 1
b startLoop #do the loop again
endLoop:
#End program
li $v0, 10
syscall