Hello, I tried to convert below code, but I couldn't.. What is wrong?

void invert(unsigned char *image, int width, int height){
         for(int i=0;i<width*height;i++)
               image[i]=255-image[i];
}
---------------------ASM---------
invert PROC
	push ebp					; save ebp register
	mov ebp,esp					; get current stack pointer
	
	mov esi,[ebp+8]				; get first parameter
	mov eax,[ebp+12]			; get second parameter
	mov ebx,[ebp+16]			; get third parameter
	mul ebx						; eax=eax * ebx
	mov ecx,eax					; get image size
	dec ecx
	mov al,255
	
	L1:
		sub al,[esi]			; al=al-image[i]
		mov [esi],al			; image[i]=al
		inc esi
		loop L1
	
	pop ebp						; restore ebp
	ret							; return to caller
	
invert ENDP

--------------------------------------------------
please help me....thanks...

Hello, I tried to convert below code, but I couldn't..

Actually that's not correct, you did convert it and a reasonably good job too, the only problem is it's not working as expected.

1. You only initialize AL to -1 (255 or 0FFH) once and then inside your loop it's modified.

L1:    push    eax
         sub      al, [esi]
         stosb
         pop     eax
         loop    L1

Note: mov [esi], al and then incrementing ESI is not wrong, it's just STOSB saves code space.

pls tel d 8951 assembly code for follwing c program......

#include<reg51.h>
void delay(unsigned int time);
void gate_open();
void gate_close();
unsigned char Rx,coin;

int k=0;
sbit L1=P0^3;                                        //LED connected

sbit E_M=P0^0;                          //L293D enable
sbit L293_A=P0^1;                           //L293D INPUT1
sbit L293_B=P0^2;                           //L293D INPUT2

sbit C=P1^0;                                       //coin arrived 
sbit S1=P1^1;                                              //BOTTOM SENSOR
sbit S2=P1^2;                                      //TOP SENSOR


void main()                             //main function
{
    unsigned int i=0,j=0;   

    P0=0X00;                            
    P1=0XFF;                        // setting port1 as input port
    P2=0X00;                            
    P3=0X00;                            



while(1)
    {
        while(S1==0);                                  //wait till a vehicle arrives
         delay(100);        
        if(S2==1)
        {
            coin=2;           //heavy vehicle
        }
        else
        {
            coin=1;           //light vehicle
        }
        L1=1;

        while(coin > 0)                  //count coins
        {
        while(C==1);
        delay(100);
        while(C==0);
        coin--; 
        }
        L1=0;
        delay(100);
        gate_open();
        delay(400);
        gate_close();

    }


}

void delay(unsigned int time)                      //delay   time=t ms
{
    unsigned int i,j;
    for(i=0;i<time;i++)
        for(j=0;j<1275;j++);
}

    void gate_open()
{
    L293_A=1;
    L293_B=0;
    E_M=1;
       delay(400);
    E_M=0;  
    L293_A=0;
    L293_B=0;


}
void gate_close()
{
    L293_A=0;
    L293_B=1;
    E_M=1;
       delay(400);
    E_M=0;  
    L293_A=0;
    L293_B=0;

}
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.