// File: Ziang95[P]Tomasulo_simulator/reserv_station.cpp
// Function: resStation::fill_rs(int, instr const*, int, int, memCell, memCell)
bool resStation::fill_rs(int _dest_robi, const instr* _instr, int _Qj, int _Qk, memCell _Vj, memCell _Vk)
{
    sub = _instr->code == SUB || _instr->code == SUB_D;
    busy = true;
    dest = _dest_robi;
    code = _instr->code;
    Qj = _Qj;
    Qk = _Qk;
    offset = _instr->offset;
    Vj = _Vj;
    Vk = _Vk;
    Rj = Qj<0? true:false;
    Rk = Qk<0? true:false;
    if (code == LD)
        lsqE = main_mem.LD_enQ(dest, -1);
    else if (code == SD)
    {
        memCell SD_source;
        int SD_source_rob = -1;
        get_reg_or_rob(_instr->dest, SD_source_rob, SD_source);
        lsqE = main_mem.SD_enQ(dest, SD_source_rob, -1, SD_source);
    }
    if (Rj&&Rk)
    {
        msg_log("Operands ready, sending to FU, dest ROB = " + to_string(dest), 2);
        prnt_Q->enQ(code, dest, &rest, &Vj, &Vk, lsqE, offset, &busy);
    }
    else
        to_start = true;
    msg_log("Res Station filled, ROB = " + to_string(dest), 3);
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movl 0x10(%rbp), %eax
movl %r9d, -0x4(%rbp)
movl %eax, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x20(%rbp), %rcx
movb $0x1, %al
cmpl $0x2, 0x20(%rcx)
movb %al, -0xe1(%rbp)
je 0x20d95
movq -0x20(%rbp), %rax
cmpl $0x3, 0x20(%rax)
sete %al
movb %al, -0xe1(%rbp)
movq -0xf0(%rbp), %rax
movb -0xe1(%rbp), %cl
andb $0x1, %cl
movb %cl, 0x2e(%rax)
movb $0x1, (%rax)
movl -0x14(%rbp), %ecx
movl %ecx, 0x4(%rax)
movq -0x20(%rbp), %rcx
movl 0x20(%rcx), %ecx
movl %ecx, 0x30(%rax)
movl -0x24(%rbp), %ecx
movl %ecx, 0x8(%rax)
movl -0x28(%rbp), %ecx
movl %ecx, 0xc(%rax)
movq -0x20(%rbp), %rcx
movl 0x8c(%rcx), %ecx
movl %ecx, 0x28(%rax)
movl -0x4(%rbp), %ecx
movl %ecx, 0x14(%rax)
movl -0x8(%rbp), %ecx
movl %ecx, 0x18(%rax)
movl 0x8(%rax), %ecx
shrl $0x1f, %ecx
movb %cl, 0x2c(%rax)
movl 0xc(%rax), %ecx
sarl $0x1f, %ecx
andb $0x1, %cl
movb %cl, 0x2d(%rax)
cmpl $0x6, 0x30(%rax)
jne 0x20e29
movq -0xf0(%rbp), %rax
movl 0x4(%rax), %esi
leaq 0xf014(%rip), %rdi      # 0x2fe20
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x1af70
movq %rax, %rcx
movq -0xf0(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x20ecc
movq -0xf0(%rbp), %rax
cmpl $0x7, 0x30(%rax)
jne 0x20eca
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rsi
addq $0x28, %rsi
leaq -0x50(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x4180
movq -0xf8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
callq 0x17a50
jmp 0x20e6f
leaq -0x50(%rbp), %rdi
callq 0x4240
movq -0xf0(%rbp), %rax
movl 0x4(%rax), %esi
movl -0x30(%rbp), %edx
movl -0x2c(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %r8d
leaq 0xef8a(%rip), %rdi      # 0x2fe20
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x1b090
movq %rax, %rcx
movq -0xf0(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x20eca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x4240
jmp 0x2106e
jmp 0x20ecc
movq -0xf0(%rbp), %rax
testb $0x1, 0x2c(%rax)
je 0x20fc0
movq -0xf0(%rbp), %rax
testb $0x1, 0x2d(%rax)
je 0x20fc0
movq -0xf0(%rbp), %rax
movl 0x4(%rax), %esi
leaq -0xa0(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x8410
movq -0x100(%rbp), %rdx
leaq 0x1b11(%rip), %rsi      # 0x22a2a
leaq -0x80(%rbp), %rdi
callq 0x83c0
jmp 0x20f24
leaq -0x80(%rbp), %rdi
movl $0x2, %esi
callq 0x12060
jmp 0x20f34
leaq -0x80(%rbp), %rdi
callq 0x4240
leaq -0xa0(%rbp), %rdi
callq 0x4240
movq -0xf0(%rbp), %rax
movq 0x48(%rax), %rdi
movl 0x30(%rax), %esi
movl 0x4(%rax), %edx
movq %rax, %rcx
addq $0x10, %rcx
movq %rax, %r8
addq $0x14, %r8
movq %rax, %r9
addq $0x18, %r9
movq 0x20(%rax), %r11
movl 0x28(%rax), %r10d
movq %r11, (%rsp)
movl %r10d, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x53f0
jmp 0x20fcb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x20faf
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 0x2106e
movq -0xf0(%rbp), %rax
movb $0x1, 0x1(%rax)
movq -0xf0(%rbp), %rax
movl 0x4(%rax), %esi
leaq -0xe0(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x8410
movq -0x108(%rbp), %rdx
leaq 0x1a5f(%rip), %rsi      # 0x22a55
leaq -0xc0(%rbp), %rdi
callq 0x83c0
jmp 0x21004
leaq -0xc0(%rbp), %rdi
movl $0x3, %esi
callq 0x12060
jmp 0x21017
leaq -0xc0(%rbp), %rdi
callq 0x4240
leaq -0xe0(%rbp), %rdi
callq 0x4240
movb $0x1, %al
andb $0x1, %al
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x21062
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)