1

I have declared a variable:

section .bss
var    resb    1

I want to initialise this in my program to the value 255.

mov    [var], 255 ;error on this line

When compiling I get the error below:

program.asm:123: error: invalid size for operand 1

What am I doing wrong here?

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
ojhawkins
  • 3,200
  • 15
  • 50
  • 67

1 Answers1

-1

it works this way, you have to use a register to assign data to the location addressed by the symbol [myVar] :

mov eax,255
mov [myVar],eax

PRINT_DEC 2,myVar
  • 1
    You can assign an immediate value (like 255) to a memory location without going through a register. OPCODE information `C6 /0 MOV r/m8,imm8 ` | `Move imm8 to r/m8.` . See the x86 [instruction set reference](http://x86.renejeschke.de/html/file_module_x86_id_176.html). Move an 8 bit value to an 8 bit object in memory can be done with something like `mov byte [myVar],255` . `byte` says what the size of the memory object that `myVar` points to. The original poster wants to move an 8 bit value to `myvar` your code incorrectly tries to move 32 bits to a variable declared as 1 byte. – Michael Petch Nov 05 '15 at 20:26