:)我正在努力学习一种汇编语言,主要是打印字符串的顺序。这就是我所拥有的!!
.model small
.stack 100h
.DATA
;DISPLAYS
msgquestion db 13,10, "Addition or Subtraction?: $ "
msgfirst db 13,10, "Enter first number : $" ;MESSAGE first
msgsecond db "Enter second Number : $" ;MESSAGE second
msgSum db 13,10, "The result is : $"
msgDif db 13,10, "The result is : $"
msgterminator db 13,10, "X to END: $"
.code
;START OF CODE
start:
mov ax,@data
mov ds, ax
lea dx, msgfirst ;Displays first
mov ah, 09h
int 21h
mov bx, 0
start1:
mov ah, 01h
int 21h
cmp al,0dh
je next1
mov ah,0
sub al,30h
push ax
mov ax,10d
mul bx
pop bx
add bx,ax
jmp start1
next1:
push bx
lea dx,msgsecond ;DISPLAYS MESSAGE 'second'
mov ah,09h
int 21h
mov bx,0
start2:
mov ah,01h
int 21h
cmp al,0dh
je QUESTION
mov ah,0
sub al,30h
push ax
mov ax,10d
mul bx
pop bx
add bx,ax
jmp start2
QUESTION:
lea dx, msgquestion
mov ah, 09h
int 21h
mov ah, 01h
int 21h
cmp al,'+'
je adding
cmp al,'-'
je subtracting
cmp al,'x'
mov ah, 4ch
int 21h
jmp break
TERMINATOR:
lea dx, msgterminator
mov ah, 09h
int 21h
mov ah, 01h
int 21h
cmp al,'+'
je adding
cmp al,'-'
je subtracting
cmp al,'x'
mov ah, 4ch
int 21h
jmp break
adding:
pop ax
add ax,bx
push ax
lea dx,msgSum
mov ah,09h
int 21h
pop ax
mov cx,0
mov dx,0
mov bx,10d
jmp break
subtracting:
pop ax
sub ax,bx
push ax
lea dx,msgDif
mov ah,09h
int 21h
pop ax
mov cx,0
mov dx,0
mov bx,10d
break:
div bx
push dx
mov dx,0
inc cx
or ax,ax
jne break
ans:
pop dx
add dl,30h
mov ah,02h
int 21h
loop ans
jmp TERMINATOR
end start
;END OF THE PROGRAM
我想首先显示加法和减法QUESTION。 还请建议我做的任何其他错误!我真的很感激,谢谢你! < 3
答案 0 :(得分:0)
我从您的问题中了解到,您希望先显示Addition or subtraction:
,然后输入您的号码&执行计算。那么解决方案很简单。代码一开始,您就可以询问用户添加或减去的问题,然后将保存的值(从al
)存储到变量中。稍后您可以使用该保存的值进行比较。
这是新代码
.model small
.stack 100h
.DATA
;DISPLAYS
msgquestion db 13,10, "Addition or Subtraction?: $ "
msgfirst db 13,10, "Enter first number : $" ;MESSAGE first
msgsecond db "Enter second Number : $" ;MESSAGE second
msgSum db 13,10, "The result is : $"
msgDif db 13,10, "The result is : $"
msgterminator db 13,10, "X to END: $"
v1 db ?
.code
;START OF CODE
main proc
mov ax,@data
mov ds, ax
;//CHANGES MADE HERE
;//add or sub
lea dx, msgquestion
mov ah, 09h
int 21h
mov ah, 01h
int 21h
mov v1,al
;//END CHANGES
lea dx, msgfirst ;Displays first
mov ah, 09h
int 21h
mov bx, 0
start1:
mov ah, 01h
int 21h
cmp al,0dh
je next1
mov ah,0
sub al,30h
push ax
mov ax,10d
mul bx
pop bx
add bx,ax
jmp start1
next1:
push bx
lea dx,msgsecond ;DISPLAYS MESSAGE 'second'
mov ah,09h
int 21h
mov bx,0
start2:
mov ah,01h
int 21h
cmp al,0dh
je QUESTION
mov ah,0
sub al,30h
push ax
mov ax,10d
mul bx
pop bx
add bx,ax
jmp start2
QUESTION:
mov al,v1 ;will now move the value stored in v1 earlier into al for comparision
cmp al,'+'
je adding
cmp al,'-'
je subtracting
cmp al,'x'
mov ah, 4ch
int 21h
jmp break
TERMINATOR:
lea dx, msgterminator
mov ah, 09h
int 21h
mov ah, 01h
int 21h
cmp al,'+'
je adding
cmp al,'-'
je subtracting
cmp al,'x'
mov ah, 4ch
int 21h
jmp break
adding:
pop ax
add ax,bx
push ax
lea dx,msgSum
mov ah,09h
int 21h
pop ax
mov cx,0
mov dx,0
mov bx,10d
jmp break
subtracting:
pop ax
sub ax,bx
push ax
lea dx,msgDif
mov ah,09h
int 21h
pop ax
mov cx,0
mov dx,0
mov bx,10d
break:
div bx
push dx
mov dx,0
inc cx
or ax,ax
jne break
ans:
pop dx
add dl,30h
mov ah,02h
int 21h
loop ans
jmp TERMINATOR
main endp
end main