| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 7003 人关注过本帖, 1 人收藏
标题:发一个自己写的超长汇编程序,实现输入日期,输出该日期是这一年的第几天和 ...
只看楼主 加入收藏
chenwei435
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:2
帖 子:322
专家分:1611
注 册:2010-11-28
结帖率:92.31%
收藏(1)
已结贴  问题点数:50 回复次数:7 
发一个自己写的超长汇编程序,实现输入日期,输出该日期是这一年的第几天和星期几
程序代码:
;数据段,定义了indate用来存放输入的ascll,定义的date用来年,月,日,
;存放ascll转换成数形式的年,月,日,和星期,weeks也存放了星期,其他的就是一些输出的字符串
DATAS SEGMENT
    indate db 11,11 dup (?),'$'
    date0 db 13,10,'$'
    dates dw 5 dup (?)
    date1 db ' is the ','$'
    day dw 4 dup (?)
    date2 db 'th day of this year and ','$'
    weekdate1 db 'Monday','$'
    weekdate2 db 'Tuesday','$'
    weekdate3 db 'Wednesday','$'
    weekdate4 db 'Thursday','$'
    weekdate5 db 'Friday','$'
    weekdate6 db 'Saturday','$'
    weekdate7 db 'Sunday','$'
    weeks dw 1 dup (?)
    error db 13,10,'Error date! Input a correct date:','$'
    input db 'please input a date between 1949 and 2049(yyyy.mm.dd):','$'
DATAS ENDS


;数据段开始

CODES SEGMENT
    ASSUME CS:CODES,DS:DATAS
   
    main proc far     ;main程序
   
START:

        MOV AX,DATAS   ;载入数据段
       MOV DS,AX
       
        mov dx,offset input  ;调用21h的06号功能实现字符串输入
        mov ah,09h
        int 21h
        call  inputsub
        call  dealmon
    call  dealsub

       
    mov   dx,offset date0      ;最终的输出
    mov   ah,09h
    int   21h
    mov   dx,offset indate
    mov   ah,09h
    int   21h
    mov   dx,offset date1
    mov   ah,09h
    int   21h
    mov   dx,offset day
    mov   ah,09h
    int   21h
    mov   dx,offset date2
    mov   ah,09h
    int   21h
       
    call  dealweek         ;输出最后一个字符串,即星期
       
    mov   dx,offset date0    ;输入正确日期结束后,再次输入时,回车换行
    mov   ah,09h
    int   21h
        jmp start          ;  再次开始

    main endp               ;main程序结束

   
    inputsub proc near   ;实现输入的子程序,转换为数据
        lea dx,indate
        mov ah,0ah
        int 21h
       
        mov di,2
        mov cx,11
        loop1:
            mov al,[indate+di]             ;处理字符串的开始两位
            mov [indate-2+di],al
            inc di
            loop loop1
            mov al,'$'                   ;处理掉回车换行
            mov [indate+10],al
       
        mov al,byte ptr [indate]     ;把年的ascll转换成数
        cbw
        sub ax,30h
        mov bx,1000d
        mul bx
        mov [dates],ax
        mov al,byte ptr [indate+1]
        cbw
        sub ax,30h
        mov bx,100d
        mul bx
        add [dates],ax
        mov al,byte ptr [indate+2]
        cbw
        sub ax,30h
        mov bx,10d
        mul bx
        add [dates],ax
        mov al,byte ptr [indate+3]
        cbw
        sub ax,30h
        add [dates],ax
        mov dx,[dates]       
        cmp dx,1949
        jb error1
        cmp dx,2049
        ja error1
           
           
        mov al,byte ptr [indate+5]           ;把月的ascll转换成数
        cbw
        sub ax,30h
        mov bx,10d
        mul bx
        mov [dates+2],ax
        mov al,byte ptr [indate+6]
        cbw
        sub ax,30h
        add [dates+2],ax
        mov dx,[dates+2]
        cmp dx,1
        jb error1
        cmp dx,12
        ja error1
           
           
        mov al,byte ptr [indate+8]              ;把日的ascll转换成数
        cbw
        sub ax,30h
        mov bx,10d
        mul bx
        mov [dates+4],ax
        mov al,byte ptr [indate+9]
        cbw
        sub ax,30h
        add [dates+4],ax
        mov dx,[dates+4]
        cmp dx,1
        jb error1
        cmp dx,30
        ja error1
           
        jmp exiti
           
                                   
    error1:     mov dx,offset error         ;如果错误,则输出错误信息,并且重新输入
            mov ah,9h
            int 21h
            call inputsub
    exiti:           
            ret
    inputsub endp
           
    dealsub proc near       ;实现处理星期处理的子程序,用蔡勒公式处理
        mov ax,[dates+2]            ;判断月份是不是小于3
        cmp ax,3
        jae  above3

        mov ax,0                ;不是小于3就不需要转换成上一年的13,14月处理
        mov ax,[dates]
        dec ax
        mov dx,0       
        mov bx,100d
        div bx
        mov [dates+6],dx
        mov ax,dx
        mov dx,0
        mov bx,4
        div bx
        add [dates+6],ax
        mov ax,[dates+2]
        add ax,12
        inc ax
        mov bx,26d
        mul bx
        mov dx,0
        mov bx,10d
        div bx
        add [dates+6],ax
        mov ax,[dates+4]
        add [dates+6],ax
        mov ax,[dates+6]
        dec ax
        mov [dates+6],ax
        mov dx,[dates]
        cmp dx,1999d
        jb below3
        mov dx,35
        sub [dates+6],dx
        jmp exit
    below3:
        mov dx,34
        sub [dates+6],dx
        jmp exit       
    above3:                     ;月份大于3的情况
        mov ax,0
        mov ax,[dates]
        mov dx,0       
        mov bx,100d
        div bx
        mov [dates+6],dx
        mov ax,dx
        mov dx,0
        mov bx,4
        div bx
        add [dates+6],ax
        mov ax,[dates+2]
        inc ax
        mov bx,26d
        mul bx
        mov dx,0
        mov bx,10d
        div bx
        add [dates+6],ax
        mov ax,[dates+4]
        add [dates+6],ax
        mov ax,[dates+6]
        dec ax
        mov [dates+6],ax
        mov dx,[dates]
        cmp dx,2000d
        jb below
        mov dx,35
        sub [dates+6],dx
        jmp exit
    below:
        mov dx,34
        sub [dates+6],dx
    exit:                            ;用蔡勒公式算出来的分正数和负数分开处理
        mov ax,[dates+6]
        cmp ax,0
        js signd
        mov dx,0
        mov bx,7d
        div bx
        mov [dates+6],dx
        mov [weeks],dx
        jmp exitddd
    signd:   
            neg ax   
        mov dx,0
        mov bx,7d
        div bx
        sub dx,7
        neg dx
        mov [dates+6],dx
        mov [weeks],dx       
    exitddd:
            ret
    dealsub endp 

    dealmon proc near   ;处理在多少天,分闰年和非闰年分开处理
        mov  ax,[dates]
        mov  dx,0
        mov  bx,4
        div  bx
        cmp  dx ,0
        jnz  nleap
        mov  ax,[dates]
        mov  dx,0
        mov  bx,100d
        div  bx
        cmp  dx,0
        jnz  leap
        jz  again
    again:  mov  ax,[dates]
        mov  dx,0
        mov  bx,400
        div  bx
        cmp  dx,0
        jz   leap
        jnz  nleap
    leap:                         ;是闰年,继续判断月份
        mov  [dates+8],0
        mov  dx,[dates+2]
        cmp  dx,12d
        jz   leap12
        mov  dx,[dates+2]
        cmp  dx,11d
        jz   leap11
        mov  dx,[dates+2]
        cmp  dx,10d
        jz   leap10
        mov  dx,[dates+2]
        cmp  dx,9d
        jz   leap9
        mov  dx,[dates+2]
        cmp  dx,8d
        jz   leap8
        mov  dx,[dates+2]
        cmp  dx,7d
        jz   leap7
        mov  dx,[dates+2]
        cmp  dx,6d
        jz   leap6
        mov  dx,[dates+2]
        cmp  dx,5d
        jz   leap5
        mov  dx,[dates+2]
        cmp  dx,4d
        jz   leap4
        mov  dx,[dates+2]
        cmp  dx,3d
        jz   leap3
        mov  dx,[dates+2]
        cmp  dx,2d
        jz   leap2
        mov  dx,[dates+2]
        cmp  dx,1d
        jz   leap1
       leap12:
        mov  [dates+8],335
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd
       leap11:
        mov  [dates+8],305
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd
       leap10:
        mov  [dates+8],274
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd
       leap9:
        mov  [dates+8],244
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd
       leap8:
        mov  [dates+8],213
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd
       leap7:
        mov  [dates+8],182
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd
       leap6:
        mov  [dates+8],152
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd
       leap5:
        mov  [dates+8],121
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd

       leap4:
        mov  [dates+8],91
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd
       leap3:
        mov  [dates+8],60
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd      
       leap2:
        mov  [dates+8],31
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd
       leap1:
        mov  [dates+8],0
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd   
    nleap:  mov  [dates+8],0       ;不是闰年
        mov  dx,[dates+2]
        cmp  dx,12d
        jz   nleap12
        mov  dx,[dates+2]
        cmp  dx,11d
        jz   nleap11
        mov  dx,[dates+2]
        cmp  dx,10d
        jz   nleap10
        mov  dx,[dates+2]
        cmp  dx,9d
        jz   nleap9
        mov  dx,[dates+2]
        cmp  dx,8d
        jz   nleap8
        mov  dx,[dates+2]
        cmp  dx,7d
        jz   nleap7
        mov  dx,[dates+2]
        cmp  dx,6d
        jz   nleap6
        mov  dx,[dates+2]
        cmp  dx,5d
        jz   nleap5
        mov  dx,[dates+2]
        cmp  dx,4d
        jz   nleap4
        mov  dx,[dates+2]
        cmp  dx,3d
        jz   nleap3
        mov  dx,[dates+2]
        cmp  dx,2d
        jz   nleap2
        mov  dx,[dates+2]
        cmp  dx,1d
        jz   nleap1
       nleap12:
        mov  [dates+8],334
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd
       nleap11:
        mov  [dates+8],304
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd
       nleap10:
        mov  [dates+8],273
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd
       nleap9:
        mov  [dates+8],243
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd
       nleap8:
        mov  [dates+8],212
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd
       nleap7:
        mov  [dates+8],181
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd
       nleap6:
        mov  [dates+8],151
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd
       nleap5:
        mov  [dates+8],120
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd
       nleap4:
        mov  [dates+8],90
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd
       nleap3:
        mov  [dates+8],59
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd      
       nleap2:
        mov  [dates+8],31
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd
       nleap1:
        mov  [dates+8],0
        mov  ax,[dates+4]
        add  [dates+8],ax
        jmp  exitd
    exitd:  mov  ax,[dates+8]      ;判断 第几天 ,有三种情况,大于100,大于10和小于10,需要不同的空间来存放ascll
        mov  dx,ax
        cmp  dx,100d
        jae  exitd1
        cmp  dx,10d
        jae  exitd2
        jb   exitd3
    exitd1: mov  ax,[dates+8]      
        mov  dx,0
        mov  bx,100d
        div  bx
        mov  [day],ax
        mov  ax,dx
        mov  dx,0
        mov  bx,10d
        div  bx
        mov  [day+2],ax
        mov  [day+4],dx
        mov  ax,'$'
        mov  [day+6],ax
        mov  cx,30h
        add  [day],cx
        add  [day+2],cx
        add  [day+4],cx
        jmp  exitdddo
    exitd2: mov  ax,[dates+8]
        mov  dx,0
        mov  bx,10d
        div  bx
        mov  [day],ax
        mov  [day+2],dx
        mov  ax,'$'
        mov  [day+4],ax
        mov  cx,30h
        add  [day],cx
        add  [day+2],cx
        jmp  exitdddo
    exitd3:
                mov  ax,[dates+8]
        mov  [day],ax
        mov  ax,'$'
        mov  [day+2],ax
        mov  cx,30h
        add  [day],cx
        jmp  exitdddo
    exitdddo:
        ret
    dealmon endp 

    dealweek proc near              ;把存放在week的星期最终的星期输出
        mov ax,[weeks]
        cmp ax,6
        jz weeks6
        mov ax,[weeks]
        cmp ax,5
        jz weeks5
        mov ax,[weeks]
        cmp ax,4
        jz weeks4
        mov ax,[weeks]
        cmp ax,3
        jz weeks3
        mov ax,[weeks]
        cmp ax,2
        jz weeks2
        mov ax,[weeks]
        cmp ax,1
        jz weeks1
        mov ax,[weeks]
        cmp ax,0
        jz weeks0
    weeks6:
        mov dx,offset weekdate6
        mov ah,09h
        int 21h
        jmp exitw
    weeks5:
        mov dx,offset weekdate5
        mov ah,09h
        int 21h
        jmp exitw
    weeks4:
        mov dx,offset weekdate4
        mov ah,09h
        int 21h
        jmp exitw
    weeks3:
        mov dx,offset weekdate3
        mov ah,09h
        int 21h
        jmp exitw
    weeks2:
        mov dx,offset weekdate2
        mov ah,09h
        int 21h
        jmp exitw
    weeks1:
        mov dx,offset weekdate1
        mov ah,09h
        int 21h
        jmp exitw
    weeks0:
        mov dx,offset weekdate7
        mov ah,09h
        int 21h
        jmp exitw
    exitw:
        ret
    dealweek endp  
    


CODES ENDS                  ;数据段结束
    END START


asm.rar (2.59 KB)
2011-11-08 13:28
李尸尸
Rank: 2
等 级:论坛游民
威 望:1
帖 子:30
专家分:77
注 册:2011-11-7
收藏
得分:13 
牛了哇  新手膜拜
2011-11-08 22:44
zjsxwc
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:1
帖 子:252
专家分:601
注 册:2011-1-20
收藏
得分:13 
16位汇编,用了DOS中断来显示,楼主敢不用DOS中断吗,直接对显卡操作,这样可以写的更长点

The tools I recommended:
GUI: CSharp(VS), QT;    Core Code: Plain C (Tiny C Compiler);    Web: Python, JavaScript;    Android: Java;    Embedded System: ASM&C (Linux)
2011-11-09 12:09
Alar30
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:10
帖 子:988
专家分:1627
注 册:2009-9-8
收藏
得分:13 
来膜拜一下。。
俺现在写代码就头疼。。。
2011-11-14 10:25
zaixuexi
Rank: 12Rank: 12Rank: 12
来 自:上海
等 级:火箭侠
威 望:8
帖 子:858
专家分:3233
注 册:2010-12-1
收藏
得分:13 
我一般都拆成几个文件,好维护

技术问题,请不要以短消息方式提问
2011-11-15 11:34
ch775914568
Rank: 2
等 级:论坛游民
帖 子:15
专家分:10
注 册:2012-10-29
收藏
得分:0 
求大神多加注释   新手看不懂。。。
2012-10-31 20:33
ch775914568
Rank: 2
等 级:论坛游民
帖 子:15
专家分:10
注 册:2012-10-29
收藏
得分:0 
楼主 我用dosbox实现出现16个错误
图片附件: 游客没有浏览图片的权限,请 登录注册
2012-11-04 21:32
香菜爱obm
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2015-10-9
收藏
得分:0 
有错误呀,怎么改呀,求高手求教
2015-10-13 09:04
快速回复:发一个自己写的超长汇编程序,实现输入日期,输出该日期是这一年的第几 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028688 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved