eternuii 2014-10-22 02:59 采纳率: 0%
浏览 3225

【求助】怎么判断一个数是否是偶数啊 div 指令怎么用 T^T

想要的效果是
Enter the number:
(用户input一个数后)
Output:
The number is odd 或者 The number is even

下面是我写的,加粗的是不会写的部分,div指令看王爽的《汇编语言》不甚明白 ps:我看书上说被除数是32位的,要把高16位放在dx里,低16位放在ax里,我这个input是int类型,应该是32位的吧?那我怎么把这个数的高十六位和低十六位分别赋给dx和ax啊,汇编要怎么写呢?pps:余数是在dx中吧,我拿dx和0比较来判断奇偶没问题吧?

// test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
char message1[] = "Enter the number: ";
char message2[] = "The number is even. ";
char message3[] = "The number is odd.";
char format[] = "%d";

 int input;

 _asm{
     lea eax, message1;
     push eax;
     call printf;
     add esp, 4;

     lea eax, input;
     push eax;
     lea eax, format;
     push eax;
     call scanf;
     add esp, 8;

      **mov eax, input;
     mov bx, 2; //判断input是否为偶
     div bx;
     cmp dx, 0;
     je label1;
     jne label2;** 

label1:lea eax, message2;
push eax;
call printf;
add esp, 4;

label2:lea, eax, message3;
push eax;
call printf;
add esp, 4;
}
return 0;
}

  • 写回答

1条回答 默认 最新

  • freedamjustice 2014-10-22 03:03
    关注

    和1进行位与&,结果是1就是奇数,是0就是偶数

    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制