tasm: operand type does not match

后端 未结 2 723
无人共我
无人共我 2020-12-07 06:44
.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 nam         


        
相关标签:
2条回答
  • 2020-12-07 06:59

    First mistake:

    readchar dw 0
    ...
    mov al, readchar
    

    readchar is defined as WORD ("dw" = "data word", some say "define word". A word has a size of 16 bits. AL is an 8-bit-register. You cannot store a 16-bit word into an 8-bit register.

    Second mistake:

    mov si, al
    

    SI is a 16-bit register, AL is an 8-bit register. You cannot copy an 8-bit register into a 16-bit register.

    0 讨论(0)
  • 2020-12-07 07:11

    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], '$'
    
    0 讨论(0)
提交回复
热议问题