// File: ys1998[P]spsim/src/writer.cpp
// Function: Writer::tick()
void Writer::tick(void){
	if(in1->valid()){
		t1 = in1->read();
		Instruction i1 = std::get<0>(t1);
		if(i1.is_valid() && std::get<0>(i1.type()) == 0){
			rf->write(std::get<2>(i1.physical_regs()), std::get<1>(t1));
			*(b + std::get<2>(i1.physical_regs())) = false;
		}
	}
	if(in2->valid()){
		t2 = in2->read();
		Instruction i2 = std::get<0>(t2);
		if(i2.is_valid()){
			if(std::get<0>(i2.type()) == 0 && std::get<1>(i2.type()) != FUNCT["div"])
				rf->write(std::get<2>(i2.physical_regs()), std::get<1>(t2));
			else{
				rf->write_lo(std::get<1>(t2));
				rf->write_hi(std::get<2>(t2));
			}
			*(b + std::get<2>(i2.physical_regs())) = false;
		}
	}
	if(in3->valid()){
		t3 = in3->read();
		Instruction i3 = std::get<0>(t3);
		if(i3.is_valid()){
			if(std::get<0>(i3.type()) == OPCODE["lw"]){
				rf->write(std::get<2>(i3.physical_regs()), std::get<1>(t3));
				*(b + std::get<2>(i3.physical_regs())) = false;
			}
		}
	}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4e0, %rsp            # imm = 0x4E0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x3d8(%rbp)
movq 0x188(%rax), %rdi
callq 0x6420
testb $0x1, %al
jne 0x203cf
jmp 0x2057d
movq -0x3d8(%rbp), %rax
movq 0x188(%rax), %rsi
leaq -0x88(%rbp), %rdi
movq %rdi, -0x3f8(%rbp)
callq 0x12500
movq -0x3d8(%rbp), %rdi
movq -0x3f8(%rbp), %rsi
addq $0x8, %rdi
movq %rdi, -0x3f0(%rbp)
callq 0x213b0
movq -0x3f8(%rbp), %rdi
callq 0x64b0
movq -0x3f0(%rbp), %rdi
callq 0x12590
movq %rax, %rsi
leaq -0x100(%rbp), %rdi
movq %rdi, -0x3e8(%rbp)
callq 0x6c70
movq -0x3e8(%rbp), %rdi
callq 0x6280
movb %al, -0x3d9(%rbp)
jmp 0x20450
movb -0x3d9(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x3f9(%rbp)
jne 0x20465
jmp 0x20492
leaq -0x114(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x105b0
jmp 0x2047a
leaq -0x114(%rbp), %rdi
callq 0x6210
cmpl $0x0, (%rax)
sete %al
movb %al, -0x3f9(%rbp)
movb -0x3f9(%rbp), %al
testb $0x1, %al
jne 0x204a1
jmp 0x20571
movq -0x3d8(%rbp), %rax
movq 0x1a8(%rax), %rax
movq %rax, -0x408(%rbp)
leaq -0x124(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x10520
jmp 0x204cb
leaq -0x124(%rbp), %rdi
callq 0x21410
movq -0x3d8(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x40c(%rbp)
addq $0x8, %rdi
callq 0x12540
movq -0x408(%rbp), %rdi
movl -0x40c(%rbp), %esi
movl (%rax), %edx
callq 0x213f0
jmp 0x20505
movq -0x3d8(%rbp), %rax
movq 0x1b0(%rax), %rax
movq %rax, -0x418(%rbp)
leaq -0x134(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x10520
jmp 0x2052f
leaq -0x134(%rbp), %rdi
callq 0x21410
movq %rax, %rcx
movq -0x418(%rbp), %rax
movslq (%rcx), %rcx
movb $0x0, (%rax,%rcx)
jmp 0x20571
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x61d0
jmp 0x20b83
leaq -0x100(%rbp), %rdi
callq 0x61d0
movq -0x3d8(%rbp), %rax
movq 0x198(%rax), %rdi
callq 0x6310
testb $0x1, %al
jne 0x20599
jmp 0x208fa
movq -0x3d8(%rbp), %rax
movq 0x198(%rax), %rsi
leaq -0x1b8(%rbp), %rdi
movq %rdi, -0x438(%rbp)
callq 0x62b0
movq -0x3d8(%rbp), %rdi
movq -0x438(%rbp), %rsi
addq $0x108, %rdi            # imm = 0x108
movq %rdi, -0x430(%rbp)
callq 0x21430
movq -0x438(%rbp), %rdi
callq 0x62f0
movq -0x430(%rbp), %rdi
callq 0x6360
movq %rax, %rsi
leaq -0x230(%rbp), %rdi
movq %rdi, -0x428(%rbp)
callq 0x6c70
movq -0x428(%rbp), %rdi
callq 0x6280
movb %al, -0x419(%rbp)
jmp 0x2061d
movb -0x419(%rbp), %al
testb $0x1, %al
jne 0x2062c
jmp 0x208db
movb $0x0, -0x262(%rbp)
movb $0x0, -0x263(%rbp)
leaq -0x238(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x105b0
jmp 0x2064f
leaq -0x238(%rbp), %rdi
callq 0x6210
movq %rax, %rcx
xorl %eax, %eax
cmpl $0x0, (%rcx)
movb %al, -0x439(%rbp)
jne 0x20709
leaq -0x240(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x105b0
jmp 0x20684
leaq -0x240(%rbp), %rdi
callq 0x61f0
movl (%rax), %eax
movl %eax, -0x44c(%rbp)
leaq -0x261(%rbp), %rdi
movq %rdi, -0x448(%rbp)
callq 0x3490
movq -0x448(%rbp), %rdx
movb $0x1, -0x262(%rbp)
leaq 0x1959(%rip), %rsi      # 0x22019
leaq -0x260(%rbp), %rdi
callq 0x6020
jmp 0x206ce
movb $0x1, -0x263(%rbp)
leaq 0xec1c(%rip), %rdi      # 0x2f2f8
leaq -0x260(%rbp), %rsi
callq 0x5f40
movq %rax, -0x458(%rbp)
jmp 0x206f1
movl -0x44c(%rbp), %eax
movq -0x458(%rbp), %rcx
cmpl (%rcx), %eax
setne %al
movb %al, -0x439(%rbp)
movb -0x439(%rbp), %al
movb %al, -0x459(%rbp)
testb $0x1, -0x263(%rbp)
jne 0x20720
jmp 0x2072c
leaq -0x260(%rbp), %rdi
callq 0x31e0
testb $0x1, -0x262(%rbp)
jne 0x20737
jmp 0x20743
leaq -0x261(%rbp), %rdi
callq 0x3300
movb -0x459(%rbp), %al
testb $0x1, %al
jne 0x20752
jmp 0x20830
movq -0x3d8(%rbp), %rax
movq 0x1a8(%rax), %rax
movq %rax, -0x468(%rbp)
leaq -0x274(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x10520
jmp 0x2077c
leaq -0x274(%rbp), %rdi
callq 0x21410
movq -0x3d8(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x46c(%rbp)
addq $0x108, %rdi            # imm = 0x108
callq 0x63e0
movq -0x468(%rbp), %rdi
movl -0x46c(%rbp), %esi
movl (%rax), %edx
callq 0x213f0
jmp 0x207b9
jmp 0x20894
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
jmp 0x208e9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
jmp 0x20814
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
testb $0x1, -0x263(%rbp)
jne 0x20806
jmp 0x20812
leaq -0x260(%rbp), %rdi
callq 0x31e0
jmp 0x20814
testb $0x1, -0x262(%rbp)
jne 0x2081f
jmp 0x2082b
leaq -0x261(%rbp), %rdi
callq 0x3300
jmp 0x208e9
movq -0x3d8(%rbp), %rdi
movq 0x1a8(%rdi), %rax
movq %rax, -0x478(%rbp)
addq $0x108, %rdi            # imm = 0x108
callq 0x63e0
movq -0x478(%rbp), %rdi
movl (%rax), %esi
callq 0x21470
jmp 0x20861
movq -0x3d8(%rbp), %rdi
movq 0x1a8(%rdi), %rax
movq %rax, -0x480(%rbp)
addq $0x108, %rdi            # imm = 0x108
callq 0x6400
movq -0x480(%rbp), %rdi
movl (%rax), %esi
callq 0x21490
jmp 0x20892
jmp 0x20894
movq -0x3d8(%rbp), %rax
movq 0x1b0(%rax), %rax
movq %rax, -0x488(%rbp)
leaq -0x284(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x10520
jmp 0x208be
leaq -0x284(%rbp), %rdi
callq 0x21410
movq %rax, %rcx
movq -0x488(%rbp), %rax
movslq (%rcx), %rcx
movb $0x0, (%rax,%rcx)
leaq -0x230(%rbp), %rdi
callq 0x61d0
jmp 0x208fa
leaq -0x230(%rbp), %rdi
callq 0x61d0
jmp 0x20b83
movq -0x3d8(%rbp), %rax
movq 0x190(%rax), %rdi
callq 0x6420
testb $0x1, %al
jne 0x20916
jmp 0x20b7a
movq -0x3d8(%rbp), %rax
movq 0x190(%rax), %rsi
leaq -0x308(%rbp), %rdi
movq %rdi, -0x4a8(%rbp)
callq 0x12500
movq -0x3d8(%rbp), %rdi
movq -0x4a8(%rbp), %rsi
addq $0x88, %rdi
movq %rdi, -0x4a0(%rbp)
callq 0x213b0
movq -0x4a8(%rbp), %rdi
callq 0x64b0
movq -0x4a0(%rbp), %rdi
callq 0x12590
movq %rax, %rsi
leaq -0x380(%rbp), %rdi
movq %rdi, -0x498(%rbp)
callq 0x6c70
movq -0x498(%rbp), %rdi
callq 0x6280
movb %al, -0x489(%rbp)
jmp 0x2099a
movb -0x489(%rbp), %al
testb $0x1, %al
jne 0x209a9
jmp 0x20b5e
leaq -0x388(%rbp), %rdi
leaq -0x380(%rbp), %rsi
callq 0x105b0
jmp 0x209be
leaq -0x388(%rbp), %rdi
callq 0x6210
movl (%rax), %eax
movl %eax, -0x4b4(%rbp)
leaq -0x3a9(%rbp), %rdi
movq %rdi, -0x4b0(%rbp)
callq 0x3490
movq -0x4b0(%rbp), %rdx
leaq 0x167a(%rip), %rsi      # 0x2206d
leaq -0x3a8(%rbp), %rdi
callq 0x6020
jmp 0x20a01
leaq 0xe8c0(%rip), %rdi      # 0x2f2c8
leaq -0x3a8(%rbp), %rsi
callq 0x5f40
movq %rax, -0x4c0(%rbp)
jmp 0x20a1d
movq -0x4c0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4c4(%rbp)
leaq -0x3a8(%rbp), %rdi
callq 0x31e0
leaq -0x3a9(%rbp), %rdi
callq 0x3300
movl -0x4c4(%rbp), %ecx
movl -0x4b4(%rbp), %eax
cmpl %ecx, %eax
jne 0x20b5c
movq -0x3d8(%rbp), %rax
movq 0x1a8(%rax), %rax
movq %rax, -0x4d0(%rbp)
leaq -0x3bc(%rbp), %rdi
leaq -0x380(%rbp), %rsi
callq 0x10520
jmp 0x20a82
leaq -0x3bc(%rbp), %rdi
callq 0x21410
movq -0x3d8(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x4d4(%rbp)
addq $0x88, %rdi
callq 0x12540
movq -0x4d0(%rbp), %rdi
movl -0x4d4(%rbp), %esi
movl (%rax), %edx
callq 0x213f0
jmp 0x20abf
movq -0x3d8(%rbp), %rax
movq 0x1b0(%rax), %rax
movq %rax, -0x4e0(%rbp)
leaq -0x3cc(%rbp), %rdi
leaq -0x380(%rbp), %rsi
callq 0x10520
jmp 0x20ae9
leaq -0x3cc(%rbp), %rdi
callq 0x21410
movq %rax, %rcx
movq -0x4e0(%rbp), %rax
movslq (%rcx), %rcx
movb $0x0, (%rax,%rcx)
jmp 0x20b5c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
jmp 0x20b6c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
jmp 0x20b4e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
leaq -0x3a8(%rbp), %rdi
callq 0x31e0
leaq -0x3a9(%rbp), %rdi
callq 0x3300
jmp 0x20b6c
jmp 0x20b5e
leaq -0x380(%rbp), %rdi
callq 0x61d0
jmp 0x20b7a
leaq -0x380(%rbp), %rdi
callq 0x61d0
jmp 0x20b83
addq $0x4e0, %rsp            # imm = 0x4E0
popq %rbp
retq
movq -0x108(%rbp), %rdi
callq 0x3480
nop