// File: /workspace/github_cpp_makefile_star2_O2/tmtxt[P]microcontroller-emulation/main.cpp
// Function: optionModifyMemoryHandler(mcontroller::Microcontroller**)
void optionModifyMemoryHandler(mcontroller::Microcontroller** microcontroller){

	// display the message for user
	cout << "Message: Modify memory." << endl;
	cout << "Message: Enter the memory location to modify (hexadeciaml format)." << endl;
	
	// The input memory address
	int location;

	// input address from user
	location = (*microcontroller)->lookUpMemoryAddress();

	// check if the location is valid
	if(location != Microcontroller::memoryLocationInvalid){
		// print the old value
		unsigned int oldValue = (*microcontroller)->getMemoryValueAtLocation(location);
		cout << "Message: Old value: ";
		cout << hex << oldValue;
		cout << endl;

		// print the message
		cout << "Message: Enter the new value (hexadecimal format)." << endl;
		cout << "new? ";

		// read the input value from user
		unsigned int inputNewValue;
		// validate input
		while(!(cin >> hex >> inputNewValue)){
			cerr << "Error: Please input a valid hexadecimal integer!" << endl;
			cin.clear();
			cin.ignore(1000, '\n');
			cout << "news? ";
		}

		// As each memory location is a byte size (unsigned char), only the
		// lower 8 bits of input should be stored.
		unsigned char newValue = (inputNewValue & 0xFF);
		(*microcontroller)->setMemoryValueAtLocation(location, newValue);

		// clear the cin
		cin.clear();
		cin.ignore(1000, '\n');
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x64ed(%rip), %r14      # 0x8fc8
leaq 0x2856(%rip), %rsi      # 0x5338
movq %r14, %rdi
callq 0x2170
movq %rax, %rdi
callq 0x20b0
leaq 0x2857(%rip), %rsi      # 0x5350
movq %r14, %rdi
callq 0x2170
movq %rax, %rdi
callq 0x20b0
movq (%rbx), %rdi
callq 0x3000
cmpl $-0x1, %eax
je 0x2c5d
movq %rbx, 0x10(%rsp)
movq (%rbx), %rdi
movl %eax, 0x8(%rsp)
movl %eax, %esi
callq 0x2fd6
movl %eax, %ebx
leaq 0x285d(%rip), %rsi      # 0x5393
movq %r14, %rdi
callq 0x2170
movq (%r14), %rax
movq -0x18(%rax), %rax
movl 0x18(%r14,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%r14,%rax)
movzbl %bl, %esi
movq %r14, %rdi
callq 0x20e0
movq %r14, %rdi
callq 0x20b0
leaq 0x2839(%rip), %rsi      # 0x53a8
movq %r14, %rdi
callq 0x2170
movq %rax, %rdi
callq 0x20b0
leaq 0x2855(%rip), %rsi      # 0x53db
movq %r14, %rdi
callq 0x2170
movq 0x6443(%rip), %r15      # 0x8fd8
leaq 0xc(%rsp), %r12
movq 0x644f(%rip), %r13      # 0x8ff0
leaq 0x2839(%rip), %rbx      # 0x53e1
pushq $0xa
popq %rbp
leaq 0x2860(%rip), %r14      # 0x5412
movq (%r15), %rax
movq -0x18(%rax), %rax
movl 0x18(%r15,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%r15,%rax)
movq %r15, %rdi
movq %r12, %rsi
callq 0x2270
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
je 0x2c26
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2170
movq %rax, %rdi
callq 0x20b0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
xorl %esi, %esi
callq 0x2250
movl $0x3e8, %esi            # imm = 0x3E8
movq %r15, %rdi
movl %ebp, %edx
callq 0x20d0
movq 0x63ac(%rip), %rdi      # 0x8fc8
movq %r14, %rsi
callq 0x2170
jmp 0x2bb2
movzbl 0xc(%rsp), %edx
movq 0x10(%rsp), %rax
movq (%rax), %rdi
movl 0x8(%rsp), %esi
callq 0x2fec
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
xorl %esi, %esi
callq 0x2250
pushq $0xa
popq %rdx
movl $0x3e8, %esi            # imm = 0x3E8
movq %r15, %rdi
callq 0x20d0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq