/ int bcdsub( / unsigned char *x1, / unsigned char *y1, / unsigned char *z1, / int c) / z1 = x1 - y1; / return final borrow or zero / if the return value is zero, then the result may be used / if the return value is 15, then swap the operands and try again / y1 must be at least c+1 bytes long / output array should be initialized to zeros before this is called / / Copyright John Moyer 1996 / permission is granted to use this for any purpose provided proper / credit is given to the author #ident "@(#)bcdsub.s 1.6 5/24/96 11:29:56" .file "bcdsub.s" .text .globl bcdsub .align 4 bcdsub: pushl %ebp movl %esp,%ebp pushl %ecx pushl %edx pushl %esi pushl %edi movl 16(%ebp),%edi movl 12(%ebp),%edx movl 8(%ebp),%esi movl 20(%ebp),%ecx xorl %eax,%eax movb (%esi),%al clc / clear carry myloop: incl %esi movb $0,%ah / use movb so that carry flag is not changed sbbb (%edx),%al / .byte 0x3f aas movb %al,(%edi) incl %edx incl %edi movb (%esi),%al loop myloop movb %ah,%al / save the final borrow popl %edi popl %esi popl %edx popl %ecx andl $0x0f,%eax leave ret .type bcdsub,@function .size bcdsub,.-bcdsub