Hi guys help this newbie out. My code which uses midpoint circle algorithm to draw the circle and seeking algorithm (steering behaviour) to move the circle towards a position. However the circle is not being drawn and the seeking algorithm i believe is flawed. Please review this and tell me what I am doing wrong.

Seeking Algorithm

.data

midpoint circle algorithm variables

xvalue: .word 0
yvalue: .word 10
radius: .word 10

yvalue = radius

colour: .word 0x00FFFFFF
one: .word 1
two: .word 2
three: .word 3
five: .word 5
bmp: .space 0x80000
bmpheight: .word 70
bmpwidth: .word 90

seeking algorithm variables

angle: .word 0xffff0014
orientation: .word 0xffff0040
velocity: .word 0xffff0010
maxspeed: .word 200
pi: .float 3.142
max_force: .word 5
sinangle: .double 0.96
cosangle: .double 0.99
square1: .double 67.08
square2: .double 316.23
anglemain: .double 8.13

.text
main:
lw $a2, one
lw $a1, radius
jal dvalue
dvalue:
sub $a3, $a2, $a1 # d
jal drawpixel

draw first set of points

lw $t4, three
lw $t5, five
li $a0, 0 # x
lw $a1, radius # y

while y > x

bgt $a1, $a0, dlessthan

dlessthan:
blez $a3, selectE # if d < 0 then
bgtz $a3, selectSE
jal stopalgorithm

selectE:
sll $a0, $a0, 2
add $t3, $a0, $t4 # 2x + 3
add $a3, $a3, $t3 # d + = x * 2 + 3
addi $a0, $a0, 1

selectSE:
sub $t3, $a0, $a1 # x - y
sll $t3, $t3, 2 # * 2
add $t3, $t3, $t5 # +5
addi $a0, $a0, 1
lw $a1, radius
addi $a1, $a1, -1
jal drawpixel
jal stopalgorithm

stopalgorithm:

when x > = y stop

bge $a0, $a1, pause

pause:
li $v0, 32
nop

drawpixel:
li $t0, 0x10000100
lw $t3, bmp #t3
lw $t4, bmpheight #t4
lw $t5, bmpwidth #t5
sll $a0, $a0, 1

add $t6, $a0, $a0
sll $t6, $t6, 2
add $t6, $t6, $t0
lw $t5, colour
sw $t5, ($t6)

jal startseeking

startseeking:
addi $sp, $sp, -96
sw $ra, 92($sp)
sw $a0, 8($sp)
sw $a1, 12($sp)
sw $a3, 16($sp)
sw $t1, 20($sp)
sw $t2, 24($sp)
sw $t3, 28($sp)
sw $t4, 32($sp)
sw $t5, 36($sp)
sw $t6, 40($sp)
sw $t7, 44($sp)
sw $t8, 48($sp)
sw $t9, 52($sp)

sw $t5, 26

li $t1, 100
li $t2, 300
li $a0, 30 # x
li $a1, 60 # y
li $v0, 120 # set location
lw $a3, maxspeed

dotproduct:
mul $t3, $a0, $a1 # x1 * x2
mul $t3, $1, $t2 # y1 * y2
add $t3, $t3, $t4 # t3 is the dot product

magnitude:
mult $a0, $a0
mult $a1, $a1
add $t5, $a1, $a0

square root, i took a shortcut here, already calculated the square root

l.d $f5, square1
mult $t1, $t1
mult $t2, $t2
add $t6, $a1, $a2

square root, i took a shortcut here, already calculated the square root

l.d $f6, square2 #316.23

anglebetween:
jal dotproduct
nop
jal magnitude

mtc1 $t3, $f0
div.s $f5, $f0, $f5 # dot product / magnitude
div.s $f6, $f0, $f6 # dotproduction / magniude

arcos (adjacent/hypotenuse) = angle
cos angle = 0.98994949
angle = 8.13

l.d $f7, anglemain #8.13
s.d $f7, angle
jal desiredvelocity

desiredvelocity:

targetposition - characterposition

sub $t1, $t1, $a0
sub $t2, $t2, $a1

muliply by maxspeed

mult $t1, $a3
mult $t2, $a3

sll $t1, $t1, maxspeed
sll $t2, $t2, maxspeed

jal addtodesiredvelocity

addtodesiredvelocity:

addi $t2, $zero, $t2
addi $t1, $zero, $t1

sw $t1, desiredvelocity($0)
sw $t2, desiredvelocity($0)
jal steerforce

steerforce:
sub $t1, $t1, $a3
sub $t2, $t2, $a3

multiply by max force

sll $t1, $t1, 5
sll $t2, $t2, 5
jal newposition

updateobject:
li $v0, 121

updateposition:
add $a0, $a0, $a3
add $a1, $a1, $a3
li $v0, 121

newposition:

newposition = position + velocity

jal moveindirection
jal desiredvelocity
jal updateposition
jal returnmemory

moveindirection:

x = speed *sin of angle
y = speed * cos of angle

l.d $f8, sinangle # 0.962 # put sin of angle in $f8
l.d $f9, cosangle# 0.9899 # put cos of angle in $f9
l.d $f10, 30
l.d $f11, 60
mul.s $f8, $f8 $f10
mul.s $f9, $f8, $f11
jal updateobject

returnmemory:

lw $ra, 92($sp)
lw $a0, 8($sp)
lw $a1, 12($sp)
lw $a3, 16($sp)
lw $t1, 20($sp)
lw $t2, 24($sp)
lw $t3, 28($sp)
lw $t4, 32($sp)
lw $t5, 36($sp)
lw $t6, 40($sp)
lw $t7, 44($sp)
lw $t8, 48($sp)
lw $t9, 52($sp)

addi $sp, $sp, 96
jr $ra

jal exit

exit:
li $v0, 10
syscall
mips circle

well he only dots is completely different. The moving circle question only included the steering code part. Yes I wrote both of them. I know the midpoint has errors and i worked on redoing the setpixel code. I try to single step but I am not realising whats wrong. I know the steering code i wrote is wrong but i just cant find the complete algorithm for it to include sin, cos, madnitude, distance etc.

I don't write as much assembler today. Background? I wrote my own assembler back in the 80's and 90's but today I use the assembler code to get to C and then I'm in a higher level language. I know there are C compilers for MIPS and you may get much more help on C than assembler.

oh that is pretty cool :) so use a c compiler for mips? but from what you can see can you give a few pointers? I'm trying and rediting but the circle isnt being drawn

I can't be more specific as I don't know your target system. The last MIPS we used was the one from Microchip. Microchip has a basic C compiler and with their programmer and debugging tools you usually can single step your code till you find what's up.

Embedded systems like this are indeed cool. I've done so many over the years but as I don't know yours (and may never know it) you find yourself self supporting a lot. I know I felt that way most of the time.

ok well im using mars the simulator. ok thanks for your advice :)

You may have to give more information when posting about assembler. If this was the usual x86 devices (PCs) then folk might reply.

Here, and while I have a lot of embedded work over the years, I would never have guessed you were using Mars the simulator.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.