程序集 NASM - 和掩码
Assembly NASM - AND Mask
当我 运行 这个程序时它说:
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
MASM/TASM/JWASM 语法不同于 NASM。如果你想 load/store 一个地址的数据,你需要显式地使用方括号。如果要使用 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
当我 运行 这个程序时它说:
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
MASM/TASM/JWASM 语法不同于 NASM。如果你想 load/store 一个地址的数据,你需要显式地使用方括号。如果要使用 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