// File: Ziang95[P]Tomasulo_simulator/memory.cpp
// Function: memory::store(LSQEntry)
bool memory::store(LSQEntry entry)
{
    ROBEntry *R = CPU_ROB->get_entry(entry.rob_i);
    R->output.commit = R->output.mem = sys_clk.get_prog_cyc();
    instr_timeline_output(R);
    msg_log("Begin to store value to Addr="+to_string(entry.addr), 3);
    for (int i = 0; ; i++)
    {
        msg_log("Storing value to Addr="+to_string(entry.addr), 3);
        if (i == CPU_cfg->ld_str->mem_time - 1)
            break;
        at_falling_edge(mem_next_vdd);
        if (i == 0)
            CPU_ROB->ptr_advance();
        at_rising_edge(mem_next_vdd);
    }
    buf[entry.addr] = entry.val;
    at_falling_edge(mem_next_vdd);
    if (CPU_cfg->ld_str->mem_time == 1) //In this case the ROB pointer was not advanced in the loop
        CPU_ROB->ptr_advance();
    Sfront = (++Sfront)%Q_LEN;
    msg_log("Value stored ROB = " + to_string(entry.rob_i), 2);
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
leaq 0x10(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rcx
movq %rcx, -0xf8(%rbp)
leaq 0x14ee4(%rip), %rcx     # 0x2f460
movq (%rcx), %rdi
movl (%rax), %esi
callq 0xe4d0
movq %rax, -0x10(%rbp)
leaq 0x15807(%rip), %rdi     # 0x2fd98
callq 0x116c0
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x58(%rax)
movq -0x10(%rbp), %rax
movl %ecx, 0x60(%rax)
movq -0x10(%rbp), %rdi
callq 0x1cfd0
movq -0xf0(%rbp), %rax
movl 0x10(%rax), %esi
leaq -0x50(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x8410
movq -0xe8(%rbp), %rdx
leaq 0x8136(%rip), %rsi      # 0x2270d
leaq -0x30(%rbp), %rdi
callq 0x83c0
jmp 0x1a5e2
leaq -0x30(%rbp), %rdi
movl $0x3, %esi
callq 0x12060
jmp 0x1a5f2
leaq -0x30(%rbp), %rdi
callq 0x4240
leaq -0x50(%rbp), %rdi
callq 0x4240
movl $0x0, -0x60(%rbp)
movq -0xf0(%rbp), %rax
movl 0x10(%rax), %esi
leaq -0xa0(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x8410
movq -0x100(%rbp), %rdx
leaq 0x80f5(%rip), %rsi      # 0x2272b
leaq -0x80(%rbp), %rdi
callq 0x83c0
jmp 0x1a641
leaq -0x80(%rbp), %rdi
movl $0x3, %esi
callq 0x12060
jmp 0x1a651
leaq -0x80(%rbp), %rdi
callq 0x4240
leaq -0xa0(%rbp), %rdi
callq 0x4240
movl -0x60(%rbp), %eax
leaq 0x14de0(%rip), %rcx     # 0x2f450
movq (%rcx), %rcx
movq 0x20(%rcx), %rcx
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x1a6eb
jmp 0x1a734
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x1a6a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x4240
leaq -0x50(%rbp), %rdi
callq 0x4240
jmp 0x1a851
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x1a6da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x4240
leaq -0xa0(%rbp), %rdi
callq 0x4240
jmp 0x1a851
movq -0xf8(%rbp), %rdi
addq $0x80, %rdi
callq 0x121a0
cmpl $0x0, -0x60(%rbp)
jne 0x1a713
leaq 0x14d55(%rip), %rax     # 0x2f460
movq (%rax), %rdi
callq 0xe5a0
movq -0xf8(%rbp), %rdi
addq $0x80, %rdi
callq 0x12130
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x1a60b
movq -0xf8(%rbp), %rdi
movq -0xf0(%rbp), %rdx
movq (%rdi), %rax
movslq 0x10(%rdx), %rcx
movl 0xc(%rdx), %edx
movl %edx, (%rax,%rcx,4)
addq $0x80, %rdi
callq 0x121a0
leaq 0x14cee(%rip), %rax     # 0x2f450
movq (%rax), %rax
movq 0x20(%rax), %rax
cmpl $0x1, 0x8(%rax)
jne 0x1a77e
leaq 0x14cea(%rip), %rax     # 0x2f460
movq (%rax), %rdi
callq 0xe5a0
movq -0xf0(%rbp), %rax
movq -0xf8(%rbp), %rcx
movl 0x14(%rcx), %edi
movl %edi, %edx
incl %edx
movl %edx, 0x14(%rcx)
movl %edi, %esi
addl $0x100, %esi            # imm = 0x100
testl %edx, %edx
cmovsl %esi, %edx
andl $0xffffff00, %edx       # imm = 0xFFFFFF00
negl %edx
movl %edx, %esi
movl %edi, %edx
leal 0x1(%rdx,%rsi), %edx
movl %edx, 0x14(%rcx)
movl (%rax), %esi
leaq -0xe0(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x8410
movq -0x108(%rbp), %rdx
leaq 0x7f69(%rip), %rsi      # 0x22742
leaq -0xc0(%rbp), %rdi
callq 0x83c0
jmp 0x1a7e7
leaq -0xc0(%rbp), %rdi
movl $0x2, %esi
callq 0x12060
jmp 0x1a7fa
leaq -0xc0(%rbp), %rdi
callq 0x4240
leaq -0xe0(%rbp), %rdi
callq 0x4240
movb $0x1, %al
andb $0x1, %al
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x1a845
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x4240
leaq -0xe0(%rbp), %rdi
callq 0x4240
movq -0x58(%rbp), %rdi
callq 0x45f0
nopw (%rax,%rax)