简体   繁体   中英

Assembly NASM - AND Mask

When I run this program it says:

jdoodle.asm:9: error: invalid combination of opcode and operands

The problem is the AND al, ah. The rest of the code should be correct, I just need to know how to solve this problem because as it seems I can't do an AND between 2 registers.

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 syntax is different from NASM. If you want to load/store data at an address you need to explicitly use square brackets. If you want to use the MOV instruction to place the address of a label in a variable you do not use square brackets. Square brackets are like a de-reference operator.

In 32-bit code you will want to ensure addresses are loaded into 32-bit registers. Any address above 255 won't fit in an 8 byte register, any address above 65535 won't fit in a 16-bit register.

The code you were probably looking for is:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM