// File: /workspace/github_cpp_makefile_star2_O2/QFSW[P]MIPS1-Simulator/src/MemoryMap.hpp
// Function: void Clarkitechture::MIPS::MemoryMap::write<unsigned short>(unsigned long, unsigned short)
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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %r14
testb $0x1, %r14b
jne 0x7242
movq %r14, %rax
andq $-0x4, %rax
cmpq $0x30000004, %rax       # imm = 0x30000004
jne 0x71ef
xorl %eax, %eax
cmpq $0x30000006, %r14       # imm = 0x30000006
movzwl %dx, %edi
cmovnel %eax, %edi
callq 0x52d0
cmpl $-0x1, %eax
jne 0x71e0
movq 0x9df8(%rip), %rax      # 0x10fc8
movq (%rax), %rdi
callq 0x53c0
testl %eax, %eax
jne 0x72e1
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rax
andq $-0x4000000, %rax       # imm = 0xFC000000
cmpq $0x20000000, %rax       # imm = 0x20000000
jne 0x7293
movq %rdi, %rbx
movzwl %dx, %r12d
addl $0xe0000000, %r14d      # imm = 0xE0000000
pushq $0x8
popq %rbp
leaq 0x4(%rsp), %r15
cmpl $-0x8, %ebp
je 0x71e0
movl %r12d, %r13d
movl %ebp, %ecx
shrl %cl, %r13d
movl %r14d, 0x4(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x7440
movb %r13b, (%rax)
addl $-0x8, %ebp
incl %r14d
jmp 0x721a
pushq $0x50
popq %rdi
callq 0x50f0
movq %rax, %rbx
leaq 0x31e6(%rip), %rsi      # 0xa43a
leaq 0x48(%rsp), %rdi
leaq 0x4(%rsp), %rdx
callq 0x67c8
movb $0x1, %bpl
leaq 0x48(%rsp), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5722
xorl %ebp, %ebp
leaq 0x8b29(%rip), %rsi      # 0xfda8
leaq -0x134a(%rip), %rdx     # 0x5f3c
movq %rbx, %rdi
callq 0x5360
jmp 0x732f
pushq $0x50
popq %rdi
callq 0x50f0
movq %rax, %rbx
leaq 0x3162(%rip), %rsi      # 0xa407
leaq 0x8(%rsp), %rdi
leaq 0x4(%rsp), %rdx
callq 0x67c8
movb $0x1, %bpl
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5722
xorl %ebp, %ebp
leaq 0x8ad8(%rip), %rsi      # 0xfda8
leaq -0x139b(%rip), %rdx     # 0x5f3c
movq %rbx, %rdi
callq 0x5360
jmp 0x732f
movl %eax, %ebp
pushq $0x50
popq %rdi
callq 0x50f0
movq %rax, %rbx
leaq 0x3167(%rip), %rsi      # 0xa45c
leaq 0x28(%rsp), %rdi
leaq 0x4(%rsp), %rdx
callq 0x67c8
movb $0x1, %r15b
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x5a62
xorl %r15d, %r15d
leaq 0x8ad0(%rip), %rsi      # 0xfdf0
leaq -0x1349(%rip), %rdx     # 0x5fde
movq %rbx, %rdi
callq 0x5360
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x50d0
testb %r15b, %r15b
jne 0x7368
jmp 0x7370
jmp 0x7365
movq %rax, %r14
leaq 0x8(%rsp), %rdi
jmp 0x7359
jmp 0x7365
movq %rax, %r14
leaq 0x48(%rsp), %rdi
callq 0x50d0
testb %bpl, %bpl
jne 0x7368
jmp 0x7370
movq %rax, %r14
movq %rbx, %rdi
callq 0x5170
movq %r14, %rdi
callq 0x5390