编写汇编程序,要求从键盘输入两个两位数并求它们的乘积,并在屏幕上显示输出计算结果
我写也一段程序,但不能显示结果,HELP ME!
stacks segment stack
dw 64 dup(?)
data segment
mess1 db 'input a number ',0ah,0dh, '$ '
mess2 db 'input another number ',0ah,0dh, '$ '
mess3 db 'the result is ',0ah,0dh, '$ '
data1 dw ?
data2 dw ?
result dw ?
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov bx,0
mov dx,offset mess1
mov ah,09h
int 21h
input1:
mov ah,01h
int 21h
cmp al,0dh
jz write1
sub al,30h
mov cl,al
mov ch,00
mov ax,bx
mov bx,0ah
mul bx
mov bx,ax
add bx,cx
jmp input1
write1:
mov data1,bx
mov bx,0
mov ah,2 ;回车换行。
mov dl,0ah
int 21h
mov dl,0dh
int 21h
mov dx,offset mess2
mov ah,09h
int 21h
input2:
mov ah,01h
int 21h
cmp al,0dh
jz write2
sub al,30h
mov cl,al
mov ch,00
mov ax,bx
mov bx,0ah
mul bx
mov bx,ax
add bx,cx
jmp input2
write2:
mov ax,bx
mul bx
mov data2,ax
mov ah,2 ;回车换行。
mov dl,0ah
int 21h
mov dl,0dh
int 21h
mov dx,offset mess3
mov ah,09h
int 21h
mov di,00h
mov di,offset data2
mov dx,[di]
mov ah,02h
int 21h
mov ax,data
add ax,14h
mov data2,ax
inc di
mov dx,[di]
mov ah,02h
int 21h
mov ah,4ch
int 21h
code ends
end start
------解决方案--------------------------------------------------------
程序有点乱,我把它稍微修改一下,可以编译通过,结果也正确:
.MODEL SMALL
STACKS SEGMENT STACK
DW 64 DUP(?)
STACKS ENDS
DATA SEGMENT
MESS1 DB 'input a number ',0AH,0DH, '$ '
MESS2 DB 'input another number ',0AH,0DH, '$ '
MESS3 DB 'the result is ',0AH,0DH, '$ '
DATA1 DW ?
DATA2 DW ?
RESULT DB 4 DUP (0),0AH,0DH, '$ '
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:STACKS
START:
MOV AX,DATA
MOV DS,AX
MOV BX,0
MOV DX,OFFSET MESS1
MOV AH,09H
INT 21H
MOV AH,01H
INT 21H
AND AX,0FH
MOV BL,0AH
MUL BL
MOV CX,AX
MOV AH,01H
INT 21H