tasm:操作数类型不匹配 [英] tasm: operand type does not match
问题描述
.model small
.stack
.data
buff label byte
maxchar dw 50
readchar dw 0
name1 db 48 dup(0)
m1 db 10,13,"enter name: $"
m2 db 10,13,"your name is: $"
.code
mov ax, @data
mov ds, ax
lea dx, m1
mov ah, 09
int 21h
lea dx, buff
mov ah, 10
int 21h
mov ah,0
mov al, readchar
add ax, 2
mov si, al
mov buff[si],24H ;ascii code for $ to terminate string
lea dx, m2
mov ah, 9
int 21h
lea dx, name1
mov ah, 09
int 21h
mov ah, 4ch
int 21h
end
推荐答案
操作数类型不匹配错误来自尝试移动
- 将字大小的变量放入字节大小的寄存器(
mov al, readchar
) - 将字节大小的寄存器转换为字大小的寄存器(
mov si, al
)
- a word sized variable into a byte sized register (
mov al, readchar
) - a byte sized register into a word sized register (
mov si, al
)
要解决这些问题,您必须考虑下一个数据定义的真正含义.
To solve these issues you have to consider what the next data definitions really represent.
buff label byte
maxchar dw 50
readchar dw 0
name1 db 48 dup(0)
这4行代码一起是DOS输入功能0Ah使用的结构.它期望在第一和第二字段中输入 bytes (字节)!
因此,要摆脱第一个问题,请将其更改为
These 4 lines of code together are the structure that is used by the DOS input function 0Ah. It expects bytes in the 1st and 2nd fields!
So to get rid of the first problem change this into
buff label byte
maxchar db 50
readchar db 0
name1 db 48 dup(0)
要纠正第二个问题,只需编写mov si, ax
,这正是您想要的.
To correct the second problem just write mov si, ax
which is what you intended anyway.
作为奖励,为什么不使用标签 name1 起作用?这将为您节省add ax, 2
指令.
As a bonus, why don't you put the label name1 to work? It will save you the add ax, 2
instruction.
mov ah, 0
mov al, readchar
mov si, ax
mov name1[si], '$'
第二个好处是,您可以使用BX寄存器代替SI并保存另一条指令.
As a second bonus, you could use the BX register in stead of SI and save yet another instruction.
mov bh, 0
mov bl, readchar
mov name1[bx], '$'
这篇关于tasm:操作数类型不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!