【发布时间】:2015-08-19 04:04:35
【问题描述】:
我在汇编中的简单程序有问题。我正在使用 DOSBox 和 TASM。问题是第 76、78 和 80 行中的操作数类型不匹配。这是在乘法之后。我尝试使用不同的可变大小进行一些更改。
; --------------------------------------------
; Equation=(a+c*b)/d-2*c,
; --------------------------------------------
.model small
.stack 100h
.data
a db 0
b db 0
c db 0
d db 0
result1 db ?
result2 db ?
message1 db "Equation: (a+c*b)/d-2*c a=$"
message2 db "b=$"
message3 db "c=$"
message4 db "d=$"
message5 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 message1
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 number
mov c,al
mov ax, seg message4 ;get d and save to a variable
mov ds,ax
mov dx,offset message4
mov ah, 9h
int 21h
mov ah, 1h
int 21h
sub al,30h ;converting to real number
mov d,al
mov al,b ; (a+c*b) ------------------------error
mul c
add ax,a ; ------------------------error
push ax ;save current ax
mov ax,c ;d-2*c------------------------error
shl ax,2
sub d,ax
pop bx ;get previous ax to bx
div bx ; div ax:bx
mov result1,al
mov result2,ah
add result1,30h ;converting to string
add result2,30h ;converting to string
mov al,result1
mov bl,result2
mov ax, seg message5
mov ds,ax
mov dx,offset message5
mov ah, 9h
int 21h
mov al,result1
mov bl,result2
mov dl, al
mov ah , 2h
int 21h
mov dl, bl
mov ah , 2h
int 21h
mov ax,4C00h
int 21h
end start
【问题讨论】:
-
直接在这里发布您的代码。
-
.. 并标记线条。例如,在粘贴线 76 和 80 中是空的。我以某种方式怀疑错误是否存在......
-
你的程序应该处理的最大数字是多少?
-
您已将
a和c声明为字节。所以add ax,a和mov ax,c可能不会做你想做的事,即使他们组装了。使您的变量成为单词,或使用扩展movs。 -
因为这个问题在 9k 浏览量中取得了巨大的成功并且因为接受的答案本质上是错误和误导,所以我决定发布一个正确的版本,以便人们最终了解如何计算这些简单的表达式。
标签: assembly expression x86-16 tasm dosbox