8086 基本数学表达式

8086 basic mathematic expression

我必须在8086中进行这样的操作

((x*y)-c)+1

我写了这段代码:

.stack
.data
A dw 180
B db 4  
C dw 300 


.code
start:
    
    MOV AX, 00h
    MOV AX, A
    MUL B
    SUB AX, C
    DEC AX
    int 21h 
end start

此代码有效,但我不认为我想要的表达式...

我哪里错了?

This code works but I don't think does the expression I wanted...

((x * y) - c) + 1

计算基本正确。只是 DEC AX 应该变成 INC AX 所以它匹配你在最后 add 1 的表达式:

Looking at my teacher's example he always uses int 21h at the end of his code

我确定您老师的代码会在该行的正上方有类似 mov ah, 00hmov ax, 4C00h 的内容。它的意思是终止程序和 return 到 DOS。


这是在屏幕上额外显示计算结果的代码。该程序在终止之前等待键盘按键,让您有机会实际看到结果。

start:
    mov  ax, A
    mul  B
    sub  ax, C
    inc  ax         ; -> AX == 421

    mov  bx, 10
    xor  cx, cx
Divide:
    xor  dx, dx     ; Setup for division DX:AX / BX
    div  bx         ; -> Quotient AX, Remainder DX=[0,9]
    push dx         ; (1)
    inc  cx
    test ax, ax
    jnz  Divide
Show:
    pop  dx         ; (1)
    add  dl,"0"     ; [0,9] -> ["0","9"]
    mov  ah, 02h    ; DOS.DisplayCharacter
    int  21h        ; -> AL
    dec  cx
    jnz  Show

    mov  ah, 01h    ; DOS.GetKey
    int  21h        ; -> AL

    mov  ax, 4C00h  ; DOS.Terminate
    int  21h 
end start