// File: /workspace/github_cpp_makefile_star2_O3/czmccrory[P]ManchesterBaby/assembler.cpp
// Function: Assembler::encodeInstructionValue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
string Assembler::encodeInstructionValue(string mne, int value)
{
	//get opcode (make it a binary string)
	string opcode = getOpcode(mne);
	cout << "mne: " << mne << " -> opcode: " << opcode << endl;
	//get memory address of operand
	string operand = decToBinaryString(value, 6);
	cout << "operand: " << operand << endl;
	//initialises templine to be 32 0s
	string tempLine = "";
	for (int i = 0; i < 32; i++)
	{
		tempLine += "0";
	}
	// 6 for 64x32 store
	// 4 for 4 bit opcode (0-15)
	tempLine.replace(0, 6, operand);
	tempLine.replace(13, 4, opcode);
	tempLine.replace(31,1, "1");
	return tempLine;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %ecx, %ebp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x58(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rdx), %rsi
movq 0x8(%rdx), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %r12
movq %r12, %rdi
callq 0x5ebe
leaq 0x28(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x56c6
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
je 0x54a2
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x4b27(%rip), %rdi      # 0x9fd0
leaq 0x1ca1(%rip), %rsi      # 0x7151
movl $0x5, %edx
callq 0x2230
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0x4b08(%rip), %rdi      # 0x9fd0
callq 0x2230
movq %rax, %r14
leaq 0x1c80(%rip), %rsi      # 0x7157
movl $0xc, %edx
movq %rax, %rdi
callq 0x2230
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq %r14, %rdi
callq 0x2230
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2130
leaq 0x8(%rsp), %rdi
movl %ebp, %esi
movl $0x6, %edx
callq 0x33fa
movq 0x4a98(%rip), %rdi      # 0x9fd0
leaq 0x1c25(%rip), %rsi      # 0x7164
movl $0x9, %edx
callq 0x2230
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x4a76(%rip), %rdi      # 0x9fd0
callq 0x2230
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2130
leaq 0x10(%rbx), %r15
movq %r15, (%rbx)
leaq 0x1b4d(%rip), %rdx      # 0x70e4
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x605e
movl $0x20, %ebp
leaq 0x1ad2(%rip), %r14      # 0x7080
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2370
decl %ebp
jne 0x55ae
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %r8
movl $0x6, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2220
movq 0x28(%rsp), %rcx
movq 0x30(%rsp), %r8
movl $0xd, %esi
movl $0x4, %edx
movq %rbx, %rdi
callq 0x2220
leaq 0x1a89(%rip), %rcx      # 0x7082
movl $0x1f, %esi
movl $0x1, %edx
movl $0x1, %r8d
movq %rbx, %rdi
callq 0x2220
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x562c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5647
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21f0
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5669
jmp 0x566e
movq %rax, %r14
movq 0x48(%rsp), %rdi
jmp 0x56ad
jmp 0x5673
movq %rax, %r14
jmp 0x5689
movq %rax, %r14
jmp 0x56a4
movq %rax, %r14
movq (%rbx), %rdi
cmpq %r15, %rdi
je 0x5689
movq (%r15), %rsi
incq %rsi
callq 0x21f0
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x56a4
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x38(%rsp), %r13
movq -0x10(%r13), %rdi
cmpq %r13, %rdi
je 0x56be
movq (%r13), %rsi
incq %rsi
callq 0x21f0
movq %r14, %rdi
callq 0x2330