gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

ASM > plotting a circle in ASM

#18792 - niallz - Mon Apr 05, 2004 4:48 pm

hi,

can anybody tell me what is wrong with the following code snippet? not the actual assembly, just the way I'm using the registers etc. gcc 3.02 just tells me its encountered an internal error when I try to compile it.

Thanks
Niall

void PlotPixel16(u32 centre_x, u32 centre_y, u32 radius, u32 t)
{ // PlotPixel16(int in_iX, int in_iY, unsigned short int in_usColour)
//g_uspVideoBuffer[(in_iY) * 240 + (in_iX)] = (in_usColour);

asm volatile ( "mov r4, %3 \n" // r4 = t
"mov r7, #0 \n" // reset the negate value
"bl SIN \n" // branch with link to SIN
"mov r5, %2 \n" // r5 = radius
"mul r4, r5 \n" // r4 = (radius * Sin(t))
"lsr r4, #8 \n" // r4 = (radius * Sin(t)) >> BITSHIFT
"mov r5, %1 \n" // r5 = centre_y
"sub r6, r5, r4 \n" // r6 = centre_y - (Sin(t) * radius) >> BITSHIFT

"mov r4, %3 \n" // r4 = t
"add r4, r4, #90 \n" // r4 = t + 90
"mov r7, #0 \n" // reset the negate value
"bl SIN \n" // branch with link to SIN
"mov r5, %2 \n" // r5 = radius
"mul r4, r5 \n" // r4 = (radius * Cos(t))
"lsr r4, #8 \n" // r4 = (radius * Cos(t)) >> BITSHIFT
"mov r5, %0 \n" // r5 = centre_x
"add r5, r5, r4 \n" // r5 = centre_x + (radius * Cos(t)) >> BITSHIFT

"mul r6, #240 \n" // r6 = y * 240
"add r6, r6, r5 \n" // r6 = (y * 240) + x
"ldr r7, %5 \n" // r7 = g_uspVideoBuffer
"strh 0x8FFF, [r7, r4] \n"// [r7 + r6] = 0x8FFF

"SIN: cmp r4, #90 \n"
"ble LESS90 \n" // if r4 <= 90 goto LESS90
"cmp r4, #180 \n" //
"ble LESS180 \n" // if r4 <= 180 goto LESS180
"mov r8, #90 \n"
"lsr r8, #2 \n" // r8 = 360
"cmp r4, r8 \n" //
"ble LESS360 \n" // if r4 <= 360 goto LESS360
"bgt GREAT360 \n" // if r4 > 360 goto GREAT360

"LESS90: ldr r5, %0 \n" // r5 = mysin
"ldr r4, [r5, r4] \n" // r4 = mysin[r4]
"b NEG \n" // goto NEG

"LESS180: ldr r5, %0 \n" // r5 = mysin
"sub r4, #180, r4 \n" // r4 = 180 - r4
"ldr r4, [r5, r4] \n" // r4 = mysin[180-r4]
"b NEG \n" // goto NEG

"LESS360: sub r4, r4, #180 \n" // r4 = r4 - 180
"mov r7, #1 \n" // set the negate value
"b SIN \n" // branch to SIN

"GREAT360: "mov r8, #90 \n"
"lsr r8, #2 \n" // r8 = 360
"sub r4, r4, r8 \n" // r4 = r4 - 360
"b SIN \n" // branch to SIN

"NEG: cmp r7, #0 \n" //
"bgt NEGTRUE \n" // goto NEGTRUE if negate is set
"mov pc, lr \n" // return using the lr
"NEGTRUE: neg r4, r4 \n" // negate r0
"mov pc, lr \n" // return using the lr

: : "r"(centre_x),
"r"(centre_y),
"r"(radius),
"r"(t),
"m"(mysin),
"m"(g_uspVideoBuffer)
: "r4","r5","r6","r7","r8"
);
}

#18803 - poslundc - Mon Apr 05, 2004 7:47 pm

I've only barely glanced at your code, but I notice you are using the MUL instruction with a constant, which is illegal.

There could be any number of other errors, though.

Dan.