程序集 multiply/divide 菜单
Assembly multiply/divide menu
我对汇编编程还很陌生,主要是想从 youtube 视频和 "assembly language for x86 processors" pdf 中学习。该程序现在还没有接近完成,但我已经遇到了 3 个我无法弄清楚的错误。
- 文件中的字符无效(第 1 行)
- 无效指令操作数(第 27、46、26 行)
符号类型冲突(第 15 行)
.model small
.data
message db "Please enter a for mutiplication or b for division $"
message2 db " Enter the first number $"
message3 db " Enter the second number $"
message4 db " * $"
message5 db " / $"
message6 db " = $"
.code
main proc
mov ax, seg message
mov ds, ax
mov dx, offset message
mov ah, 9h
int 21h
mov ah, 1h ;input stored in al
int 21h
mov bl, al ; menu selection input stored in bl so al can be used freely
mov ah, seg message2
mov ds, ah
mov dx, offset message2
mov ah, 9h
int 21h
mov ah, 1h; input stored in al
int 21h
mov cl, al ; first number input stored in cl so al can be used freely
mov dl, bl
mov ah, 2h
int 21h
mov dl, al ;second number imput stored in dl so al can be used again
sub cl, 30h ;convert characters to decimal
sub dl, 30h
mov ax, cl ;preform division
div dl
mov al, cl ;preform multiplication
mul dl
add cl, 30h ; convert decimal back to the characters
add dl, 30h
main endp
end main
最终我想将输入范围限制在 1-100 之间,如果有任何关于如何做到这一点的提示,我将不胜感激
我无法在这里重现错误 1) 和 3)。也许他们正在 "gone" 进行复制。删除源中的行并重新键入它们。
"error A2070:invalid instruction operands":
1) 第 27 行和第 26 行:
mov ah, seg message2
mov ds, ah
一个段是一个16位的值。您不能将其加载到 8 位寄存器 (AH
)。此外,您不能将 8 位寄存器 (AH
) 复制到 16 位寄存器 (DS
)。将行更改为:
mov ax, seg message2
mov ds, ax
2) 第 46 行:
mov ax, cl ;preform division
div dl
您不能将 8 位寄存器 (CL
) 复制到 16 位寄存器 (AX
)。执行此类操作有特殊说明:MOVZX
& MOVSX
。第一条指令将 8 位寄存器视为无符号整数,第二条指令将其视为有符号整数。将行更改为:
movzx ax, cl ;preform division
div dl
一个"ancient" 8086方式是:
xor ch, ch ; set CH (the upper part of CX) to null
mov ax, cx ;preform division
div dl
我对汇编编程还很陌生,主要是想从 youtube 视频和 "assembly language for x86 processors" pdf 中学习。该程序现在还没有接近完成,但我已经遇到了 3 个我无法弄清楚的错误。
- 文件中的字符无效(第 1 行)
- 无效指令操作数(第 27、46、26 行)
符号类型冲突(第 15 行)
.model small .data message db "Please enter a for mutiplication or b for division $" message2 db " Enter the first number $" message3 db " Enter the second number $" message4 db " * $" message5 db " / $" message6 db " = $" .code main proc mov ax, seg message mov ds, ax mov dx, offset message mov ah, 9h int 21h mov ah, 1h ;input stored in al int 21h mov bl, al ; menu selection input stored in bl so al can be used freely mov ah, seg message2 mov ds, ah mov dx, offset message2 mov ah, 9h int 21h mov ah, 1h; input stored in al int 21h mov cl, al ; first number input stored in cl so al can be used freely mov dl, bl mov ah, 2h int 21h mov dl, al ;second number imput stored in dl so al can be used again sub cl, 30h ;convert characters to decimal sub dl, 30h mov ax, cl ;preform division div dl mov al, cl ;preform multiplication mul dl add cl, 30h ; convert decimal back to the characters add dl, 30h main endp end main
最终我想将输入范围限制在 1-100 之间,如果有任何关于如何做到这一点的提示,我将不胜感激
我无法在这里重现错误 1) 和 3)。也许他们正在 "gone" 进行复制。删除源中的行并重新键入它们。
"error A2070:invalid instruction operands":
1) 第 27 行和第 26 行:
mov ah, seg message2
mov ds, ah
一个段是一个16位的值。您不能将其加载到 8 位寄存器 (AH
)。此外,您不能将 8 位寄存器 (AH
) 复制到 16 位寄存器 (DS
)。将行更改为:
mov ax, seg message2
mov ds, ax
2) 第 46 行:
mov ax, cl ;preform division
div dl
您不能将 8 位寄存器 (CL
) 复制到 16 位寄存器 (AX
)。执行此类操作有特殊说明:MOVZX
& MOVSX
。第一条指令将 8 位寄存器视为无符号整数,第二条指令将其视为有符号整数。将行更改为:
movzx ax, cl ;preform division
div dl
一个"ancient" 8086方式是:
xor ch, ch ; set CH (the upper part of CX) to null
mov ax, cx ;preform division
div dl