// File: stacksmith[P]picoasm/cassembler.cpp
// Function: CAssembler::createOpcodes()
bool CAssembler::createOpcodes()
{
	list<CSourceLine*>::iterator it ;
	int columnOffset ; 
	
	for ( it = m_source.begin() ; it != m_source.end() ; it++ ) {
		if ( (*it)->m_type == CSourceLine::stNamereg || 
		     (*it)->m_type == CSourceLine::stConstant || 
			 (*it)->m_type == CSourceLine::stAddress )
			continue ;
			
		if ( (*it)->m_type == CSourceLine::stLabel )
			columnOffset = 2 ;
		else 
			columnOffset = 0 ;	

		if ( !(*it)->isColumn( columnOffset + 0 ) )						// just a label
			continue ;
								
		int instr = getInstruction( (*it)->getColumn( columnOffset + 0 ) ) ;
		
		if ( instr < 0  ) {
			error( (*it)->m_lineNr, "Unknown instruction" ) ;
			return FALSE ;
		}
		
		
		if ( addInstruction( (instrNumber) instr, **it, columnOffset )  == FALSE )
			return FALSE ;
			
	} 
	return TRUE ;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x40a3f0
movq -0xa0(%rbp), %rdi
callq 0x40a410
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0xa0(%rbp), %rdi
callq 0x40a470
movq %rax, -0x30(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x40a440
testb $0x1, %al
jne 0x409991
jmp 0x409b51
leaq -0x18(%rbp), %rdi
callq 0x40a4a0
movq (%rax), %rax
cmpl $0x2, 0x24(%rax)
je 0x4099c7
leaq -0x18(%rbp), %rdi
callq 0x40a4a0
movq (%rax), %rax
cmpl $0x3, 0x24(%rax)
je 0x4099c7
leaq -0x18(%rbp), %rdi
callq 0x40a4a0
movq (%rax), %rax
cmpl $0x4, 0x24(%rax)
jne 0x4099cc
jmp 0x409b3a
leaq -0x18(%rbp), %rdi
callq 0x40a4a0
movq (%rax), %rax
cmpl $0x1, 0x24(%rax)
jne 0x4099e7
movl $0x2, -0x1c(%rbp)
jmp 0x4099ee
movl $0x0, -0x1c(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x40a4a0
movq (%rax), %rdi
movl -0x1c(%rbp), %esi
addl $0x0, %esi
callq 0x40a570
testb $0x1, %al
jne 0x409a0e
jmp 0x409b3a
leaq -0x18(%rbp), %rdi
callq 0x40a4a0
movq (%rax), %rsi
movl -0x1c(%rbp), %edx
leaq -0x58(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x40a4c0
movq -0xa0(%rbp), %rdi
movq -0xb0(%rbp), %rsi
callq 0x405f70
movl %eax, -0xa4(%rbp)
jmp 0x409a48
leaq -0x58(%rbp), %rdi
callq 0x485ad0
movl -0xa4(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jge 0x409aa4
leaq -0x18(%rbp), %rdi
callq 0x40a4a0
movq -0xa0(%rbp), %rdi
movq (%rax), %rax
movl (%rax), %esi
leaq 0x181e18(%rip), %rdx    # 0x58b894
callq 0x405dc0
movb $0x0, -0x1(%rbp)
jmp 0x409b55
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x485ad0
jmp 0x409b63
movl -0x34(%rbp), %eax
movl %eax, -0xc4(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x40a4a0
movq (%rax), %rsi
leaq -0x90(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x40ad60
movq -0xa0(%rbp), %rdi
movl -0xc4(%rbp), %esi
movq -0xc0(%rbp), %rdx
movl -0x1c(%rbp), %ecx
callq 0x407730
movb %al, -0xb1(%rbp)
jmp 0x409af0
movb -0xb1(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0xc8(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x40adb0
movl -0xc8(%rbp), %eax
cmpl $0x0, %eax
jne 0x409b38
movb $0x0, -0x1(%rbp)
jmp 0x409b55
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x40adb0
jmp 0x409b63
jmp 0x409b3a
leaq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0x40ab50
movq %rax, -0x98(%rbp)
jmp 0x40996b
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xd0, %rsp
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x4b74e0
nopl (%rax)