assembly - 将 AH 存储到 DW 变量中时“操作数类型不匹配”
问题描述
嘿伙计们,我的汇编代码有点问题
第 55,60 行操作数类型不匹配我是否试图将 16 位内存移动到 8 位或其他方式?如果是这样,我该如何解决我的问题?谢谢你!
; NUM%
;
.MODEL SMALL
.STACK 100h
.DATA
Ten DW 10
Two DW 2
Num DW 0 ; variable to save Num input from user
Dig DW 0 ; Variable to save Dig input from user
Half_Dig DW 0 ; Variable to save Dig/2
Result DW 0 ; Variable to store result from Num^2%dig
PromptStr1 DB 13,10,'Please Enter Number (from 00 up to 99)',13,10,'$';string output to user
PromptStr2 DB 13,10,'Please Enter Digit (from 0 up to 9)',13,10,'$' ;string output to user
ResultStr DB 13,10,'XX^2 mod X = X',13,10,'$';Result output to user
ResultStr1 DB 13,10,'The result shloud be round up',13,10,'$'
ResultStr2 DB 13,10,'The result shloud be round down',13,10,'$'
DivisionErr DB 13,10,'Division Error',13,10,'$'
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AH,9
MOV DX,OFFSET PromptStr1
INT 21h
; Reading First Part of Num
MOV AH,1
INT 21h
MOV ResultStr[2],AL
SUB AL,'0'
MOV AH,0
MUL Ten
MOV Num,AX
MOV AX,0
; Reading Second Part of Num
MOV AH,1
INT 21h
MOV ResultStr[3],AL
SUB AL,'0'
MOV AH,0
ADD Num,AX
MOV AH,0
; Reading Dig
MOV AH,1
INT 21h
MOV ResultStr[11],AL
SUB AL,'0'
MOV AH,0
MOV Dig,AX
MOV AX,0
; checking to see if dig==0 , if so divsion error
CMP Dig,0
JE Error
MOV AX,Dig
DIV Two
***MOV Half_Dig,AH***
MOV AX,0
MOV AX,Num
MUL Num
DIV Half_dig
***MOV Result, AH***
希望能帮助我在这里做错了什么!
解决方案
查明问题
MOV AX,@DATA MOV DS,AX MOV AH,9 MOV DX,OFFSET PromptStr1 INT 21h ; Reading First Part of Num MOV AH,1 INT 21h MOV ResultStr[2],AL SUB AL,'0' MOV AH,0 ? MUL Ten Does not need the WORD sized multiplication MOV Num,AX ? MOV AX,0 Redundant ; Reading Second Part of Num MOV AH,1 INT 21h MOV ResultStr[3],AL SUB AL,'0' MOV AH,0 ADD Num,AX ? MOV AH,0 Redundant ; Reading Dig MOV AH,1 INT 21h MOV ResultStr[11],AL SUB AL,'0' MOV AH,0 MOV Dig,AX ? MOV AX,0 Redundant ; checking to see if dig==0 , if so divsion error CMP Dig,0 JE Error MOV AX,Dig ? DIV Two WORD sized division requiring DX=0 ? ***MOV Half_Dig,AH*** Quotient is in AL instead ? MOV AX,0 Redundant MOV AX,Num MUL Num DIV Half_dig Danger! Half_dig could be zero ? ***MOV Result, AH*** Quotient is in AX instead
您的代码最需要的是将变量定义为字节
Ten DB 10
Num DB 0 ; 0-99
Dig DB 0 ; 0-9
Half_Dig DB 0 ; 1-4
Result DB 0 ; 0-3
然后你需要清楚你想要计算什么。你的消息说:XX^2 mod X
但你的程序试图计算XX^2 mod (X/2)
。它是哪一个?
在下面的代码中,我将使用Half_Dig方法......
应用这些更改
MOV AX,@DATA
MOV DS,AX
MOV AH,9
MOV DX,OFFSET PromptStr1
INT 21h
; Reading First Part of Num
MOV AH,1
INT 21h
MOV ResultStr[2],AL
SUB AL,'0'
MUL Ten
MOV Num,AL
; Reading Second Part of Num
MOV AH,1
INT 21h
MOV ResultStr[3],AL
SUB AL,'0'
ADD Num,AL
; Reading Dig
MOV AH,1
INT 21h
MOV ResultStr[12],AL
SUB AL,'0'
MOV Dig,AL
; checking to see if (dig/2)==0 , if so divsion error
SHR AL, 1
JZ Error
MOV Half_Dig, AL
MOV AL, Num
MUL AL
DIV Half_dig
MOV Result, AL
您不需要除以除以 2。简单SHR
的工作做得更好。
这使用:ResultStr DB 13,10,'XX^2 mod (X/2) = X',13,10,'$'
推荐阅读
- encryption - 基于客户端身份验证加密解密 DynamoDB 数据
- apache-camel - Camel-Cdi 没有使用 Registery 注入 CamelContext
- ios - UINavigationController 交互式弹出手势仅在第一次工作
- javascript - 动态读取下拉列表中的选定值
- angular - 构建角度应用程序后,在角度中加载失败的 inline.318b50c57b4eba3d437b.bundle.js
- python - 是否有任何选项可以从 python 中的数组元素创建多个 dict
- java - 部署程序集配置不适用于 mvn 包
- python-3.x - Pandas 数据框按列名上的函数合并
- python - 如果找到分隔符,则拆分字符串
- playframework - 播放 2.4 Global.java onStart 多次调用