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

	// print the message for user
	cout << "Message: Display all memory." << endl;
	
	// the memory array
	unsigned char* memory = (*microcontroller)->getMemory();

	// the memory size
	int memorySize = (*microcontroller)->getMemorySize();

	// loop through the memory array and display
	for (int i = 0; i < memorySize; ++i)
	{
		// special case: add new line and print the left-most value
		if((i % 16) == 0){
			cout << endl;
			cout << std::setfill('0') << std::setw(4);
			cout << hex << i;
			cin.clear();
		}

		// special case: current column is column 8, print one more extra space
		if((i % 8) == 0){
			cout << " ";
		}

		// normal case: print the value in that memory address
		cout << " ";
		cout << std::setfill('0') << std::setw(2);
		int value = memory[i];
		cout << hex << value;
		cin.clear();
	}

	cout << endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r15
movq 0x85d5(%rip), %rbx      # 0xafc8
leaq 0x4a1f(%rip), %rsi      # 0x7419
movl $0x1c, %edx
movq %rbx, %rdi
callq 0x2190
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20e0
movq (%r15), %rdi
callq 0x375e
movq %rax, %r14
movq (%r15), %rdi
callq 0x3764
testl %eax, %eax
jle 0x2ba4
movl %eax, %ebp
xorl %r15d, %r15d
movq 0x8583(%rip), %r12      # 0xafd8
testb $0xf, %r15b
jne 0x2af7
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20e0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
leaq (%rbx,%rcx), %r13
cmpb $0x0, 0xe1(%rbx,%rcx)
jne 0x2ab3
movq %r13, %rdi
movl $0x20, %esi
callq 0x2150
movb $0x1, 0xe1(%r13)
movq (%rbx), %rax
movb $0x30, 0xe0(%r13)
movq -0x18(%rax), %rcx
movq $0x4, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %rbx, %rdi
movl %r15d, %esi
callq 0x2230
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
xorl %esi, %esi
callq 0x2220
testb $0x7, %r15b
jne 0x2b11
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x489a(%rip), %rsi      # 0x73a6
callq 0x2190
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x4886(%rip), %rsi      # 0x73a6
callq 0x2190
movq (%rbx), %rax
movq -0x18(%rax), %rcx
leaq (%rbx,%rcx), %r13
cmpb $0x0, 0xe1(%rbx,%rcx)
jne 0x2b52
movq %r13, %rdi
movl $0x20, %esi
callq 0x2150
movb $0x1, 0xe1(%r13)
movq (%rbx), %rax
movb $0x30, 0xe0(%r13)
movq -0x18(%rax), %rcx
movq $0x2, 0x10(%rbx,%rcx)
movzbl (%r14,%r15), %esi
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq %rbx, %rdi
callq 0x2230
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
xorl %esi, %esi
callq 0x2220
incq %r15
cmpq %r15, %rbp
jne 0x2a55
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x20e0