正文

初级汇编,减法2007-04-09 12:20:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/lingdlz/24724.html

分享到:

;---------------------------------------------------------;条件转移,溢出测试,简单减法,数制转换;--------------------------------------------------------- .model small data segment MAX dw 100 x dw 30 y dw 25 result dw ? msg_th db 'The x too high !$' msg_of db 'Overflow !$' rlt_asc db 10 dup(?) temp_asc db 10 dup(?) data ends code segment assume cs:code,ds:data ;---------------------------------------------------------;屏幕打印回车换行符,用到寄存器 ax,dx;---------------------------------------------------------macPutEnt macro  mov dl,0dh mov ah,02h int 21h mov dl,0ah mov ah,02h int 21h endm ;---------------------------------------------------------;屏幕输出一个字符 OPRCH,用到寄存器 dx;---------------------------------------------------------macPutChar macro OPRCH mov dl,OPRCH mov ah,02h int 21h endm ;---------------------------------------------------------;屏幕输出以 '$' 结尾的字符串,OPR为字符串变量;用到寄存器 ax,dx;---------------------------------------------------------macPutTxt macro OPR mov dx,offset OPR mov ah,09h int 21h endm ;---------------------------------------------------------;结束程序,回到 DOS,用到寄存器 ax,dx;---------------------------------------------------------macExit macro mov ah,4ch int 21h endm ;---------------------------------------------------------;将 ax 中的二进制转为十进制ASCALL 码(带符号数);结果存于 rlt_asc 中;---------------------------------------------------------bin_to_hec_asc proc far mov bx,0 test ax,8000h jz positive mov byte ptr rlt_asc[bx],'-' ;负数 inc bx neg axpositive: mov di,0 mov dl,10nextbh: div dl    ;字节操作 add ah,30h mov byte ptr temp_asc[di],ah inc di mov ah,0 cmp al,0 jnz nextbhnextinbh: dec di  js overbth mov al,byte ptr temp_asc[di] mov byte ptr rlt_asc[bx],al inc bx jmp nextinbhoverbth: mov byte ptr rlt_asc[bx],' ' inc bx mov byte ptr rlt_asc[bx],'$' retbin_to_hec_asc  endp ;---------------------------------------------------------;主过程;---------------------------------------------------------main proc far mov ax,data mov ds,ax  mov ax,x cmp ax,MAX jg too_high sub ax,y jo over_flow  mov result,ax  ;输出结果 mov ax,x call bin_to_hec_asc macPutTxt rlt_asc  macPutChar '-' macPutChar ' '  mov ax,y call bin_to_hec_asc macPutTxt rlt_asc  macPutChar '=' macPutChar ' ' mov ax,result call bin_to_hec_asc macPutTxt rlt_asc macPutEnt jmp exittoo_high: macPutTxt msg_th macPutEnt jmp exitover_flow: macPutTxt msg_of macPutEnt jmp exit exit: macExitmain endp code ends end main    

阅读(4087) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册