装配NASM - 和面具

问题描述 投票:0回答:1

当我运行这个程序时,它说:

jdoodle.asm:9:错误:操作码和操作数的组合无效

问题是AND al,啊。其余的代码应该是正确的,我只需要知道如何解决这个问题,因为我似乎无法在2个寄存器之间进行AND。

section .text
global _start
_start:
    call _input
    mov al, input
    mov ah, maschera
    and al, ah
    mov input, al
    call _output
    jmp _exit

_input:
    mov eax, 3
    mov ebx, 0
    mov ecx, input
    mov edx, 1
    int 80h
    ret

_output:
    mov eax, 4
    mov ebx, 1
    mov ecx, input
    mov edx, 1
    int 80h
    ret

_exit:

mov eax, 1

int 80h

section .data
maschera: db 11111111b

segment .bss
input resb 1
assembly nasm x86-16
1个回答
1
投票

MASM / TASM / JWASM语法与NASM不同。如果要在地址加载/存储数据,则需要明确使用方括号。如果要使用MOV指令将标签的地址放在变量中,则不要使用方括号。方括号就像去参考运算符。

在32位代码中,您需要确保将地址加载到32位寄存器中。高于255的任何地址都不适合8字节寄存器,高于65535的任何地址都不适合16位寄存器。

您可能正在寻找的代码是:

section .text
global _start
_start:
    call _input
    mov al, [input]
    mov ah, [maschera]
    and al, ah
    mov [input], al
    call _output
    jmp _exit

_input:
    mov eax, 3
    mov ebx, 0
    mov ecx, input
    mov edx, 1
    int 80h
    ret

_output:
    mov eax, 4
    mov ebx, 1
    mov ecx, input
    mov edx, 1
    int 80h
    ret

_exit:

mov eax, 1

int 80h

section .data
maschera: db 11111111b

segment .bss
input resb 1
© www.soinside.com 2019 - 2024. All rights reserved.