I'm a beginner in assembly and I'm having difficulties with an exercise where I have to implement a filter of an image encoded in BMP in assembly. Each pixel is encoded on 24 bits so that, each component (blue, green, red) of the pixel is encoded on 8 bits. To represent the image I have an array of uint8_t
. For example the first pixel of the array is represented by array[0] (blue component), array[1] (green component) and array[2] (red component). What I have to do is to implement a filter that finds the mean of the 3 components of each pixel and fix the value of each component to that mean. My problem is then to calculate that mean. The signature of the function is extern size_t filter(const uint8_t* in_buf, uint32_t w, uint32_t h);
Here is my code.
.text
.global filter
filter:
push %ebp
mov %esp, %ebp
xor %ecx, %ecx #increment variable for_width = 0
for_width:
xor %ebx, %ebx #increment variable for_height = 0
for_height:
calcul_offset: # find the position of the position of an i, j pixel
mov %ecx, %esi
mov %ebx, %edx
imull $3, %esi
imull $3, %edx
imull 12(%ebp), %edx #12(%ebp) = width of the image
add %edx, %esi
calcul_mean:
mov %esi, %edx
add 8(%esi), %edx
add 16(%esi), %edx #edx contains the sum of the 3 components
change_pixel: # supposing edx contains the mean of the 3 components
mov 8(%ebp), %esi #8(%ebp) is the adress of the array
mov %edx, (%esi) #blue component
mov %edx, 8(%esi) #green component
mov %edx, 16(%esi) #red component
#here is my problem - to divide %esi by 3
inc %ebx
cmp 16(%ebp), %ebx #16(%ebp) = height of the image
jle for_height
inc %ecx
cmp 12(%ebp), %ecx
jle for_width
# retour
ret
Note that my code is not complete yet and that i m just trying to figure out the division at the moment.
Thank you ! Alexis