0

I am unable to understand why dec [count] is used ( assuming of course, count is declared in .data section ) something similar to

section .data
        count dw 0
        value db 15

section .text
        global _start

_start:
        dec [count]               

is used instead of using dec count, won't dec [count] decrement the the content at address count?

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
Pawan Nirpal
  • 565
  • 1
  • 12
  • 29
  • See also: [Basic use of immediates vs. square brackets in YASM/NASM x86 assembly](https://stackoverflow.com/q/10362511/555045) (for MASM it works in a different way but this isn't MASM-compatible code) – harold May 07 '22 at 20:12
  • @harold I am using nasm, would that make a substantial difference? – Pawan Nirpal May 07 '22 at 20:16
  • 1
    *"won't `dec [count]` decrement the the content at address count"* - yeah, that's exactly what it does. Where's the problem exactly? It's just decrementing a variable stored in memory in the `.data` section, whose address is `count`. – Marco Bonelli May 07 '22 at 20:21
  • 1
    Yes NASM vs MASM makes a substantial difference, square bracket usage in NASM is very regular, but [not so regular in MASM](https://stackoverflow.com/q/25129743/555045). – harold May 07 '22 at 20:24
  • Thank you, I think I am starting to understand now. Appreciate the help. – Pawan Nirpal May 07 '22 at 20:26

0 Answers0