Write a X86 Assembly code for this function This function ta
Write a X86 Assembly code for this function:
This function takes in a square sized grayscale image and applies thresholding on each pixel:
void imageThresholding(unsigned char* image, int dim, unsigned char threshold)
Solution
void imageThresholding(unsigned char* image, int dim) {
__asm {
push ebx;
push edi;
push esi;
mov eax, image
mov edi, 0
BEGIN_FOR_ROW:
cmp edi, dim
jge END_FOR_ROW
mov esi, 0
BEGIN_FOR_COL:
cmp esi, dim
jge END_FOR_COL
mov ebx, 0 //Transfer row to ebx
mov edx, 0 //Multiply row by dim (add row to row dim times)
BEGIN_FOR_MUL:
cmp edx, dim
jge END_FOR_MUL
add ebx, edi
inc edx
jmp BEGIN_FOR_MUL
END_FOR_MUL:
add ebx, esi
xor edx, edx
mov dl, [eax + ebx]
mov cl, 0x80
and cl, dl
cmp cl, 0x00
jne IF_HIGHER
xor edx, edx //set to Min
jmp CONT
IF_HIGHER:
or edx, 0xFFFFFFFF
CONT:
mov [eax + ebx], dl
inc esi
jmp BEGIN_FOR_COL
END_FOR_COL:
inc edi
jmp BEGIN_FOR_ROW
END_FOR_ROW:
mov image, eax
pop esi;
pop edi;
pop ebx;
}
}

