Hi all,
I just started asm and I tried pass to assembler (without optimization) the following C program, but it doesn?t seem correct ?
Someone can help me?

C program:
void filter(int height, int width, Byte *porig[], Byte *pdest[])
{
      int x, y, r, g, b, color;
  for(y = 0; y < height; y++){
      for(x = 0; x < width * 3; x+=3){
        r = porig;
        g = porig;
        b = porig;
        color = (r * 299 + g * 587 + b * 114) / 1000;
        pdest = (Byte)color;
        pdest = (Byte)color;
        pdest = (Byte)color;
      }
  }
}

ASM:

/*************************************
ebp+20 pdest
ebp+16 porig
ebp+12 width
ebp+8 height 
ebp-4  x
ebp-8    y
*************************************/


  asm{
    mov dword ptr , 0      //y = 0

  f2_cicle_y_start:
      mov eax, dword ptr
      cmp eax, dword ptr     //y < height ?
      jge f2_cicle_y_end


      mov dword ptr , 0      //x = 0

  f2_cicle_x_start:
      mov eax, dword ptr
      add eax, eax
      add eax, dword ptr
      cmp dword ptr , eax    //x < width * 3 ?
      jge f2_cicle_x_end




      mov ebx, dword ptr     //porig // r
      mov ecx, dword ptr     //x
      mov edx, dword ptr     //y
      mov esi, dword ptr //point line of img orig

      mov dl,byte ptr
      mov dword ptr ,edx



      mov ebx, dword ptr     // g
      mov ecx, dword ptr
      mov edx, dword ptr
      mov esi, dword ptr

      mov al,byte ptr
      mov dword ptr ,edx


      mov ebx, dword ptr // b  
      mov eci, dword ptr  
      mov edx, dword ptr    
      mov esi, dword ptr

      mov cl,byte ptr
      mov dword ptr ,edx


imul      eax,dword ptr ,299          // How I do without imul???
imul      edx,dword ptr ,587
add      eax,edx
imul      ecx,dword ptr ,114
add      eax,ecx
mov      ecx,1000

idiv      ecx                                              // ???
mov      dword ptr ,eax



mov      al,byte ptr // ???
mov      edx,dword ptr
mov      ecx,dword ptr
mov      edx,dword ptr
mov      ecx,dword ptr
mov      byte ptr ,al


mov      al,byte ptr
mov      edx,dword ptr
mov      ecx,dword ptr
mov      edx,dword ptr
mov      ecx,dword ptr
mov      byte ptr ,al


mov      al,byte ptr
mov      edx,dword ptr
mov      ecx,dword ptr
mov      edx,dword ptr
mov      ecx,dword ptr
mov      byte ptr ,al



    add dword ptr , 3        //x+=3

      jmp f2_cicle_x_start
  f2_cicle_x_end:
      inc dword ptr         //y++
      jmp f2_cicle_y_start
    f2_cicle_y_end:
     

}


Regards,
Popovych
Posted on 2007-01-07 08:13:46 by Popovych
Most C compilers will stack the arguments in reverse order.

Redo the code using the following addresses:

ebp+20  height
ebp+16  width
ebp+12  porig
ebp+8      pdest
ebp-4      x
ebp-8      y
Posted on 2007-01-09 21:50:32 by tenkey
I think the problem is not this... :sad:
Posted on 2007-01-10 04:42:24 by Popovych
What's the exact problem?
Posted on 2007-01-12 11:58:16 by roticv