Chinaunix首页 | 论坛 | 博客
  • 博客访问: 328273
  • 博文数量: 79
  • 博客积分: 2466
  • 博客等级: 大尉
  • 技术积分: 880
  • 用 户 组: 普通用户
  • 注册时间: 2006-02-07 16:47
文章分类

全部博文(79)

文章存档

2014年(3)

2012年(7)

2011年(14)

2010年(2)

2009年(2)

2008年(2)

2007年(18)

2006年(31)

分类: C/C++

2007-05-19 19:03:08

汇编语言实现:

xor ebx, ebx
cmp eax, [input1]
setg bl           ; if (eax > [input1]) set bl = 0x01;
neg ebx           ; neg 1 = 0xffffffff. neg is the arithmatich 'negate' operation
mov ecx, ebx
and ecx, eax
not ebx           ; not 0 = 0xffffffff, not 0xffffffff = 0
and ebx, [input1]
or ecx, ebx

C语言实现完全就是从汇编翻译过来的,^_^

#include
int
main() {
  int a, b, flag, result;
  scanf("%d %d", &a, &b);
  flag = a > b;
  flag = -flag;
  result = flag & a;
  result |= ((~flag) & b);
  printf("\nbigger one: %d\n", result);
  return 0;
}

阅读(2473) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~