Link to home
Start Free TrialLog in
Avatar of Doug8
Doug8

asked on

C to assembly conversion help

Hello, I am having trouble converting this function to assembly because i barely know assembly, so i need some help.  Below is the C function(bout 20 lines) and after that is what i have started on(I know its all wrong). So let me explain the variables below:

is_cached - is hit a lot more often
n - is from 0 to 319
tex - is char *
tex_row_table - is int [258]
swim_u & swim_v - is int [256]
g_mip - is int either 0,1,2,3
wid * ht - are int

#include "s.h"
#include "fix.h"
#include "tm.h"

void draw_affine(int n, char *dest, fix u, fix v, fix du, fix dv)
{
   if (is_cached) {
      while (n--) {
         int iu = u >> 16;
         int iv = v >> 16;
         *dest++ = tex[tex_row_table[iv+1] + iu];
         u += du;
         v += dv;
      }
   } else {  
      while (n--) {
         int iu = ((u + (swim_u[(((v<<g_mip) >> 16) & 0xff)] >> g_mip)) >> 16) & wid;
         int iv = ((v + (swim_v[(((u<<g_mip) >> 16) & 0xff)] >> g_mip)) >> 16) & ht;
         *dest++ = tex[tex_row_table[iv+1] + iu];
         u += du;
         v += dv;
      }
   }
}

this is what i have for assembly; (just for some sorta skeleton ;)

      .file "affine.asm"
      .medium
      .486

_global draw_affine

draw_affine:

      mov si,n
      les di,dest
      mov eax,u
      mov ebx,v
      mov ecx,du
      mov edx,dv
      mov ax,tex_row_table
      cmpl is_cached,0
      je scandone

scanloop:
            
      add ax,eax
      add ax,ebx
      adc bx,ax
      mov bx,tex
      mov ah,[bx]
      mov es:[di],ah
      add eax,ecx
      add ebx,edx
      dec si
      jnz scanloop

scandone:

      ret

so im sure a lot, a lot of that is wrong so thats why i need help, i also only attempted the if(is_cached).  This should be enough points for this, and any other questions email me at benco@gisco.net.

Thanx a lot in advance
Avatar of Tommy Hui
Tommy Hui

Which compiler are you using? If you're using Borland C++, you can at least take a look at the code they gerenate for the function by using bcc -S -c foo.cpp on the command line. If you're using Visual C++, you can use cl /c /Fa foo.c on the command line. This will give you at least the compiler's version of the function. Then you can hand optimize or use the compiler's optimization features to see how they do it.
Avatar of Doug8

ASKER

Im using DJGPP and have already used the gcc -S option and the code is very unreadable because the compiler does many things to protect the stack and so forth and its in AT&T syntax so its even harder for me to read.  The code produced is way too complex for me to optimize.
I'll convert it to assembly for you.
Can you do inline assembly in DJGPP, because it would be easier if you could?
Avatar of Doug8

ASKER

Yes you can do inline assembly but it is far different from other compilers, if you would do it in inline, im sure i probally can convert it.
That would be easier because you wouldn't have to pass as many variables.
ASKER CERTIFIED SOLUTION
Avatar of mosfet
mosfet

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial