// File: QFSW[P]MIPS1-Simulator/src/MemoryMap.hpp
// Function: void Clarkitechture::MIPS::MemoryMap::write<unsigned int>(unsigned long, unsigned int)
void write(size_t address, T data)
            {
                if (address % sizeof(T) > 0) { throw BadMemoryAccess(address, "write data address was misaligned"); }
                else if (address >= ADDR_PUTC && address < ADDR_PUTC + 4)
                {
                    T val = address == ADDR_PUTC + 4 - sizeof(T) ? data : 0;
                    int ret = std::putchar(val);
                    if (ret == EOF)
                    {
                        int error = ferror(stdin);
                        if (error) { throw BadIO("stdout", error); }
                    }
                }
                else if (address >= ADDR_DATA && address < ADDR_DATA + ADDR_DATA_LENGTH)
                {
                    size_t memLocation = address - ADDR_DATA;
                    for (int i = 0; i < sizeof(T); i++)
                    {
                        int shamt = 8 * (sizeof(T) - i - 1);
                        memory[memLocation + i] = data >> shamt;
                    } 
                }
                else { throw BadMemoryAccess(address, "address was outside of the valid R/W memory range."); }
            }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x10(%rbp), %rax
andq $0x3, %rax
cmpq $0x0, %rax
jbe 0x9a8d
movb $0x1, -0x4d(%rbp)
movl $0x50, %edi
callq 0x6140
movq %rax, -0xe8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x64c0
movq -0xd8(%rbp), %rdx
leaq 0xaa39(%rip), %rsi      # 0x1443a
leaq -0x38(%rbp), %rdi
callq 0x8b50
jmp 0x9a0c
movq -0xe0(%rbp), %rsi
movq -0xe8(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq 0x6970
jmp 0x9a25
movq -0xe8(%rbp), %rdi
movb $0x0, -0x4d(%rbp)
leaq 0x12489(%rip), %rsi     # 0x1bec0
leaq -0x226e(%rip), %rdx     # 0x77d0
callq 0x6470
jmp 0x9d7f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x9a6b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x6190
leaq -0x39(%rbp), %rdi
callq 0x62e0
testb $0x1, -0x4d(%rbp)
jne 0x9a7c
jmp 0x9a88
movq -0xe8(%rbp), %rdi
callq 0x61f0
jmp 0x9d76
cmpq $0x30000004, -0x10(%rbp) # imm = 0x30000004
jb 0x9bd3
cmpq $0x30000008, -0x10(%rbp) # imm = 0x30000008
jae 0x9bd3
cmpq $0x30000004, -0x10(%rbp) # imm = 0x30000004
jne 0x9abe
movl -0x14(%rbp), %eax
movl %eax, -0xec(%rbp)
jmp 0x9ac8
xorl %eax, %eax
movl %eax, -0xec(%rbp)
jmp 0x9ac8
movl -0xec(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %edi
callq 0x63e0
movl %eax, -0x58(%rbp)
cmpl $-0x1, -0x58(%rbp)
jne 0x9bce
movq 0x134d3(%rip), %rax     # 0x1cfc0
movq (%rax), %rdi
callq 0x64f0
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x9bcc
movb $0x1, -0x82(%rbp)
movl $0x50, %edi
callq 0x6140
movq %rax, -0x100(%rbp)
leaq -0x81(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x64c0
movq -0xf8(%rbp), %rdx
leaq 0xa921(%rip), %rsi      # 0x1445c
leaq -0x80(%rbp), %rdi
callq 0x8b50
jmp 0x9b46
movq -0x100(%rbp), %rdi
movl -0x5c(%rbp), %edx
leaq -0x80(%rbp), %rsi
callq 0x6e20
jmp 0x9b5b
movq -0x100(%rbp), %rdi
movb $0x0, -0x82(%rbp)
leaq 0x12398(%rip), %rsi     # 0x1bf08
leaq -0x2257(%rip), %rdx     # 0x7920
callq 0x6470
jmp 0x9d7f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x9ba4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x6190
leaq -0x81(%rbp), %rdi
callq 0x62e0
testb $0x1, -0x82(%rbp)
jne 0x9bbb
jmp 0x9bc7
movq -0x100(%rbp), %rdi
callq 0x61f0
jmp 0x9d76
jmp 0x9bce
jmp 0x9d6b
cmpq $0x20000000, -0x10(%rbp) # imm = 0x20000000
jb 0x9c8d
cmpq $0x24000000, -0x10(%rbp) # imm = 0x24000000
jae 0x9c8d
movq -0x10(%rbp), %rax
subq $0x20000000, %rax       # imm = 0x20000000
movq %rax, -0x90(%rbp)
movl $0x0, -0x94(%rbp)
movslq -0x94(%rbp), %rax
cmpq $0x4, %rax
jae 0x9c88
movq -0xd0(%rbp), %rdi
movslq -0x94(%rbp), %rcx
movl $0x4, %eax
subq %rcx, %rax
subq $0x1, %rax
shlq $0x3, %rax
movl %eax, -0x98(%rbp)
movl -0x14(%rbp), %eax
movl -0x98(%rbp), %ecx
shrl %cl, %eax
movb %al, -0x101(%rbp)
movq -0x90(%rbp), %rax
movslq -0x94(%rbp), %rcx
addq %rcx, %rax
movl %eax, -0x9c(%rbp)
leaq -0x9c(%rbp), %rsi
callq 0xa710
movb -0x101(%rbp), %cl
movb %cl, (%rax)
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x9c0a
jmp 0x9d69
movb $0x1, -0xc2(%rbp)
movl $0x50, %edi
callq 0x6140
movq %rax, -0x120(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x118(%rbp)
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x64c0
movq -0x110(%rbp), %rdx
leaq 0xa736(%rip), %rsi      # 0x14407
leaq -0xc0(%rbp), %rdi
callq 0x8b50
jmp 0x9cdf
movq -0x118(%rbp), %rsi
movq -0x120(%rbp), %rdi
leaq -0xc0(%rbp), %rdx
callq 0x6970
jmp 0x9cfb
movq -0x120(%rbp), %rdi
movb $0x0, -0xc2(%rbp)
leaq 0x121b0(%rip), %rsi     # 0x1bec0
leaq -0x2547(%rip), %rdx     # 0x77d0
callq 0x6470
jmp 0x9d7f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x9d44
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x6190
leaq -0xc1(%rbp), %rdi
callq 0x62e0
testb $0x1, -0xc2(%rbp)
jne 0x9d5b
jmp 0x9d67
movq -0x120(%rbp), %rdi
callq 0x61f0
jmp 0x9d76
jmp 0x9d6b
jmp 0x9d6d
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x64b0
nop