Assembly &引用;操作数类型不匹配;将AH存储到DW变量中时
嘿,伙计们,我的汇编代码有点问题 第55,60行操作数类型不匹配 我是在尝试将16位内存移动到8位还是其他方式?如果是,我如何解决我的问题?谢谢大家!Assembly &引用;操作数类型不匹配;将AH存储到DW变量中时,assembly,x86-16,Assembly,X86 16,嘿,伙计们,我的汇编代码有点问题 第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
; 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***
如果你能帮我做错事,我将不胜感激 查明问题
代码最需要的是将变量定义为字节
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)
。是哪一个
在下面的代码中,我将使用半挖方法
应用这些更改
你不需要除法来除以2。一个简单的SHR
做得更好
这使用:
ResultStr DB 13,10,'XX^2 mod(X/2)=X',13,10',$”
我建议将Half_Dig
和Result
定义为DB
,而不是DW
;您似乎只使用了8位,那么为什么要将它们定义为16位呢?所以db保存0-9之间的数字,被认为是1位?在x86上,一个字节是8位(就像所有现代ISA一样),所以它可以保存0..255之间的值。(或者如果您将其解释为带符号,-128..+127)。当然,如果您正在读取一个ASCII字符,它需要一个字节,如果我们正在讨论基数10,那么一个单位数字符串只能是'0'9'
Ten DB 10
Num DB 0 ; 0-99
Dig DB 0 ; 0-9
Half_Dig DB 0 ; 1-4
Result DB 0 ; 0-3
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