我应该做两个项目。第一个
a
、b
和 c
是字节,第二个是 double 类型。a-(b-c:2)
。
我已经成功做到了(
double
类型我认为):
.model small
.stack 100h
.data
a db 0
b db 0
c db 0
result db ?
message1 db, "Equation: a-(b-c:2) a=$"
message2 db, "b=$" ;<=========
message3 db, "c=$" ;<========= LINEBREAK
message4 db, "Result=$"
.code
start: mov ax, data
mov ds,ax
mov ax, seg message1 ;get a and save to a variable
mov ds,ax
mov dx,offset message 1
mov ah, 9h
int 21h
mov ah, 1h
int 21h
sub al,30h ;converting to real number
mov a,al
mov ax, seg message2 ;get b and save to a variable
mov ds,ax
mov dx,offset message2
mov ah, 9h
int 21h
mov ah, 1h
int 21h
sub al,30h ;converting to real number
mov b,al
mov ax, seg message3 ;get c and save to a variable
mov ds,ax
mov dx,offset message3
mov ah, 9h
int 21h
mov ah, 1h
int 21h
sub al,30h ; converting to real numebr
mov c,al
要在计算机程序中求解方程,就像在其他地方一样,您需要遵循代数规则:
*
和/
位于+
和-
对于表达式
a-(b-c:2)
,可归结为以下 3 个步骤:
这是一种单寄存器解决方案。它基于:
a - b <=> a + (-b) <=> (-b) + a
; Step 1
mov al, c
shr al, 1
; Step 2
neg al
add al, b
; Step 3
neg al
add al, a