title: LinkedList in Assembly x86 Irvine
body: <p>The following is a linked list Assembly program found in Kip Irvine's Assembly Language x86 book. In main, a loop traverses the list and displays all the node values. Rather than using a fixed counter for the loop, the program checks for the null pointer in the tail node and stops looping when it is found. My question is the following: </p>
  
  <p><strong>(a) Can someone explain &lt; Counter, ($ + Counter * SIZEOF ListNode) >? How does it work and what does it mean?</strong></p>
  
  <p><strong>(b) Can someone explain (ListNode PTR [esi]).NextPtr? What does that mean?</strong></p>
  
  <pre><code>INCLUDE Irvine32.inc
  
      ListNode STRUCT
      NodeData DWORD ?
      NextPtr DWORD ?
      ListNode ENDS
      TotalNodeCount = 15
      NULL = 0
      Counter = 0
  
  .data
  
      putc     macro   ptr
  
       push    eax
  
       mov     al, ptr
       call    writechar
  
       pop     eax
       endm
  
       ;to use:             
       ;putc        'a'
  
  
  
      LinkedList LABEL PTR ListNode
  
  REPEAT TotalNodeCount
      Counter = Counter + 1
      ListNode &lt;Counter, ($ + Counter * SIZEOF ListNode)&gt;
      ;struct variables Counter, and ($+Counter*SIZEOF ListNode) being declared 
      ;
      ENDM
  
      ListNode &lt;0,0&gt; ; tail node
  
  .code
  
  main PROC
      mov esi,OFFSET LinkedList
      ; Display the integers in the NodeData fields.
      NextNode:
      ; Check for the tail node.
  
      putc    'a'; -&gt;first node, then third node
  
      mov eax,(ListNode PTR [esi]).NextPtr
      cmp eax,NULL
      je quit
      ; Display the node data.
  
      putc   'b' ;-&gt;fourth node 
  
      mov eax,(ListNode PTR [esi]).NodeData
      call WriteDec
      call Crlf
      ; Get pointer to next node.
  
      putc   'c' ;-&gt;first node 
      putc   'd' ;-&gt;second node 
      mov esi,(ListNode PTR [esi]).NextPtr
      ;references a struct using [esi] 
      jmp NextNode
      quit:
  
  
      exit
  main ENDP
  END main
  </code></pre>