Shadow Chasm
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
« 上一篇: Recall of Fresher Year B-Assembly-mood 下一篇: Template of Assembly For Editplus »
OwnWaterloo @ 2006-06-24 20:26

收获蛮大的 对程序能从更底层去理解了
具体到每个寄存器的操作 程序流程的跳转 变量的定义空间分配and so on

register变量 — 快速 但是不能定义太多或者太大的register
;remark1 的那几句相当于 for (register int i=stdyear;i<year;i++){} 吧

中断 — 程序运行时交还控制给用户的方式之一(唯一吗?) 输入输出时都要利用中断
;remark2 一个典型的getchar()
;remark3 printf("%s",s);?

通过标号控制流程 — 学Pascal C/C++时喜欢用goto的朋友有福气啦~  你们应该能更快适应和掌握汇编的 循环 分支设计……
真的是无出不在………
简单总结一下(以后补……)

变量生存期 — 遗憾的是这个项目stack用的太少了 不然对这个的理解会更深的
;remark4 唯一用到stack的地方了… 相当于调用函数时把原函数的变量压栈“保护现场”吧?
汇编的函数还得多写点才行 嗯嗯~

附上code.....
格式不齐也太浪费资源 不过还是有好处的
自从nga down掉回档后让我明白 技术帖不要仅保存链接!!

data segment

year dw 0
month dw 0
day dw 0
stdyear equ 1900
status db 0
count dw 0
SY  db 0dh,0ah,'Pleas input the year $'
SM  db 0dh,0ah,'Month? $'
SD  db 0dh,0ah,'And the day $'
SMon db 0dh,0ah,'It is Monday$'
STue db 0dh,0ah,'It is Tuesday$'
SWed db 0dh,0ah,'It is Wednesday$'
SThu db 0dh,0ah,'It is Thursday$'
SFri db 0dh,0ah,'It is Friday$'
SSat db 0dh,0ah,'It is Saturday$'
SSun db 0dh,0ah,'It is Sunday$'
SAsk db 0dh,0ah,'Do you want to inquire one more time? (y/n)$'
SBye db 0dh,0ah,'Thx for using~$'
SHello db 0dh,0ah,'This small program will tell what day is it',0dh,0ah,'Let`s begin$'

data ends

stack segment
dw 10 dup(0)
stack ends

Show macro addr    ;remark3 printf("%s",s)
 lea dx,addr
 mov ah,9h
 int 21h
endm

code segment

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

main proc far

start: push ds
 sub ax,ax
 push ax
 mov ax,data
 mov ds,ax
 mov ax,stack
 mov ss,ax

 Show Shello
step_begin:
 sub ax,ax
 mov year,ax
 mov month,ax
 mov day,ax
 mov count,ax

 Show SY
inputY: 
 mov ax,0   ;remark2 getchar()
 mov ah,1   ;remark2
 int 21H    ;remark2
 cmp al,0DH
 je IM1
 sub al,30h
 mov bl,al
 mov bh,0
 mov ax,10D
 mul year
 mov year,ax
 add year,bx
 jmp inputY

IM1: Show SM
inputM: mov ax,0
 mov ah,1
 int 21H
 cmp al,0DH
 je ID1
 sub al,30h
 mov bl,al
 mov bh,0
 mov ax,10D
 mul month
 mov month,ax
 add month,bx
 jmp inputM

ID1: Show SD
inputD: mov ax,0
 mov ah,1
 int 21H
 cmp al,0DH
 je step_year
 sub al,30h
 mov bl,al
 mov bh,0
 mov ax,10D
 mul day
 mov day,ax
 add day,bx
 jmp inputD

step_year:
 mov ax,stdyear   ;remark1 for ("register int i=stdyear";i<year;i++){}

year_add:    ;remark1 for (register int i=stdyear;i<year;i++){""}
 cmp ax,year   ;remark1 for (register int i=stdyear;"i<year";i++){}
 jae step_month
 push ax    ;remark4
 call far ptr leapyear
 cmp status,1
 je y_leap
 add count,365
 jmp y_not_leap

y_leap:
 add count,366

y_not_leap:
 mov ax,count
 mov dx,0
 mov cx,7
 div cx
 mov count,dx
 pop ax    ;remark4
 inc ax    ;remark1 for (register int i=stdyear;i<year;"i++"){}
 jmp year_add   ;remark1 for (register int i=stdyear;i<year;i++){""}

step_month:
 dec month
 cmp month,0
 je step_day
 cmp month,1
 je month1
 cmp month,2
 je month2
 cmp month,3
 je month3
 cmp month,4
 je month4
 cmp month,5
 je month5
 cmp month,6
 je month6
 cmp month,7
 je month7
 cmp month,8
 je month8
 cmp month,9
 je month9
 cmp month,10
 je month10
 cmp month,11
 je month11

month1: add count,31
 jmp step_day
month2: add count,59
 jmp month_leap
month3: add count,90
 jmp month_leap
month4: add count,120
 jmp month_leap
month5: add count,151
 jmp month_leap
month6: add count,181
 jmp month_leap
month7: add count,212
 jmp month_leap
month8: add count,243
 jmp month_leap
month9: add count,273
 jmp month_leap
month10:
 add count,304
 jmp month_leap

month11:
 add count,334
 
month_leap:
 call far ptr leapyear
 cmp status,1
 jne step_day
 inc count

step_day:
 mov cx,day
 add count,cx
 mov dx,0
 mov ax,count
 mov cx,7
 div cx
 mov count,dx

 cmp count,0
 je w0
 cmp count,1
 je w1
 cmp count,2
 je w2
 cmp count,3
 je w3
 cmp count,4
 je w4
 cmp count,5
 je w5
 cmp count,6
 je w6
 
w0: Show SSun
 jmp ask
w1: Show SMon
 jmp ask
w2: Show STue
 jmp ask
w3: Show SWed
 jmp ask
w4: Show SThu
 jmp ask
w5: Show SFri
 jmp ask
w6: Show SSat
 jmp ask

ask:
 Show SAsk
 mov ax,0
 mov ah,1
 int 21H
 cmp al,'y'
 je step_begin
 cmp al,'Y'
 je step_begin
 cmp al,'n'
 je step_end
 cmp al,'N'
 je step_end
 jmp ask

step_end:
 Show SBye
      mov ax ,4c00h
      int 21h
      ret

main endp

leapyear proc far
 mov status,0
 mov bx,ax
 mov dx,0
 mov cx,400
 div cx
 cmp dx,0
 je leap
 mov ax,bx
 mov dx,0
 mov cx,4
 div cx
 cmp dx,0
 jne exit
 mov ax,bx
 mov dx,0
 mov cx,100
 div cx
 cmp dx,0
 je exit
leap: mov status,1
exit: ret
leapyear endp

code ends
END start





评论 / 个人网页 / 扔小纸条
* 昵称

已经注册过? 请登录

新用户请先注册 以便能显示头像及追踪评论回复

Email
网址
* 评论
表情
 


 

分类小组论坛
杂谈 , 娱乐、八卦 , 文学、艺术 , 体育 , 旅游、同城 , 象牙塔 , 情感 , 时尚、生活 , 星座 , 科技

请注意遵守中华人民共和国法律法规, 如威胁到本站生存, 将依法向有关部门报告, 同时本站的相关记录可能成为对您不利的证据.

相关法律法规
全国人大常委会关于维护互联网安全的决定
中华人民共和国计算机信息系统安全保护条例
中华人民共和国计算机信息网络国际联网管理暂行规定
计算机信息网络国际联网安全保护管理办法
计算机信息系统国际联网保密管理规定

分类
· 所有网志 (22)
· 随便乱涂 (10)
· Fresher Year B (8)
· For English (1)
· Data (1)
· 2006 (2)
链接
· 我的歪酷 非非共享界
站内搜索
订阅 RSS
0003458
歪酷博客