当前位置:编程学习 > 汇编语言 >>

把这个汇编语言逐句翻译下

data segment temp dw ? data ends decihex segment assume cs:decihex,ds:data main proc far nexts: call decibin mov temp,bx call decibin mov ax,temp add bx,ax call hexibin call crlf call binihex call crlf jmp nexts main endp hexibin proc near mov ax,bx mov cx,1h xor bx,bx loop2:mov dl,10d div dl mov dl,ah xor ah,ah cbw mov temp,ax xor ax,ax mov al,dl cbw mul cx add bx,ax mov ax,cx mov dx,10h mul dx mov cx,ax mov ax,temp cmp ax,0d je exit2 jne loop2 exit2: ret hexibin endp binihex proc near mov ch,4 rotate: mov cl,4 rol bx,cl mov al,bl and al,0fh add al,30h cmp al,3ah jl printit add al, 7h printit: mov dl, al mov ah, 2 int 21h dec ch jnz rotate ret binihex endp decibin proc near mov bx,0 newchar:mov ah,1 int 21h sub al,30h jl exit cbw xchg ax,bx mov cx,10d mul cx xchg ax,bx add bx,ax jmp newchar exit: ret decibin endp crlf proc near mov dl,0dh mov ah,2 int 21h mov dl,0ah mov ah,2 int 21h ret crlf endp decihex ends end main
追问:那你能不能写一个简单的汇编语言就是键盘输入的十进制加法结果输出也是十进制,也逐句翻译一下
答案:这是一个并不十分规范的汇编程序
其功能是对输入的两个十进制数求和,并显示结果。程序没有按正常方式返回,但可以用CTRL+C结束。
“逐句翻译”实在没有必要,简要说明如下:
程序中含一个主程序(main proc far)和4个子程序(hexibin proc near ;binihex proc near ;decibin proc near;crlf proc near)

data segment   		;数据段
  temp dw ?  		;定义一个字,保存输入的第一个数
data ends  

decihex segment  	;代码段
assume cs:decihex,ds:data  
  main proc far  	;主程序开始
nexts:  
  call decibin  	;调用输入子程序,输入第一个加数,结果在BX中
  mov temp,bx  		;保存输入的第一个数	
  call decibin  	;调用输入子程序,输入第二个加数,结果在BX中
  mov ax,temp  		;将第一个加数放入AX
  add bx,ax  		;将两个数相加,结果在BX中
  call hexibin  	;调用将16进制数转换成10进制表示的数子程序
  call crlf  		;调用回车换行子程序
  call binihex  	;调用输出子程序
  call crlf  		;调用回车换行子程序
  jmp nexts  		;继续做下一个加法。。。
  main endp  		;主程序结束
;=====================
  hexibin proc near  	;将和转换成16进制表示的10进制数,如:13+24=37 在BX中表示的和为25(H),通过该子程序调用后,BX=0037(H). 该子程序主要算法是除10取余,但代

码太繁琐。。。 晕!
  mov ax,bx  
  mov cx,1h  
  xor bx,bx  
loop2:mov dl,10d  
  div dl  

  mov dl,ah  
  xor ah,ah  
  cbw  
  mov temp,ax  

  xor ax,ax  
  mov al,dl  
  cbw  
  mul cx  
  add bx,ax  

  mov ax,cx  
  mov dx,10h  
  mul dx  
  mov cx,ax  

  mov ax,temp  
  cmp ax,0d  
  je exit2  
  jne loop2  
exit2:  
  ret  
hexibin endp  
;=====================
binihex proc near  	;输出子程序。将BX中16进制表示的10进制数按10进制位逐位输出。 假如:BX=1234H
  mov ch,4  		;循环数4次
rotate: mov cl,4  	;移位数
  rol bx,cl  		;BX循环左移4位,BX:1234H ==>> 2341H		
  mov al,bl  		;将BL送AL,即:将41H送AL
  and al,0fh   		;只保留AL低4位 即:AL=01H
  add al,30h  		;转换成ASCII码以便输出 AL=31H
  cmp al,3ah  
  jl printit  
  add al, 7h  
printit: mov dl, al  
  mov ah, 2  		;调用DOS 2号功能输出一个字符 ,4次循环依次输出1 2 3 4
  int 21h  
  dec ch  		;减一次循环计数
  jnz rotate		;转循环
  ret
 binihex endp
;======================
decibin proc near	;输入子程序,输入的最终数保存在BX中
  mov bx,0		;置BX初值位0
newchar:mov ah,1	;调用DOS 1号功能输入一个字符,输入的结果在AL中
  int 21h
  sub al,30h		;将输入的ASCII码转换成数字
  jl exit		;如果输入字符的ASCII码小于“0”则直接返回(主程序),如:"+ - / " 空格 等字符
  cbw			;将AL的8位值扩展到16位的AX
  xchg ax,bx		;将AX与BX交换,交换的目的是需将已输入的数(在BX中,且初值为0)进位(乘以10),而执行乘法时要用到AX寄存器
  mov cx,10d		;执行BX*10 结果在 DX:AX中
  mul cx
  xchg ax,bx		;此指令完全多余!
  add bx,ax		;将乘以10以后的值再加上这次的数。 比如:第一次输入2,第二次输入8,结果是2*10+8=18;若再输入3,则结果是18*10+3=183.
  jmp newchar		;输入下一个字符
exit: ret
decibin endp
;===================
crlf proc near		;回车换行子程序(很简单)
  mov dl,0dh
  mov ah,2
  int 21h
  mov dl,0ah
  mov ah,2
  int 21h
  ret
crlf endp
;====================
decihex ends
  end main
其他:数据段
  临时dw吗?
  数据结束
  decihex段
  假定cs:decihex,ds:数据
  主要过程远
  nexts:
  叫decibin
  mov临时雇员、bx
  叫decibin
  mov斧,临时
  添加bx、斧
  叫hexibin
  叫crlf
  叫binihex
  叫crlf
  nexts该科通过就业选配计划
  主要endp
  附近hexibin触发
  mov斧,bx
  mov cx、1 h
  xor bx、bx
  loop2:mov dl、10 d
  师dl
  
  mov黎宇光,呵呵
  xor呀,
  生化
  mov临时雇员、斧
  
  xor斧,ax
  mov铝、dl
  生化
  cx度 

上一个:一道计算机组成原理题, 汇编指令MOV AX,[1010H],对应的机器指令编码为048B1010H,其中AX为寄存器寻址
下一个:求 int 3 这条汇编指令的解释?

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,