// File: /workspace/github_cpp_makefile_star2_O2/ariannagavioli[P]ALU/simulator.cpp
// Function: main
int main() {
	System system;
	
	//Initialize the system here by adding modules to the system object
	// system.addModule(new ExampleModule("Alice"));
	// system.addModule(new ExampleModule("Bob", 10));//The second parameter is the priority. It's useful only when you need to intercept someone's else message
	uint8_t dst = 4;
	
	global_regs.general_regs[dst] = -4000;
	cout << "Initial binary " << bitset<16>(global_regs.general_regs[dst]) << endl;

	alu_regs.opcode = IMUL_OPC;
	alu_regs.operand1 = 2;

	global_regs.general_regs[alu_regs.operand1] = 5;
	
	alu_regs.operand2 = dst;
	alu_regs.destination_reg = dst;

	cout << "OPCODE: " << int(alu_regs.opcode) << 
	" / OPE1: " << alu_regs.operand1 <<
	" / OPE2: " << alu_regs.operand2 << 
	" / DST: " << int(alu_regs.destination_reg) << 
	" / GENR: " << global_regs.general_regs[dst] << endl; 

	system.addModule(new AluModule("Alu"));
	system.addModule(new ExampleModule("Fetch"));
	//Call run() to start the simulation
	system.run();
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x90, %rsp
andl $0x0, 0x48(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x30(%rsp)
leaq 0x3e67(%rip), %rbx      # 0x8114
movw $0xf060, 0xa(%rbx)      # imm = 0xF060
movq 0x3d1e(%rip), %rdi      # 0x7fd8
leaq 0xed9(%rip), %rsi       # 0x519a
callq 0x2130
movzwl 0xa(%rbx), %ecx
leaq 0x8(%rsp), %rsi
movq %rcx, (%rsi)
movq %rax, %rdi
callq 0x3220
movq %rax, %rdi
callq 0x2090
leaq 0x3e23(%rip), %r14      # 0x810c
movb $0x65, (%r14)
movl $0x40002, 0x2(%r14)     # imm = 0x40002
movw $0x5, 0x6(%rbx)
movb $0x4, 0x6(%r14)
movq 0x3cd1(%rip), %rdi      # 0x7fd8
leaq 0xe9c(%rip), %rsi       # 0x51aa
callq 0x2130
movzbl (%r14), %esi
movq %rax, %rdi
callq 0x21b0
leaq 0xe8d(%rip), %rsi       # 0x51b3
movq %rax, %rdi
callq 0x2130
movzwl 0x2(%r14), %esi
movq %rax, %rdi
callq 0x21a0
leaq 0xe7b(%rip), %rsi       # 0x51bd
movq %rax, %rdi
callq 0x2130
movzwl 0x4(%r14), %esi
movq %rax, %rdi
callq 0x21a0
leaq 0xe69(%rip), %rsi       # 0x51c7
movq %rax, %rdi
callq 0x2130
movzbl 0x6(%r14), %esi
movq %rax, %rdi
callq 0x21b0
leaq 0xe56(%rip), %rsi       # 0x51d0
movq %rax, %rdi
callq 0x2130
movzwl 0xa(%rbx), %esi
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x2090
pushq $0x68
popq %rdi
callq 0x2140
movq %rax, %rbx
leaq 0xd57(%rip), %rsi       # 0x50ff
leaq 0x70(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x2050
movb $0x1, %bpl
leaq 0x70(%rsp), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x235c
xorl %ebp, %ebp
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x3654
leaq 0x70(%rsp), %rdi
callq 0x2080
pushq $0x48
popq %rdi
callq 0x2140
movq %rax, %rbx
leaq 0xd0f(%rip), %rsi       # 0x5103
leaq 0x50(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x2050
movb $0x1, %bpl
leaq 0x50(%rsp), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3380
xorl %ebp, %ebp
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x3654
leaq 0x50(%rsp), %rdi
callq 0x2080
leaq 0x10(%rsp), %rdi
callq 0x37dc
leaq 0x10(%rsp), %rdi
callq 0x4494
xorl %eax, %eax
addq $0x90, %rsp
popq %rbx
popq %r14
popq %rbp
retq
jmp 0x4452
movq %rax, %r14
jmp 0x4473
movq %rax, %r14
leaq 0x50(%rsp), %rdi
jmp 0x4469
movq %rax, %r14
leaq 0x70(%rsp), %rdi
callq 0x2080
testb %bpl, %bpl
je 0x4482
movq %rbx, %rdi
callq 0x2120
jmp 0x4482
jmp 0x447f
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x4494
movq %r14, %rdi
callq 0x21d0