汇编语言程序设计:[2]判断闰年程序

2025-10-02 10:30:58

1、打开masm汇编编译程序,新建一个masm源文件脚本。

DATAS SEGMENT

    ;此处输入数据段代码  

DATAS ENDS

STACKS SEGMENT

    ;此处输入堆栈段代码

STACKS ENDS

CODES SEGMENT

    ASSUME CS:CODES,DS:DATAS,SS:STACKS

START:

    MOV AX,DATAS

    MOV DS,AX

    ;此处输入代码段代码

    MOV AH,4CH

    INT 21H

CODES ENDS

    END START

汇编语言程序设计:[2]判断闰年程序

汇编语言程序设计:[2]判断闰年程序

2、在正文中输入我们的程序代码,并将文件命名为testleap.asm

data segment    ;定义数据段

    infon db 0dh,0ah,'xiaobo leap test Designed by 1wangxiaobo@163.com',0dh,0ah,'Please input a year: $'

    Y db 0dh,0ah,'This is a leap year! $'

    N db 0dh,0ah,'This is not a leap year! $'

    w dw 0

    buf db 8

        db ?

        db 8 dup(?)

data ends

stack segment stack

    db 200 dup(0)

stack ends

code segment

          assume ds:data,ss:stack,cs:code

    start:mov ax,data

          mov ds,ax

          

          lea dx,infon  ;在屏幕上显示提示信息

          mov ah,9

          int 21h

          lea dx,buf    ;从键盘输入年份字符串

          mov ah,10

          int 21h

          

          mov cl, [buf+1]

          lea di,buf+2

          call datacate

          call ifyears

          jc a1

          

          lea dx,n

          mov ah,9

          int 21h

          jmp exit

    a1:   lea dx,y

          mov ah,9

          int 21h

    exit: mov ah,4ch

          int 21h

       

 datacate PROC near

          push cx;                                                       

          dec cx

          lea si,buf+2

     tt1: inc si

          loop tt1

          ;lea si,cx[di]

          pop cx

     

      

          mov dh,30h

          mov bl,10

          mov ax,1

      l1: push ax

          sub  byte ptr  [si],dh

          mul  byte ptr [si]

          add w,ax

          pop ax

          mul bl

          dec si

          loop l1

          ret

 datacate  ENDP 

   ifyears proc near

           push  bx

           push  cx

           push  dx

           mov ax,w

           mov   cx,ax

           mov  dx,0

           mov  bx,4

           div  bx

           cmp  dx,0

           jnz  lab1

           mov   ax,cx

           mov  bx,100

           div  bx

           cmp dx,0

           jnz  lab2

           mov  ax,cx

           mov bx,400

           div  bx

           cmp  dx,0

           jz  lab2

     lab1: clc

           jmp lab3

     lab2: stc

     lab3: pop  dx

           pop  cx

           pop  bx

           ret

   ifyears endp

code ends

   end start

      

汇编语言程序设计:[2]判断闰年程序

3、运行我们编辑的文件,按提示输入 例 四位数字 1988  就会显示This is a leap year!表示为 闰年 如果不是显示This is not a leap year! 就是闰年

xiaobo leap test Designed by 1wangxiaobo@163.com

Please input a year: 1988

This is a leap year!

             Press any key to continue

汇编语言程序设计:[2]判断闰年程序

汇编语言程序设计:[2]判断闰年程序

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢