void Mask_1 - gcc汇编

本文深入探讨了使用 GCC 编译器进行汇编编程的细节,重点解析了函数 `Mask_1` 的实现过程,涵盖了从 C 代码到汇编转换的关键步骤,帮助读者理解底层指令和优化技巧。
摘要由CSDN通过智能技术生成
void Mask_1(unsigned char * const ptrDestBuffer, const unsigned char * const ptrSrcBuffer, int Width, int Height, int idLineAdd, int isLineAdd, int idPixelAdd, int isPixelAdd, int MaskColor)
{
 const int ld = idPixelAdd + 3;
 const int ls = isPixelAdd + 3;

 const unsigned char bmaskr = (unsigned char)MaskColor;
 const unsigned char bmaskb = (unsigned char)(MaskColor>>16);

 idPixelAdd += 2;
 isPixelAdd += 2;
 Width--;
 int i;

    register unsigned char *ptrDest = ptrDestBuffer;
    register const unsigned char *ptrSrc = ptrSrcBuffer;

    for (i = Height - 1; i >= 0; i--)
     {
      register int j = Width;
      do
       {
        j--;
        if (*ptrDest != bmaskr) //bmaskrgb[0]:Dest background color[blue part]
         {
          if (*ptrSrc != bmaskb) //bmaskb:Src background color[blue part]
           {
            *ptrDest = *ptrSrc;
            ptrDest++;
            ptrSrc++;
            *((unsigned short int *)(ptrDest)) = *((unsigned short int *)(ptrSrc));

            ptrDest += idPixelAdd;
            ptrSrc += isPixelAdd;
           }
          else
           {
            ptrDest += ld;
            ptrSrc += ls;
           }
         }
        else
         {
          *ptrDest = *ptrSrc;
          ptrDest++;
          ptrSrc++;
          *((unsigned short int *)(ptrDest)) = *((unsigned short int *)(ptrSrc));

          ptrDest += idPixelAdd;
          ptrSrc += isPixelAdd;
         }
       }while(j >= 0);

      ptrDest += idLineAdd;
      ptrSrc += isLineAdd;
     }
}
	pushl	%ebp
	movl	%esp, %ebp
	subl	$28, %esp
	movl	32(%ebp), %eax
	addl	$3, %eax
	movl	%eax, -4(%ebp)
	movl	36(%ebp), %eax
	addl	$3, %eax
	movl	%eax, -8(%ebp)
	movl	40(%ebp), %eax
	movb	%al, -9(%ebp)
	movl	40(%ebp), %eax
	sarl	$16, %eax
	movb	%al, -10(%ebp)
	leal	32(%ebp), %eax
	addl	$2, (%eax)
	leal	36(%ebp), %eax
	addl	$2, (%eax)
	leal	16(%ebp), %eax
	decl	(%eax)
	movl	8(%ebp), %eax
	movl	%eax, -20(%ebp)
	movl	12(%ebp), %edx
	movl	%edx, -24(%ebp)
	movl	20(%ebp), %eax
	decl	%eax
	movl	%eax, -16(%ebp)
L3:
	cmpl	$0, -16(%ebp)
	js	L2
	movl	16(%ebp), %eax
	movl	%eax, -28(%ebp)
L6:
	decl	-28(%ebp)
	movl	-20(%ebp), %edx
	movzbl	(%edx), %eax
	cmpb	-9(%ebp), %al
	je	L9
	movl	-24(%ebp), %edx
	movzbl	(%edx), %eax
	cmpb	-10(%ebp), %al
	je	L10
	movl	-24(%ebp), %edx
	movzbl	(%edx), %eax
	movl	-20(%ebp), %edx
	movb	%al, (%edx)
	incl	-20(%ebp)
	incl	-24(%ebp)
	movl	-24(%ebp), %edx
	movzwl	(%edx), %eax
	movl	-20(%ebp), %edx
	movw	%ax, (%edx)
	movl	32(%ebp), %eax
	addl	%eax, -20(%ebp)
	movl	36(%ebp), %edx
	addl	%edx, -24(%ebp)
	jmp	L8
L10:
	movl	-4(%ebp), %eax
	addl	%eax, -20(%ebp)
	movl	-8(%ebp), %edx
	addl	%edx, -24(%ebp)
	jmp	L8
L9:
	movl	-24(%ebp), %edx
	movzbl	(%edx), %eax
	movl	-20(%ebp), %edx
	movb	%al, (%edx)
	incl	-20(%ebp)
	incl	-24(%ebp)
	movl	-24(%ebp), %edx
	movzwl	(%edx), %eax
	movl	-20(%ebp), %edx
	movw	%ax, (%edx)
	movl	32(%ebp), %eax
	addl	%eax, -20(%ebp)
	movl	36(%ebp), %edx
	addl	%edx, -24(%ebp)
L8:
	cmpl	$0, -28(%ebp)
	js	L7
	jmp	L6
L7:
	movl	24(%ebp), %eax
	addl	%eax, -20(%ebp)
	movl	28(%ebp), %edx
	addl	%edx, -24(%ebp)
	leal	-16(%ebp), %eax
	decl	(%eax)
	jmp	L3
L2:
	leave
	ret

                                                

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值