// File: 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
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdx, -0xc0(%rbp)
movq %rsi, %rax
movq -0xc0(%rbp), %rsi
movq %rdi, -0xb8(%rbp)
movq %rdi, %rdx
movq %rdx, -0xb0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rax, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0x60(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0x3100
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
leaq -0x40(%rbp), %rdi
callq 0x72e0
jmp 0x7040
leaq -0x60(%rbp), %rdi
callq 0x31c0
movq 0x8f80(%rip), %rdi      # 0xffd0
leaq 0x40fa(%rip), %rsi      # 0xb151
callq 0x3290
movq %rax, -0xc8(%rbp)
jmp 0x7065
movq -0xc0(%rbp), %rsi
movq -0xc8(%rbp), %rdi
callq 0x3270
movq %rax, -0xd0(%rbp)
jmp 0x7081
movq -0xd0(%rbp), %rdi
leaq 0x40c8(%rip), %rsi      # 0xb157
callq 0x3290
movq %rax, -0xd8(%rbp)
jmp 0x709d
movq -0xd8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3270
movq %rax, -0xe0(%rbp)
jmp 0x70b6
movq -0xe0(%rbp), %rdi
movq 0x8ef4(%rip), %rsi      # 0xffb8
callq 0x32d0
jmp 0x70cb
movl -0x1c(%rbp), %esi
leaq -0x90(%rbp), %rdi
movl $0x6, %edx
callq 0x4b60
jmp 0x70e1
movq 0x8ee8(%rip), %rdi      # 0xffd0
leaq 0x4075(%rip), %rsi      # 0xb164
callq 0x3290
movq %rax, -0xe8(%rbp)
jmp 0x70fd
movq -0xe8(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x3270
movq %rax, -0xf0(%rbp)
jmp 0x7119
movq -0xf0(%rbp), %rdi
movq 0x8e91(%rip), %rsi      # 0xffb8
callq 0x32d0
jmp 0x712e
movb $0x0, -0x91(%rbp)
leaq -0x92(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x3460
movq -0xb8(%rbp), %rdi
movq -0xf8(%rbp), %rdx
leaq 0x3f87(%rip), %rsi      # 0xb0e4
callq 0x7630
jmp 0x7164
leaq -0x92(%rbp), %rdi
callq 0x32f0
movl $0x0, -0x98(%rbp)
cmpl $0x20, -0x98(%rbp)
jge 0x7225
movq -0xb8(%rbp), %rdi
leaq 0x3eeb(%rip), %rsi      # 0xb080
callq 0x3280
jmp 0x719c
jmp 0x719e
movl -0x98(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x98(%rbp)
jmp 0x717a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x31c0
jmp 0x72d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x72cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x72bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x92(%rbp), %rdi
callq 0x32f0
jmp 0x72bf
movq -0xb8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
callq 0x31c0
jmp 0x72bf
movq -0xb8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x6, %edx
leaq -0x90(%rbp), %rcx
callq 0x30c0
jmp 0x7243
movq -0xb8(%rbp), %rdi
movl $0xd, %esi
movl $0x4, %edx
leaq -0x40(%rbp), %rcx
callq 0x30c0
jmp 0x725f
movq -0xb8(%rbp), %rdi
leaq 0x3e15(%rip), %rcx      # 0xb082
movl $0x1f, %esi
movl $0x1, %edx
callq 0x31a0
jmp 0x727e
movb $0x1, -0x91(%rbp)
testb $0x1, -0x91(%rbp)
jne 0x729a
movq -0xb8(%rbp), %rdi
callq 0x31c0
leaq -0x90(%rbp), %rdi
callq 0x31c0
leaq -0x40(%rbp), %rdi
callq 0x31c0
movq -0xb0(%rbp), %rax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
leaq -0x90(%rbp), %rdi
callq 0x31c0
leaq -0x40(%rbp), %rdi
callq 0x31c0
movq -0x68(%rbp), %rdi
callq 0x3450
nopl (%rax)