求一个汇编语言程序,给一个年份,判断是否为润年?
data segment infon db 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 endsstack segment stack db 200 dup(0)stack endscode segme...全部
data segment infon db 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 endsstack segment stack db 200 dup(0)stack endscode 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,0Ah ;0AH功能调用从键盘接受字符串到内存的输入缓存区 int 21h xor ch,ch ;ch要清0,否则循环次数有误。
mov cl, buf 1 ;把输入的字符的个数保存在cl中 call datacate ;调用datacate子程序 call ifyears ;调用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 21hdatacate proc near ;把表示年份的字符串转换为数值 push cx dec cx lea si,buf 2 tt1: inc si loop tt1 pop cx mov ax,1 l1: push ax mov dh,30h mov bx,10 mov dl,[si] ;字符减去30H后即可转换为十六进制数 sub dl,dh xor dh,dh mul dx add w,ax pop ax mul bx dec si loop l1 retdatacate endpifyears proc near push bx push cx push dx mov ax,w mov dx,0 mov bx,100 div bx cmp dx,0 je next xor dx,dx mov ax,w mov bx,4 div bx cmp dx,0 je lab2 jmp lab1 next: xor dx,dx mov ax,w mov bx,400 div bx cmp dx,0 je lab2 jmp lab1 lab1: clc jmp lab3 lab2: stc lab3: pop dx pop cx pop bx retifyears endpcode ends end start赞同8| 评论。
收起