// File: /workspace/github_cpp_makefile_star2_O1/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 %r15
pushq %r14
pushq %rbx
subq $0x88, %rsp
movl $0x0, 0x38(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, 0x20(%rsp)
leaq 0x39fb(%rip), %r14      # 0x811c
movw $0xf060, 0xa(%r14)      # imm = 0xF060
movq 0x38a9(%rip), %rdi      # 0x7fd8
leaq 0xaa4(%rip), %rsi       # 0x51da
movl $0xf, %edx
callq 0x2160
movzwl 0xa(%r14), %eax
leaq 0x80(%rsp), %rsi
movq %rax, (%rsi)
movq 0x3881(%rip), %rdi      # 0x7fd8
callq 0x32ad
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20b0
leaq 0x3987(%rip), %r15      # 0x8114
movb $0x65, (%r15)
movl $0x40002, 0x2(%r15)     # imm = 0x40002
movw $0x5, 0x6(%r14)
movb $0x4, 0x6(%r15)
movq 0x382c(%rip), %rdi      # 0x7fd8
leaq 0xa37(%rip), %rsi       # 0x51ea
movl $0x8, %edx
callq 0x2160
movzbl (%r15), %esi
movq 0x3810(%rip), %rdi      # 0x7fd8
callq 0x21b0
movq %rax, %rbx
leaq 0xa1c(%rip), %rsi       # 0x51f3
movl $0x9, %edx
movq %rax, %rdi
callq 0x2160
movzwl 0x2(%r15), %esi
movq %rbx, %rdi
callq 0x20a0
movq %rax, %rbx
leaq 0xa02(%rip), %rsi       # 0x51fd
movl $0x9, %edx
movq %rax, %rdi
callq 0x2160
movzwl 0x4(%r15), %esi
movq %rbx, %rdi
callq 0x20a0
movq %rax, %rbx
leaq 0x9e8(%rip), %rsi       # 0x5207
movl $0x8, %edx
movq %rax, %rdi
callq 0x2160
movzbl 0x6(%r15), %esi
movq %rbx, %rdi
callq 0x21b0
movq %rax, %rbx
leaq 0x9cd(%rip), %rsi       # 0x5210
movl $0x9, %edx
movq %rax, %rdi
callq 0x2160
movzwl 0xa(%r14), %esi
movq %rbx, %rdi
callq 0x20a0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20b0
movl $0x68, %edi
callq 0x2140
movq %rax, %r14
leaq 0x70(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x85b(%rip), %rsi       # 0x50ff
leaq 0x857(%rip), %rdx       # 0x5102
leaq 0x60(%rsp), %rdi
callq 0x3456
movb $0x1, %bpl
leaq 0x60(%rsp), %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x239c
xorl %ebp, %ebp
movq %rsp, %rdi
movq %r14, %rsi
callq 0x38ec
movq 0x60(%rsp), %rdi
cmpq %r15, %rdi
je 0x48e3
callq 0x2120
movl $0x48, %edi
callq 0x2140
movq %rax, %r14
leaq 0x50(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x803(%rip), %rsi       # 0x5103
leaq 0x801(%rip), %rdx       # 0x5108
leaq 0x40(%rsp), %rdi
callq 0x3456
movb $0x1, %bpl
leaq 0x40(%rsp), %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x353c
xorl %ebp, %ebp
movq %rsp, %rdi
movq %r14, %rsi
callq 0x38ec
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x493f
callq 0x2120
movq %rsp, %rdi
callq 0x3af4
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x4956
callq 0x2120
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x4964
callq 0x2120
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4976
movq %rax, %rbx
movb $0x1, %bpl
jmp 0x499a
movq %rax, %rbx
movq 0x40(%rsp), %rdi
jmp 0x4990
movq %rax, %rbx
movq 0x60(%rsp), %rdi
cmpq %r15, %rdi
je 0x499a
callq 0x2120
testb %bpl, %bpl
je 0x49ae
movq %r14, %rdi
callq 0x2120
jmp 0x49ae
jmp 0x49ab
movq %rax, %rbx
movq %rsp, %rdi
callq 0x49be
movq %rbx, %rdi
callq 0x21c0