// File: /workspace/github_cpp_makefile_star2_O2/navrajsaini[P]PL_Compiler_design_project/Assembler.cpp
// Function: Assembler::firstPass()
void Assembler::firstPass()
{
   // Start at address 0 (not 1 as I had previously thought)
   currentAddress = 0;
   string nextop;
   (*insource) >> nextop;
   // Loop until we find the ENDPROG operation.
   for (;;) {
      // Record the current address in the label table.
      if (nextop == "DEFADDR") {
	 int index;
	 (*insource) >> index;
	 labelTable[index] = currentAddress;
	 (*insource) >> nextop;
      }
      // Record the associated value in the label table.
      else if (nextop == "DEFARG") {
	 int index, value;
	 (*insource) >> index >> value;
	 labelTable[index] = value;
	 (*insource) >> nextop;
      }
      // Stop when we find ENDPROG.
      else if (nextop == "ENDPROG")
	 return;
      else if (nextop == "ARROW" || nextop == "ASSIGN" || nextop == "BAR" ||
	       nextop == "CONSTANT" || nextop == "FI" || nextop == "READ" ||
	       nextop == "WRITE") {
	 // Skip one machine words.
	 (*insource) >> nextop;
	 (*insource) >> nextop;
	 currentAddress += 2;
      }
      else if (nextop == "CALL" || nextop == "INDEX" || nextop == "PROC" ||
	       nextop == "PROG" || nextop == "VARIABLE") {
	 // Skip two machine words.
	 (*insource) >> nextop;
	 (*insource) >> nextop;
	 (*insource) >> nextop;
	 currentAddress += 3;
      }
      else {
	 // just get the next machine word.
	 (*insource) >> nextop;
	 currentAddress++;
      }
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
andl $0x0, 0x7d0(%rdi)
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x7d8(%rdi), %rdi
leaq -0x50(%rbp), %rsi
callq 0x2220
leaq 0x2809(%rip), %r14      # 0xf6a3
leaq -0x50(%rbp), %r15
leaq -0x2c(%rbp), %r12
leaq 0x27f3(%rip), %r13      # 0xf69c
movq %r15, %rdi
movq %r14, %rsi
callq 0x7926
testb %al, %al
je 0xcee5
movq 0x7d8(%rbx), %rdi
movq %r12, %rsi
callq 0x2130
movl 0x7d0(%rbx), %eax
movslq -0x2c(%rbp), %rcx
movl %eax, (%rbx,%rcx,4)
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2220
jmp 0xcea9
movq %r15, %rdi
movq %r13, %rsi
callq 0x7926
testb %al, %al
je 0xcf2d
movq 0x7d8(%rbx), %rdi
movq %r12, %rsi
callq 0x2130
movq %rax, %rdi
leaq -0x30(%rbp), %rsi
callq 0x2130
movl -0x30(%rbp), %eax
movslq -0x2c(%rbp), %rcx
movl %eax, (%rbx,%rcx,4)
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2220
jmp 0xcea9
movq %r15, %rdi
leaq 0x275d(%rip), %rsi      # 0xf694
callq 0x7926
testb %al, %al
jne 0xd0a5
movq %r15, %rdi
leaq 0x28d4(%rip), %rsi      # 0xf822
callq 0x7926
testb %al, %al
jne 0xcfc9
movq %r15, %rdi
leaq 0x2878(%rip), %rsi      # 0xf7d9
callq 0x7926
testb %al, %al
jne 0xcfc9
movq %r15, %rdi
leaq 0x28b4(%rip), %rsi      # 0xf828
callq 0x7926
testb %al, %al
jne 0xcfc9
movq %r15, %rdi
leaq 0x28ff(%rip), %rsi      # 0xf886
callq 0x7926
testb %al, %al
jne 0xcfc9
movq %r15, %rdi
leaq 0x2873(%rip), %rsi      # 0xf80d
callq 0x7926
testb %al, %al
jne 0xcfc9
movq %r15, %rdi
leaq 0x280b(%rip), %rsi      # 0xf7b8
callq 0x7926
testb %al, %al
jne 0xcfc9
movq %r15, %rdi
leaq 0x2809(%rip), %rsi      # 0xf7c9
callq 0x7926
testb %al, %al
je 0xcff3
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2220
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2220
addl $0x2, 0x7d0(%rbx)
jmp 0xcea9
movq %r15, %rdi
leaq 0x2808(%rip), %rsi      # 0xf805
callq 0x7926
testb %al, %al
jne 0xd052
movq %r15, %rdi
leaq 0x28b8(%rip), %rsi      # 0xf8c8
callq 0x7926
testb %al, %al
jne 0xd052
movq %r15, %rdi
leaq 0x278a(%rip), %rsi      # 0xf7ad
callq 0x7926
testb %al, %al
jne 0xd052
movq %r15, %rdi
leaq 0x2661(%rip), %rsi      # 0xf697
callq 0x7926
testb %al, %al
jne 0xd052
movq %r15, %rdi
leaq 0x2853(%rip), %rsi      # 0xf89c
callq 0x7926
testb %al, %al
je 0xd08b
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2220
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2220
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2220
addl $0x3, 0x7d0(%rbx)
jmp 0xcea9
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2220
incl 0x7d0(%rbx)
jmp 0xcea9
leaq -0x50(%rbp), %rdi
callq 0x20d0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xd0c3
jmp 0xd0c3
jmp 0xd0c3
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x20d0
movq %rbx, %rdi
callq 0x22e0
nop