私はアセンブリの初心者です。アセンブリでBMPでエンコードされた画像のフィルタを実装する必要がある練習が難しいです。各ピクセルは24ビットで符号化されるので、ピクセルの各成分(青、緑、赤)は8ビットで符号化される。画像を表現するために、私はuint8_t
の配列を持っています。たとえば、配列の最初のピクセルは配列[0](青のコンポーネント)、配列[1](緑のコンポーネント)、および配列[2](赤のコンポーネント)で表されます。私がしなければならないことは、各ピクセルの3つのコンポーネントの平均を見つけ出し、その平均値に各コンポーネントの値を固定するフィルタを実装することです。私の問題はその平均を計算することです。関数のシグネチャはextern size_t filter(const uint8_t* in_buf, uint32_t w, uint32_t h);
です。これは私のコードです。アセンブリの3つの数字の平均
.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
私のコードはまだ完全ではなく、私はちょうどその時点で分裂を見つけようとしていることに注意してください。
ありがとうございました! Alexis
ありがとうございます!ちなみに、私のコードには、構文とレジスタの使用の点であなたに衝撃を与えるものがいくつかありますか? – Alexis
@Alexis私が気づいた唯一の他のものは 'calcul_mean:'の後の行でした。その行は 'mov(%esi)、edx'であるべきだと私は思う。さもなければ、コードは私によく見えましたが、あなたがそれを試すまであなたは知らないでしょう:) – user3386109