// File: /workspace/github_cpp_makefile_star2_O3/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 0x38db(%rip), %r14      # 0x811c
movw $0xf060, 0xa(%r14)      # imm = 0xF060
movq 0x3789(%rip), %rdi      # 0x7fd8
leaq 0x984(%rip), %rsi       # 0x51da
movl $0xf, %edx
callq 0x2160
movzwl 0xa(%r14), %eax
leaq 0x80(%rsp), %rsi
movq %rax, (%rsi)
movq 0x3761(%rip), %rdi      # 0x7fd8
callq 0x33d9
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 0x3867(%rip), %r15      # 0x8114
movb $0x65, (%r15)
movl $0x40002, 0x2(%r15)     # imm = 0x40002
movw $0x5, 0x6(%r14)
movb $0x4, 0x6(%r15)
movq 0x370c(%rip), %rdi      # 0x7fd8
leaq 0x917(%rip), %rsi       # 0x51ea
movl $0x8, %edx
callq 0x2160
movzbl (%r15), %esi
movq 0x36f0(%rip), %rdi      # 0x7fd8
callq 0x21b0
movq %rax, %rbx
leaq 0x8fc(%rip), %rsi       # 0x51f3
movl $0x9, %edx
movq %rax, %rdi
callq 0x2160
movzwl 0x2(%r15), %esi
movq %rbx, %rdi
callq 0x20a0
movq %rax, %rbx
leaq 0x8e2(%rip), %rsi       # 0x51fd
movl $0x9, %edx
movq %rax, %rdi
callq 0x2160
movzwl 0x4(%r15), %esi
movq %rbx, %rdi
callq 0x20a0
movq %rax, %rbx
leaq 0x8c8(%rip), %rsi       # 0x5207
movl $0x8, %edx
movq %rax, %rdi
callq 0x2160
movzbl 0x6(%r15), %esi
movq %rbx, %rdi
callq 0x21b0
movq %rax, %rbx
leaq 0x8ad(%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 0x73b(%rip), %rsi       # 0x50ff
leaq 0x737(%rip), %rdx       # 0x5102
leaq 0x60(%rsp), %rdi
callq 0x3588
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 0x3a34
movq 0x60(%rsp), %rdi
cmpq %r15, %rdi
je 0x4a03
callq 0x2120
movl $0x48, %edi
callq 0x2140
movq %rax, %r14
leaq 0x50(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x6e3(%rip), %rsi       # 0x5103
leaq 0x6e1(%rip), %rdx       # 0x5108
leaq 0x40(%rsp), %rdi
callq 0x3588
movb $0x1, %bpl
leaq 0x40(%rsp), %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x3674
xorl %ebp, %ebp
movq %rsp, %rdi
movq %r14, %rsi
callq 0x3a34
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x4a5f
callq 0x2120
movq %rsp, %rdi
callq 0x3c3e
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x4a76
callq 0x2120
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x4a84
callq 0x2120
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4a96
movq %rax, %rbx
jmp 0x4abc
movq %rax, %rbx
movq 0x40(%rsp), %rdi
jmp 0x4aad
movq %rax, %rbx
movq 0x60(%rsp), %rdi
cmpq %r15, %rdi
je 0x4ab7
callq 0x2120
testb %bpl, %bpl
je 0x4acb
movq %r14, %rdi
callq 0x2120
jmp 0x4acb
jmp 0x4ac8
movq %rax, %rbx
movq %rsp, %rdi
callq 0x4adc
movq %rbx, %rdi
callq 0x21c0
nop