MIPS中的扫描转换/ Bresenham算法不起作用

时间:2019-05-09 04:12:35

标签: assembly mips

我正在尝试制作一个mips程序,该程序将仅使用空格和*表示像素来打印整行。

对于水平线的输入,它可以完美运行。

但是垂直无法正确打印,当我尝试实现Bresenham算法并使用它来查找我无法找到的像素时。

这两个程序都会进入无限循环,无法正确打印出来。

感谢您的关注和帮助。

在测试程序后,我意识到没有任何输入能够正确打印,并且程序循环了一段时间,然后达到预期效果

.data
msg1:   .asciiz " " 
msg2:   .asciiz "*" 
msg3:   .asciiz "\n"
msg4:   .asciiz "\n------"

xArray:  .space 80
yArray:  .space 80

.text

main:
add $s0, $0, 5 #x1 These four values don't print correctly
add $s1, $0, 0 #y1 They print at (0,0) - (0,5) 

add $s2, $0, 5 #x2 They should print through (5,0) - (5,5) 
add $s3, $0, 5 #y2

jal lineScanConversionFunc

add $s0, $0, 0 #x1 These four values do print correctly
add $s1, $0, 5 #y1

add $s2, $0, 5 #x2 
add $s3, $0, 5 #y2

jal lineScanConversionFunc

add $s0, $0, 2 #x1 These values get stuck inside of loop to add values to the array
add $s1, $0, 3 #y1

add $s2, $0, 8 #x2
add $s3, $0, 7 #y2

jal lineScanConversionFunc

j finish
lineScanConversionFunc:
li $t0, 0
sb $s0, xArray($t0)
sb $s1, yArray($t0)

addi $t0, $t0, 4
sb $s2, xArray($t0)
sb $s3, yArray($t0)

beq $s0,$s2, horiz
beq $s1,$s3, vert

sub $s4, $s3, $s1 #y2 - y1, ^y
sub $s5, $s2, $s0 #x2 - x1, ^x

add $s6, $s4, $s4 #2^y
add $s7, $s5, $s5 #2^x

sub $t2,$s6,$s7 #2^y - 2^x
sub $t3,$s6,$s5 #2^y - x, P0

add $t1, $t1,$zero
addi $t1, $t1, 2

slt $t4, $zero, $t3
beq $t4, $zero, less
j greater

less: #(x+1,y) #The loop that gets suck is from here
addi $t0, $t0, 4
addi $s0,$s0,1
sb $s0, xArray($t0)
sb $s1, yArray($t0) 

add $t3,$t3,$s6

beq $t1, $s5, display
j keepGoing

greater:     #(x+1,y+1)
addi $t0, $t0, 4
addi $s0,$s0,1
addi $s1,$s1,1
sb $s0, xArray($t0)
sb $s1, yArray($t0) 

add $t3,$t3,$t2
beq $t1, $s5, display

j keepGoing

keepGoing:      
addi $t1, $t1, 1 
slt $t4, $zero, $t3
beq $t4, $zero, less
j greater #Here is the location of the other end of the loop the third value gets suck in
horiz:
beq $s1,$s3, display
addi $s1,$s1, 1

addi $t0, $t0, 4
sb $s0, xArray($t0)
sb $s1, yArray($t0)
j horiz
vert:
beq $s0,$s2, display
addi $s0,$s0, 1

addi $t0, $t0, 4
sb $s0, xArray($t0)
sb $s3, yArray($t0)
j vert  
display:                
add $t1, $0, 0 #index

add $t2, $0, 0 #x lowest
div $t3, $t0, 4 #x higest

add $t4, $t3, $0 #y higest

loadArraySearch:
lb $t5, xArray($t1)
lb $t6, yArray($t1)

beq $t2, $t5, xEquals
#j printSpace
j arrayIncrease             

 xEquals:
beq $t4, $t6, printDot
#j printSpace
 j arrayIncrease
 printSpace:
li $v0, 4
la $a0, msg1
syscall

j loadArraySearch

 printDot:
li $v0, 4
la $a0, msg2
syscall

j xIncrease

printLine:
li $v0, 4
la $a0, msg3
syscall

j loadArraySearch   

arrayIncrease:
beq $t1, $t0 xIncrease
addi $t1, $t1, 4
j loadArraySearch

xIncrease:  
beq $t2, $t3, yDecrease
addi $t2, $t2, 1
add $t1, $zero, 0
j loadArraySearch
yDecrease:
beq $t4, $zero, return
subi $t4, $t4, 1
add $t2, $zero, 0
add $t1, $zero, 0
j printLine
return: 
li $v0, 4
la $a0, msg4
syscall

jr $ra
finish:
li $v0, 10
syscall

0 个答案:

没有答案