【求助】怎么判断一个数是否是偶数啊 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;
}