Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

assembly - 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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The operand type does not match error comes from trying to move

  • 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)

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)

To correct the second problem just write mov si, ax which is what you intended anyway.

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], '$'

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], '$'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...