程序需求:能被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 '%d',9,0
.code
main Proc
xor ecx,ecx
mov esi,2012
jmp testing
body:
mov eax,esi
mov ebx,4
cdq
div ebx
cmp edx,0
jne next

该博客介绍了如何用汇编语言编写程序,找出2012年至2099年间的所有闰年。程序通过判断年份能被4整除且不被100整除,或者能被400整除的条件,利用ESI作为年份计数器,ECX作为闰年计数器,并用DIV指令进行余数计算。博客展示了开发环境为Win10 + VS2017,同时给出了C语言和汇编语言的代码实现及运行结果。
1865

被折叠的 条评论
为什么被折叠?



