## Assembly Code Share

Moderators: None (Apply to moderate this forum)
Number of posts: 685

This Forum Only

Help to finish a code Posted by fabricemoreira on 20 Sept 2007 at 6:23 AM
someone can help me transforming this code on c++ to assembley:
void muda_pixeis_c_f3(int altura, int largura, Byte *porig[], Byte *pdest[])
{
// Bin
int x, y, ml, ma, tx, factor;
ml = largura / 2;
ma = altura / 2;
for(y = 0; y < altura; y++){
for(x = 0; x < largura * 3; x+=3){
tx = x / 3;
factor = 1000 - 1000 * ((tx-ml)*(tx-ml) + (y-ma)*(y-ma)) / (ml*ml + ma*ma);
pdest[y][x]= (porig[y][x] * factor) / 1000;
pdest[y][x+1]= (porig[y][x+1] * factor) / 1000;
pdest[y][x+2]= (porig[y][x+2] * factor) / 1000;
}
}
}

i have already start, i only need to someone finish the code
void muda_pixeis_asm_f3(int altura, int largura, Byte *porig[], Byte *pdest[])
{
/*************************************
ebp+20	pdest
ebp+16	porig
ebp+12	largura
ebp+8 	altura
ebp-4    x
ebp-8    y

ebp-12   ml
ebp-16   ma
ebp-20   tx
ebp-24   factor
*************************************/

asm
{
sub esp, 24                                  //int x, y, ml, ma, tx, factor

//declaraç?o de variaveis
X EQU dword ptr [ebp-4]
Y EQU dword ptr [ebp-8]
ML EQU dword ptr [ebp-12]
MA EQU dword ptr [ebp-16]
TX EQU dword ptr [ebp-20]
FACTOR EQU dword ptr [ebp-24]

mov eax, dword ptr [ebp+12]
mov ecx, 2
cdq
idiv ecx
mov ML, eax                                 // ml = largura / 2;

mov eax, dword ptr [ebp+8]
mov ecx, 2
cdq
idiv ecx
mov MA, eax                                 // ma = altura / 2;

mov Y, 0                                     //y = 0
f3_ciclo_y_inicio:
mov eax, Y
cmp eax, dword ptr [ebp+8]                   //y < altura ?
jge f3_ciclo_y_fim

mov X, 0                                     //x=0
f3_ciclo_x_inicio:
mov eax, dword ptr [ebp+12]
add eax, dword ptr [ebp+12]                  //largura * 3
cmp X, eax                                   //x < largura * 3 ?

.......(i need the rest od the code)

add X, 3                                     //x = x + 3
jmp f3_ciclo_x_inicio

f3_ciclo_x_fim:
inc Y                                        //y++
jmp f3_ciclo_y_inicio

f3_ciclo_y_fim:
add esp, 24                                  //liberta espaço x, y, ml, ma, tx, factor
}

}
Re: Help to finish a code Posted by IDK on 20 Sept 2007 at 8:03 AM
Noone will write code for you, but if you ask specific questions, you might get what you want.
Re: Help to finish a code Posted by fabricemoreira on 20 Sept 2007 at 9:51 AM
i have already all the code done, but it's not working and i don't known where is the problem

CODE:
void muda_pixeis_asm_f3(int altura, int largura, Byte *porig[], Byte *pdest[])
{
/*************************************
ebp+20	pdest
ebp+16	porig
ebp+12	largura
ebp+8 	altura
ebp-4    x
ebp-8    y

ebp-12   ml
ebp-16   ma
ebp-20   tx
ebp-24   factor
*************************************/

asm
{
sub esp, 24                                  //int x, y, ml, ma, tx, factor

//declaraç?o de variaveis
X EQU dword ptr [ebp-4]
Y EQU dword ptr [ebp-8]
ML EQU dword ptr [ebp-12]
MA EQU dword ptr [ebp-16]
TX EQU dword ptr [ebp-20]
FACTOR EQU dword ptr [ebp-24]

mov eax, dword ptr [ebp+12]
mov ecx, 2
cdq
idiv ecx
mov ML, eax                                 // ml = largura / 2;

mov eax, dword ptr [ebp+8]
mov ecx, 2
cdq
idiv ecx
mov MA, eax                                 // ma = altura / 2;

mov Y, 0                                     //y = 0
f3_ciclo_y_inicio:
mov eax, Y
cmp eax, dword ptr [ebp+8]                   //y < altura ?
jge f3_ciclo_y_fim

mov X, 0                                     //x=0
f3_ciclo_x_inicio:
mov eax, dword ptr [ebp+12]
add eax, dword ptr [ebp+12]                  //largura * 3
cmp X, eax                                   //x < largura * 3 ?
jge f3_ciclo_x_fim

//**

mov eax, X
mov ecx, 3
cdq
idiv ecx
mov TX, eax                                 // tx = x / 3;

sub eax, ML
mul eax
mov TX, eax                                 //TX passa a (tx-ml)*(tx-ml)

mov eax, Y
sub eax, MA
mul eax                                     //eax -> (y-ma)*(y-ma)

add TX, eax                                 //TX passa a (tx-ml)*(tx-ml) + (y-ma)*(y-ma)

mov eax, TX
mov ecx, 1000
mul ecx
mov TX, eax                                 //TX passa a 1000 * ((tx-ml)*(tx-ml) + (y-ma)*(y-ma))

mov eax, ML
mul ML
mov ecx, eax                                 //ecx passa a (ml * ml)

mov eax, MA
mul MA                                       //eax passa a (ma * ma)

add ecx, eax                                 //ecx -> (ml*ml + ma*ma)

mov eax, TX
cdq
idiv ecx
mov TX, eax                                 // tx = 1000 * ((tx-ml)*(tx-ml) + (y-ma)*(y-ma)) / (ml*ml + ma*ma)

mov eax, 1000
sub eax, TX                                 //eax -> 1000 - 1000 * ((tx-ml)*(tx-ml) + (y-ma)*(y-ma)) / (ml*ml + ma*ma)

mov FACTOR, eax

mov ebx, dword ptr [ebp+16]                  //porig
mov ecx, X                                   //x
mov edx, Y                                   //y
mov esi, dword ptr [ebx+4*edx]               //point linha da img orig
mov al, byte ptr [esi+ecx]                   //porig [y][x] -> al

mul FACTOR
mov ecx, 1000
cdq
idiv ecx

mov ebx, dword ptr [ebp+20]                  //pdest
mov ecx, X                                   //x
mov edx, Y                                   //y
mov edi, dword ptr [ebx+4*edx]               //point linha da img dest
mov byte ptr [edi+ecx], al                 //pdest[y][x]= (porig[y][x] * factor) / 1000

mov ebx, dword ptr [ebp+16]                  //porig
mov ecx, X                                   //x
inc ecx                                      //x+1
mov edx, Y                                   //y
mov esi, dword ptr [ebx+4*edx]               //point linha da img orig
mov al, byte ptr [esi+ecx]                   //porig [y][x+1] -> al

mul FACTOR
mov ecx, 1000
cdq
idiv ecx

mov ebx, dword ptr [ebp+20]                  //pdest
mov ecx, X                                   //x
inc ecx                                       //x+1
mov edx, Y                                   //y
mov edi, dword ptr [ebx+4*edx]               //point linha da img dest
mov byte ptr [edi+ecx], al                 //pdest[y][x+1]= (porig[y][x+1] * factor) / 1000

mov ebx, dword ptr [ebp+16]                  //porig
mov ecx, X                                   //x
mov edx, Y                                   //y
mov esi, dword ptr [ebx+4*edx]               //point linha da img orig
mov al, byte ptr [esi+ecx]                   //porig [y][x+2] -> al

mul FACTOR
mov ecx, 1000
cdq
idiv ecx

mov ebx, dword ptr [ebp+20]                  //pdest
mov ecx, X                                   //x
mov edx, Y                                   //y
mov edi, dword ptr [ebx+4*edx]               //point linha da img dest
mov byte ptr [edi+ecx], al                 //pdest[y][x+2]= (porig[y][x+2] * factor) / 1000

//**

add X, 3                                     //x = x + 3
jmp f3_ciclo_x_inicio

f3_ciclo_x_fim:
inc Y                                        //y++
jmp f3_ciclo_y_inicio

f3_ciclo_y_fim:
add esp, 24                                  //liberta espaço x, y, ml, ma, tx, factor
}

}

Re: Help to finish a code Posted by MT2002 on 20 Sept 2007 at 11:34 AM
Ugh. Please dont crosspost, it is against the forum rules.

As I said in the other post, why not just disassemble the C++ routine, and work with that? Have you tried using a debugger?

Also, please post code using [code]*code here*[/code] tags:
*code here*

Thanks.

[.:EvolutionEngine][.:MicroOS Operating System][Website :: OS Development Series]
Re: Help to finish a code Posted by BitByBit_Thor on 21 Sept 2007 at 3:34 AM
: i have already all the code done, but it's not working and i don't
: known where is the problem
:

Hey,

First off I would like to apologise for not responding to your mail.
I think I might know something that's not right:
mov ebx, dword ptr [ebp+16]                  //porig
mov ecx, X                                   //x
mov edx, Y                                   //y
mov esi, dword ptr [ebx+4*edx]               //point linha da img orig
mov al, byte ptr [esi+ecx]                   //porig [y][x] -> al

// EAX here is FACTOR except for AL which is as above
// You need to XOR EAX, EAX before moving to AL (in the part above)
mul FACTOR
mov ecx, 1000
//cdq Unnecesary, because MUL fills EDX:EAX
idiv ecx

Best Regards,
Richard

The way I see it... Well, it's all pretty blurry

## Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic