【发布时间】:2013-05-29 20:58:58
【问题描述】:
我必须制作一个可以用作计算器的程序。我是这样写的:
push ds
push 0000H
data segment
imsg1 db 13,10,'enter 1st number:$'
imsg2 db 13,10,'enter 2nd number:$'
imsg3 db 13,10,'sum:$'
imsg4 db 13,10,'diff:$'
imsg5 db 13,10,'div:$'
imsg6 db 13,10,'product:$'
num dw ?
num2 dw ?
data ends
MOV ax,data
MOV ds,ax
mov ah,09h
mov dx,offset imsg1
int 21h
mov cx,0
mov bx,10
mov num,0 ; Using num instead of dx, as we usually do, because we have to store another number too.
r1:mov ah,01h ; For storing first number
int 21h
cmp al,13
je yy
sub al,48
mov cl,al
mov ax,num
mul bx
add ax,cx
mov num,ax
jmp r1
yy:
;to enter 2nd number
mov ah,09h
mov dx,offset imsg2
int 21h
mov cx,0
mov bx,10
mov num2,0
r2:mov ah,01h
int 21h
cmp al,13
je yy1
sub al,48
mov cl,al
mov ax,num2
mul bx
add ax,cx
mov num2,ax
jmp r2
yy1:
;TO PRINT PROMPT MSG FOR SUM
mov ah,09h
mov dx,offset imsg3
int 21h
mov ax,num ; Move the numbers to registers before doing any operation
mov bx,num2 ; Because we will also need the numbers for other operations
add ax,bx ; Adding and storing in ax
mov cx,0
mov bx,10
mov dx,0
r3: ; To print the sum
mov dx,0
div bx
add dx,48
push dx
inc cx
cmp ax,0
jg r3
mov ah,02h
print:
pop dx
int 21h
loop print
;TO PRINT SUBTRACTION PROMPT
mov ah,09h
mov dx,offset imsg4
int 21h
mov ax,num
mov bx,num2
sub ax,bx ; Subtracting and storing in ax
mov cx,0
mov bx,10
mov dx,0
r4: ; Printing the subtracted value
mov dx,0
div bx
add dx,48
push dx
inc cx
cmp ax,0
jg r4
mov ah,02h
print1:
pop dx
int 21h
loop print1
;TO PRINT DIVISION PROMPT
mov ah,09h
mov dx,offset imsg5
int 21h
mov dx,0
mov ax,num
mov bx,num2
div bx ; Quotient stored in AX
mov cx,0
mov bx,10
mov dx,0
r5: ; Printing the Quotient
mov dx,0
div bx
add dx,48
push dx
inc cx
cmp ax,0
jg r5
mov ah,02h
print2:
pop dx
int 21h
loop print2
;TO PRINT MULTIPLICATION PROMPT
mov ah,09h
mov dx,offset imsg6
int 21h
mov dx,0
mov ax,num
mov bx,num2
mul bx ; Solution in AX
mov cx,0
mov bx,10
mov dx,0
r6: ; Printing the solution
mov dx,0
div bx
add dx,48
push dx
inc cx
cmp ax,0
jg r6
mov ah,02h
print3:
pop dx
int 21h
loop print3
ret
main endp
code ends
end main
我有错误:
第 5 行(数据段)解析器:预期指令
第 18 行(mov dx,偏移量 imsg1):应为逗号或行尾
第 39 行(mov dx,offset imsg2):应为逗号或行尾
第 62 行(mov dx,偏移量 imsg3):应为逗号或行尾
第 87 行(mov dx,offset imsg4):逗号或行尾预期
第 112 行(mov dx,偏移量 imsg5):应为逗号或行尾
第 138 行(mov dx,偏移量 imsg6):应为逗号或行尾
第 162 行(主要 endp):错误:解析器:预期指令
第 163 行(主要结束):错误:解析器:预期指令
第 164 行(主要结束):错误:解析器:预期指令
自一周以来我一直在尝试解决它们,但没有成功。抱歉,我已将整个代码放在这里,但它不是那么长 sn-p 所以也许有人可以帮助我.. 谢谢!
【问题讨论】:
-
什么汇编程序?看起来像 Masm/Tasm 代码,错误消息看起来可能来自 Nasm...
-
只是对未指定语法的猜测,但您是否可能需要在 imsg1: 后加一个冒号才能将它们识别为标签?
-
我想在 NASM 中编译它。添加冒号不起作用。我已经通过输入段.data解决了第一个错误,(数据端也有错误,但我已经删除了这一行)
-
如果您打算使用 NASM 来组装代码,为什么要使用 TASM 语法?
-
我不知道不同的编译器使用不同的语法。我找到了教程,听说 NASM 比其他的更好,我开始开发这个应用程序。现在,一切都清楚了:)
标签: assembly