程序需求:能被4整除但不能被100整除,或者年被400整除的年份是闰年。编程写一个完整的程序,求出2012年~2099年中的所有闰年年份,把它们存放在数组Lyear中并输出到屏幕上。
编程思路:汇编中ESI用来做年份计数器,ECX用来做闰年个数计数器,用DIV指令来求余数。
开发环境
Win10 + VS2017
C语言代码实现如下:
#include <stdio.h>
int main()
{
printf("Leap year is follow:\n");
for (int i = 2012; i < 2100; i++)
{
if ((i % 4 == 0 && i % 100 != 0) || (i % 400 == 0))
printf("%d\t",i);
}
return 0;
}
汇编语言代码实现如下:
INCLUDELIB kernel32.lib
INCLUDELIB ucrt.lib
INCLUDELIB legacy_stdio_definitions.lib
.386
.model flat,stdcall
ExitProcess PROTO,
dwExitCode:DWORD
printf PROTO C : dword,:vararg
scanf PROTO C : dword,:vararg
.data
Lyear dword 25 dup(0)
msg byte 'Leap year is follow:',10,0
format byte '%