用汇编语言编写从键盘输入两个两位的十进制数,做加法运算,并显示结果。
发布网友
发布时间:2022-04-19 09:57
我来回答
共2个回答
热心网友
时间:2023-10-24 00:15
code segment
assume cs:code
org 100h
start:
jmp bbb
lfcr db 13,10,'$'
bbb:
push cs
pop ds
call inputnum
mov ah,9
lea dx,lfcr
int 21h
lea si,array
mov ch,0
mov cl,byte ptr[num]
mov ax,0
lp:
add ax,word ptr[si]
inc si
inc si
loop lp
; mov cl,byte ptr[num]
; div cl
call dispnum
mov ah,1
int 21h
mov ah,4ch
int 21h
dispnum proc near
; 将要显示的数据放入AL中
mov ah,0
mov cl,10
div cl
mov byte ptr[y+4],ah ;保存个位
mov ah,0
div cl
mov byte ptr[y+3],ah ;保存十位
mov ah,0
mov byte ptr[y+2],al ;保存百位
mov al,byte ptr[y+2]
add al,30h ;百位转ASC2
mov byte ptr[y+2],al
mov al,byte ptr[y+3]
add al,30h ;十位转ASC2
mov byte ptr[y+3],al
mov al,byte ptr[y+4]
add al,30h ;个位转ASC2
mov byte ptr[y+4],al
mov ah,9
lea dx,y
int 21h
ret
y db 10,13,0,0,0,'$'
dispnum endp
inputnum proc near
; 输入的数据以一个空格分隔,以回车符结束输入
lea di,array ;将数组第一个元素的有效地址置入DI
mov byte ptr[num],0
stin:
mov ax,0
push ax
again1:
mov ah,1
int 21h
mov byte ptr[char],al
cmp al,13
je line0
cmp al,' '
je line0
sub al,30h
mov ah,0
mov si,ax
pop ax
mov cl,10
mov ch,0
mul cx
add ax,si
push ax
jmp again1
line0:
pop ax
mov word ptr[di],ax
inc byte ptr[num]
cmp byte ptr[char],13
je stinend
inc di
inc di
jmp stin
stinend:
ret
array dw 100 p(0)
num db 0
char db ?
inputnum endp
code ends
end start
热心网友
时间:2023-10-24 00:15
;=================================
ASSUME CS:CODE, DS:DATA
DATA SEGMENT
MSG1 DB 13, 10, 'Please input number_1: $'
MSG2 DB 13, 10, 'Please input number_2: $'
CRLF DB 13, 10, '$'
NN DB ?, ?
MM DB ?
DATA ENDS
;---------------------------------
CODE SEGMENT
START:
MOV AX, DATA
MOV DS, AX
;-----------------------
LEA DX, MSG1
MOV AH, 9
INT 21H
CALL IN_CHAR
MOV MM, AL
LEA DX, MSG2
MOV AH, 9
INT 21H
CALL IN_CHAR
MOV NN, AL
LEA DX, CRLF
MOV AH, 9
INT 21H
MOV AL, MM
CALL OUT_NUM
MOV DL, '+'
MOV AH, 2
INT 21H
MOV AL, NN
CALL OUT_NUM
MOV DL, '='
MOV AH, 2
INT 21H
MOV AL, NN
ADD AL, MM
MOV AH, 0
ADC AH, 0
CALL OUT_1
EXIT:
MOV AH, 4CH
INT 21H ;返回DOS
;---------------------------------
IN_CHAR:
LEA BX, NN
MOV CX, 2
IN_1:
MOV AH, 1
INT 21H
CMP AL, '0'
JB IN_1
CMP AL, 'F'
JA IN_1
CMP AL, '9'
JBE _09
CMP AL, 'A'
JB IN_1
SUB AL, 7
_09:
SUB AL, 30H
MOV [BX], AL
INC BX
LOOP IN_1
XCHG AL, NN
MOV BL, 16
MUL BL
ADD AL, NN
RET
;---------------------------------
OUT_NUM:
MOV AH, 0
OUT_1:
MOV DX, 0
MOV BX, 100
DIV BX
XCHG AX, DX
CALL OUT_CHAR
MOV DX, 0
MOV BX, 10
DIV BX
XCHG AX, DX
CALL OUT_CHAR
MOV DL, AL
CALL OUT_CHAR
RET
;---------------------------------
OUT_CHAR:
PUSH AX
ADD DL, 30H
MOV AH, 2
INT 21H
POP AX
RET
;---------------------------------
CODE ENDS
END START
;=================================