我想解决一个等式-2[-3(x-2y)+ 2y/2]
并在命令行界面上显示答案,给定用户输入X和Y的值。有没有办法在8位寄存器之间执行操作和一个16位寄存器?
例如MOV AX,AL。我遇到问题,因为寄存器在MUL
指令后每次都在增长。我曾尝试(X-2y)
,现在遇到问题将-3
与结果相乘!
这是我的代码:
.model small
.stack 100h
.data
open db 'Please enter value between 0 - 9 below:',13,10,'$'
req1 db 'Enter the value for X:',13,10,'$'
req2 db 'Enter the value for Y:',13,10,'$'
ans1 db 'After Multiplying Y by 2, we get: $'
ans2 db 'After Subtracting the result from X, we get: $'
ans3 db 'After multiplying the result by -3, we get: $'
ans db 'After Adding the fifth number from the result, we get: $'
var1 dw ?
var2 db ?
var3 db ?
var4 db ?
var5 db ?
ans11 dw ?
ans22 dw ?
ans33 dd ?
.code
main proc
mov ax,@data
mov ds,ax
mov dx,OFFSET open ;copies the starting address into the dx register.
mov ah,9h ;calling DOS sub program for displaying a character.
int 21h ;returning controlto the operating system.
mov dx,OFFSET req1
mov ah,9h
int 21h
mov ah,1h
int 21h
sub ah,'0'
mov var1,ax
mov dl,13d
mov ah,2h
int 21h
mov dl,10d
mov ah,2h
int 21h
mov dx,OFFSET req2 ;loading the start address of the variable req2 into the DX register.
mov ah,9h ;dos sub program for displaying a string.
int 21h ;dos interrupt to display the string on the screen
mov ah,1h ;prompts some one to enter a character from the keyboard.
int 21h ; captures a character from the keyboard and stores it in the AL register.
sub al,'0' ;stripping off the ASCII from AL to get the Actual Integer Value.
mov var2,al ; storing the integer value in the variable var2.
mov dl,13d
mov ah,2h
int 21h
mov dl,10d
mov ah,2h
int 21h
;**************
mov dx,OFFSET ans1
mov ah,9h
int 21h
mov ax,0
mov bx,0
mov al,var2
mov bl,2
mul bx
mov ans11,ax
aam
add ah,30h
add al,30h
mov cx,ax
mov dl,ch
mov ah,2h
int 21h
mov dl,cl
mov ah,2h
int 21h
mov dl,13d
mov ah,2h
int 21h
mov dl,10d
mov ah,2h
int 21h
;***************
mov dx,offset ans2
mov ah,9h
int 21h
mov ax,0
mov cx,0
mov dx,var1
mov cx,ans11
sub dx,cx
mov ans22,dx
mov ax,dx
aaa
add ah,30h
add al,30h
mov bx,ax
mov dl,bh
mov ah,2h
int 21h
mov dl,bl
mov ah,2h
int 21h
mov dl,13d
mov ah,2h
int 21h
mov dl,10d
mov ah,2h
int 21h
;******************
mov dx,offset ans3
mov ah,9h
int 21h
mov ax,0
mov bx,0
mov ax,ans22
mov bx,-3
imul bx
mov ans11,edx:eax
aam
add ah,30h
add al,30h
mov ecx,edx
mov ebx,ecx
mov ah,2h
int 21h
mov edx,eax
mov ah,2h
int 21h
mov dl,13d
mov ah,2h
int 21h
mov dl,10d
mov ah,2h
int 21h
mov ax,4c00H
int 21h
;******************
main endp
end main