// File: 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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq 0xb465(%rip), %rdi      # 0xefc8
leaq 0x68af(%rip), %rsi      # 0xa419
callq 0x31e0
movq %rax, %rdi
movq 0xb43f(%rip), %rsi      # 0xefb8
callq 0x3220
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x4d70
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x4d90
movl %eax, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x3d12
movl -0x18(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x3c4b
movq 0xb3fd(%rip), %rdi      # 0xefc8
movq 0xb3e6(%rip), %rsi      # 0xefb8
callq 0x3220
movl $0x30, %edi
callq 0x4450
movb %al, -0x19(%rbp)
movq 0xb3dd(%rip), %rdi      # 0xefc8
movzbl -0x19(%rbp), %esi
callq 0x3310
movq %rax, -0x38(%rbp)
movl $0x4, %edi
callq 0x4470
movq -0x38(%rbp), %rdi
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %esi
callq 0x3270
movq 0xb3b0(%rip), %rdi      # 0xefc8
leaq 0x801(%rip), %rsi       # 0x4420
callq 0x3090
movq %rax, %rdi
movl -0x18(%rbp), %esi
callq 0x3350
movq 0xb3a2(%rip), %rax      # 0xefd8
movq (%rax), %rax
movq 0xb398(%rip), %rdi      # 0xefd8
addq -0x18(%rax), %rdi
xorl %esi, %esi
callq 0x3340
movl -0x18(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x3c6e
movq 0xb366(%rip), %rdi      # 0xefc8
leaq 0x673d(%rip), %rsi      # 0xa3a6
callq 0x31e0
movq 0xb353(%rip), %rdi      # 0xefc8
leaq 0x672a(%rip), %rsi      # 0xa3a6
callq 0x31e0
movl $0x30, %edi
callq 0x4450
movb %al, -0x21(%rbp)
movq 0xb333(%rip), %rdi      # 0xefc8
movzbl -0x21(%rbp), %esi
callq 0x3310
movq %rax, -0x40(%rbp)
movl $0x2, %edi
callq 0x4470
movq -0x40(%rbp), %rdi
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %esi
callq 0x3270
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x2c(%rbp)
movq 0xb2f7(%rip), %rdi      # 0xefc8
leaq 0x748(%rip), %rsi       # 0x4420
callq 0x3090
movq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x3350
movq 0xb2e9(%rip), %rax      # 0xefd8
movq (%rax), %rax
movq 0xb2df(%rip), %rdi      # 0xefd8
addq -0x18(%rax), %rdi
xorl %esi, %esi
callq 0x3340
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x3ba4
movq 0xb2af(%rip), %rdi      # 0xefc8
movq 0xb298(%rip), %rsi      # 0xefb8
callq 0x3220
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)