当前位置: 代码迷 >> 汇编语言 >> 汇编程序解决方法
  详细解决方案

汇编程序解决方法

热度:5184   发布时间:2013-02-26 00:00:00.0
汇编程序
题目为 输入一组字数据 , 求和后 以10进制输出( 可能溢出 要考虑到双字才行)

------解决方案--------------------------------------------------------
DATA SEGMENT
NUM DB 30,?,30 DUP(?)
SUM DD 0
MESG DB 'Input your num:(end with #)',0DH,0AH,'$'
DATA ENDS
STACK SEGMENT PARA STACK 'STACK'
DW 10 DUP(?)
STACK ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV DX,OFFSET MESG
MOV AH,09H
INT 21H
MOV DX,OFFSET NUM
MOV AH,0AH
INT 21H
MOV SI,OFFSET NUM+2
MOV CL,NUM+1
MOV CH,0
MOV BH,0
MOV DH,0
L3: MOV AX,0
L1: MOV BX,10
MUL BX
MOV DL,[SI]
SUB DL,30H 
ADD AX,DX
MOV BL,[SI+1]
INC SI
CMP BL,' '
JE L2
CMP BL,'#'
JE L2
LOOP L1
L2:
MOV DX,WORD PTR SUM
ADD AX,DX
MOV WORD PTR SUM,AX
MOV DX,WORD PTR SUM+2
ADC DX,0
MOV WORD PTR SUM+2,DX
INC SI
CMP BL,'#'
JE L4
DEC CX
JNE L3 
L4:
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DL,0DH
INT 21H
MOV DX,0
MOV CX,0
MOV AX,WORD PTR SUM+2
MOV BX,10
L5:
DIV BX
ADD DX,30H
PUSH DX
INC CX
MOV DX,0
CMP AX,0
JE L7
JMP L5
 
L7: 
POP DX
;ADD DL,30H
MOV AH,02H
INT 21H
LOOP L7

MOV AH,4CH
INT 21H
 CODE ENDS
END START
  相关解决方案