加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

汇编程序——实现键盘输入两个两位数相加并显示结果

(2010-11-23 18:48:28)
标签:

汇编

程序

源代码

相加

教育

分类: 学习

    历经N个小时的不懈努力,终于完成了该汇编程序——实现键盘输入两个两位数相加并显示结果。程序的功能很简单,编写的过程也并不复杂,但是代码还真不少。这过程当中着实让我体会到了汇编语言的低级啊,但是从中确实又学到了不少关于编程的一些重要思想方法。正如老师所言:以后我们用到汇编语言的机会可能很少很少,但是我们这门课程的主要目的在于进一步掌握和理解计算机工作的原理,并学会一些各种语言(包括高级和低级的语言)编程时通用的思想方法。

    下面分享汇编程序源代码  注:程序源代码大部分参照老师的讲解内容,也可能有网络内容,请尊重原创。

 

data segment
    indata dw 2 dup(?)
    outdata dw 1 dup(?)
    notein1 db 'please input the first decimal number(0-99):$'
    notein2 db 'please input the second decimal number(0-99):$'
    noteout db 'the result of addition is:$'
    notewarn db 'warning:wrong char!$'
    noteagain db 'please input again:$'
data ends
show macro addr
    mov ah,9h
    lea dx,addr
    int 21h
endm

code segment
    assume  cs:code,ds:data,es:data
main proc far
    start:
 push ds
 sub ax,ax
 push ax
 mov ax,data
 mov ds,ax
 mov es,ax
 show notein1
 call crlf
 call deci_input
 mov indata,bx
 call crlf
 show notein2
 call crlf
 call deci_input
 mov indata+2,bx
 call crlf
 mov ax,bx
 add ax,indata
 mov outdata,ax
 show noteout
 call crlf
 call deci_output
      ret
main endp

deci_input proc near
 mov bx,0
    newchar:mov ah,1
 int 21h
 cmp al,0dh
 jz exit
 sub al,30h
 jl noteerr
 cmp al,9d
 jg noteerr
 cbw
 xchg ax,bx
 mov cx,10d
 mul cx
 xchg ax,bx
 add bx,ax
 jmp newchar
    noteerr:call crlf
 show notewarn
 call crlf
 show noteagain
 jmp newchar
    exit:    ret
deci_input endp

deci_output proc near
 mov bx,outdata
 mov cl,100d
 mov ax,bx
 div cl
 mov bl,ah
 mov dl,al
 add dl,30h
 call dispchar
 mov ax,0
 mov al,bl
 cbw
 mov cl,10d
 div cl
 mov bl,ah
 mov dl,al
 add dl,30h
 call dispchar
 mov dl,bl
 add dl,30h
 call dispchar
 ret
deci_output endp

crlf proc near
 mov dl,0ah
 call dispchar
 mov dl,0dh
 call dispchar
 ret
crlf endp

dispchar proc near
 mov ah,2h
 int 21h
 ret
dispchar endp

code ends
    end start
 
 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有