Search code examples
assemblyx86masmirvine32

Add two variables in assembly


I have the next program in Assembler MASM, I have a question about the sum records for Assembler MASM

 TITLE Suma variables
 INCLUDE Irvine32.inc
 .data
 a dword 10000h
 b dword 40000h
 valorFinal dword ?
.code
 main PROC
       mov eax,a ; empieza con 10000h
       add eax,b ; suma 40000h
       mov valorFinal,eax ; 
      call DumpRegs
      exit
 main ENDP
 END main

My question is when I use add with b, I'm adding only the value of the variable, or am I adding value and address in memory, because I understand that to get the particular value must be enclosed in [].


Solution

  • because I understand that to get the particular value must be enclosed in []

    In NASM syntax you would need brackets.
    In MASM/TASM syntax you don't, and add eax,b means the same thing as add eax,[b] (assuming that b is a label and not something like b EQU 42).

    If you wanted to add b's address to eax in MASM/TASM syntax you would write:

    add eax, offset b