-1

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
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Shark44
  • 593
  • 1
  • 4
  • 11
  • 3
    `and al, ah` is not line 9 in the code you've shown us. Anyway, that instruction is likely not the problem. It's more likely `mov input, al`, which should be `mov [input], al`. And similarly in all the other places where you access memory (i.e. use brackets to access memory at a given address). – Michael Apr 27 '19 at 15:17
  • Now I got these errors: – Shark44 Apr 27 '19 at 15:19
  • jdoodle.asm:(.text+0x6): relocation truncated to fit: R_386_8 against `.bss' jdoodle.asm:(.text+0x8): relocation truncated to fit: R_386_8 against `.data' – Shark44 Apr 27 '19 at 15:19
  • have a look at https://stackoverflow.com/questions/46928566/relocation-truncated-to-fit-r-386-8-against-bss – Gene Apr 27 '19 at 16:51

1 Answers1

2

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
Michael Petch
  • 46,082
  • 8
  • 107
  • 198