Cannot move 8 bit address to 16 bit register

前端 未结 2 1607
有刺的猬
有刺的猬 2020-12-06 14:05

I am trying to assign variable to register here is the code:

       ORG 100h

        var1 DB 10  ;
        var2 DB 20  ;

        MOV BX,var1 ; error : oper         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 14:33

    You're using an assembler that keeps track of how you declare symbols to figure out what operand size to use.

    var1 isn't an 8 bit address, it's a 16bit address (not counting the segment) that points at the first of two 8-bit variables. So the assembler error message is badly worded and confusing.

    NASM would do what you said, and do a 16bit load. You'd find var1 in bl and var2 in bh. Presumably you could write mov bx, word [var1], or word ptr or whatever, to get your assembler to emit the 16bit load.

    (Actually, NASM would assemble mov BX, var1 into a mov r16, imm16, putting the address into the register. Always use [] around memory references, for consistency, because that works in NASM and MASM variants of Intel syntax. NASM doesn't support the mov BX, offset var1 syntax for writing the mov-immediate form, though.)

提交回复
热议问题