MIPS LOOP QUERY?

0

Hey fellow coders I'm new to MIPS and trying to get a loop to work as intended. I can see the loop is incrementing oh boy but it's not actually performing the loop. I'm trying to draw these blue and white squares right next to each other.

I have the code commented but what I'm trying to do is create a blue and white squares right next to each other blue white blue white blue white... 10 per row. How do I get this loop to work as intended?

#Purpose of this program is to create a blue and white cafe wall illusion
 
  


  .data 
    frame:
        .space 0x80000
        prompt_Size: .asciiz "What size square do you so desire?"
        prompt_Number: .asciiz "How many pairs of squares would you like?"
        white: .word 0x00ffffff
        blue: .data 0x000000ff
    .text
        
        li $v0, 4           #Code to Print to screen
        la $a0, prompt_Size     #Load first prompt into a0
        syscall             
        
        li $v0, 5           #Code to Accept Integer from user
        syscall             
        move $s0, $v0           #Code is moved from return register into the save register
      
        li $v0, 4           #Code to Print to screen
        la $a0, prompt_Number       #Load 2nd prompt into a0
        syscall             
            
        li $v0, 5           #Code to Accept Integer from user
        syscall             
        move $s1, $v0           #Code is moved from return register into the save register
        
    # Example of drawing a rectangle; left x-coordinate is 10, width is 20
        # top y-coordinate is 10, height is 20. Coordinate system starts with
        # (0,0) at the display's upper left corner and increases to the right
        # and down.  (Notice that the y direction is the opposite of math tradition.)
        add $t8, $t8, $zero
        add $t6, $zero, $zero  # i is initialized to 0        Make this loop and then take inputs from USER to control better
    
        Loop: addi $a0, $zero, 10
        addi $a1, $zero, 20
        addi $a2, $zero, 10
        addi $a3, $a3, 0    #0 Redundant but hey    
        addi $sp, $sp, -16      # create space for 3 values on the stack (a0, a1, a2) #
        sw $a0, 12($sp)
        sw $a1, 8($sp)
        sw $a2, 4($sp)
        sw $a3, 0($sp)
        addi $a3, $a3 0x000000ff
        jal square 
        
        addi $a0, $a0, 20      #This is where I would like to add $t8 and keep spacing the squares right next to each other
        addi $a1, $zero, 20
            addi $sp, $sp, -16      # create space for 3 values on the stack (a0, a1, a2)
        sw $a0, 12($sp)           
        sw $a1, 8($sp)
        sw $a2, 4($sp)
        sw $a3, 0($sp)
        addi $a3, $a3 0x00ffffff
        
    
        jal square
    
    
    
        
        
        addi $v0, $zero, 10 # exit
        syscall
        
        # draw a rectangle by changing value to white in frame
    # $a0 is xmin (i.e., left edge; must be within the display)
    # $a1 is width (must be nonnegative and within the display)
    # $a2 is ymin  (i.e., top edge, increasing down; must be within the display)
    # $a3 is color
    square:
    
        beq  $a1, $zero, squareReturn # zero width/height: draw nothing
        #beq  $a3, $zero, rectangleReturn # zero height: draw nothing
        add $t0, $zero,$a3
        #addi $t0, $zero, 0x000000ff # color: blue          Old code commented out for now****
        la   $t1, frame
        add $t5, $zero, $a1     #Copies a1 for an identical Y height value
            add  $a1, $a1, $a0 # simplify loop tests by switching to first too-far value
        add  $t5, $t5, $a2
        sll  $a0, $a0, 2 # scale x values to bytes (4 bytes per pixel)
        sll  $a1, $a1, 2
        sll  $a2, $a2, 11 # scale y values to bytes (512*4 bytes per display row)
    
        sll  $t5, $t5, 11
        addu $t2, $a2, $t1 # translate y values to display row starting addresses
        addu $t5, $t5, $t1
        addu $a2, $t2, $a0 # translate y values to square row starting addresses
        addu $t5, $t5, $a0
        addu $t2, $t2, $a1 # and compute the ending address for first square row
        addi $t4, $zero, 0x800 # bytes per display row
        
    
    
    
    squareYloop:
        move $t3,$a2 # pointer to current pixel for X loop; start at left edge
    
    squareXloop:
        sw $t0, 0($t3)
        sw $a3, 0($t3)    
        addiu $t3, $t3, 4
        bne $t3, $t2, squareXloop # keep going if not past the right edge of the rectangle
    
        addu $a2, $a2, $t4 # advance one row for the left edge
        addu $t2, $t2, $t4 # and right edge pointers
        bne $a2, $t5, squareYloop # keep going if not off the bottom of the rectangle
    
    squareReturn:
        lw $a0, 12($sp)
        lw $a1, 8($sp)
        lw $a2, 4($sp)
        lw $a3, 0($sp)
        addi $sp, $sp, 16
        
        
          #Loop Time boys and girls let's see if this works!!! :)
          # i is initialized to 6, $t6 = 6       Make this loop and then take inputs from USER to control better
            
           ##### addi $t8, $t8, 20 #trying to make an offset for my square placement      Not Working as Intended*****
            
        addi $t6, $t6, 1 # i ++
            slti $t7, $t6, 4 # $t1 = 1 if i < 4
            bne $t7, $zero, Loop # go to Loop if i < 5
    
    
        jr $ra
loops
assembly
mips
asked on Stack Overflow Sep 24, 2020 by Chris Deal • edited Sep 24, 2020 by Michael

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0