// File: /workspace/github_cpp_makefile_star2_O1/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 0x8606(%rip), %rbx      # 0xafc8
leaq 0x4a50(%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 0x372e
movq %rax, %r14
movq (%r15), %rdi
callq 0x3734
testl %eax, %eax
jle 0x2b81
movl %eax, %ebp
xorl %r15d, %r15d
movq 0x85b4(%rip), %r12      # 0xafd8
testb $0xf, %r15b
jne 0x2acd
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), %rax
leaq (%rbx,%rax), %r13
cmpb $0x0, 0xe1(%rbx,%rax)
jne 0x2a86
movq %r13, %rdi
movl $0x20, %esi
callq 0x2150
movb %al, 0xe0(%r13)
movb $0x1, 0xe1(%r13)
movb $0x30, 0xe0(%r13)
movq (%rbx), %rax
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 0x2ae7
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x48c4(%rip), %rsi      # 0x73a6
callq 0x2190
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x48b0(%rip), %rsi      # 0x73a6
callq 0x2190
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %r13
cmpb $0x0, 0xe1(%rbx,%rax)
jne 0x2b2c
movq %r13, %rdi
movl $0x20, %esi
callq 0x2150
movb %al, 0xe0(%r13)
movb $0x1, 0xe1(%r13)
movb $0x30, 0xe0(%r13)
movq (%rbx), %rax
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 0x2a24
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