// File: /workspace/github_cpp_makefile_star2_O3/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 %r12
pushq %rbx
subq $0x70, %rsp
movq %rsi, %r14
testb $0x1, %r14b
jne 0x7cf3
movl %edx, %ebx
movq %r14, %rax
andq $-0x4, %rax
cmpq $0x30000004, %rax       # imm = 0x30000004
jne 0x7c9c
xorl %eax, %eax
cmpq $0x30000006, %r14       # imm = 0x30000006
movzwl %bx, %edi
cmovnel %eax, %edi
callq 0x52e0
cmpl $-0x1, %eax
jne 0x7ce6
movq 0x939c(%rip), %rax      # 0x10fc8
movq (%rax), %rdi
callq 0x53e0
testl %eax, %eax
je 0x7ce6
movl %eax, %ebp
movl $0x50, %edi
callq 0x5100
movq %rax, %rbx
leaq 0x40(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x3801(%rip), %rsi      # 0xb45c
leaq 0x3800(%rip), %rdx      # 0xb462
leaq 0x30(%rsp), %rdi
callq 0x7e20
movb $0x1, %r12b
leaq 0x30(%rsp), %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x5ef2
xorl %r12d, %r12d
leaq 0x8160(%rip), %rsi      # 0xfde8
leaq -0x142d(%rip), %rdx     # 0x6862
movq %rbx, %rdi
callq 0x5380
jmp 0x7da7
movq %r14, %rax
andq $-0x4000000, %rax       # imm = 0xFC000000
cmpq $0x20000000, %rax       # imm = 0x20000000
jne 0x7d4e
movq %rdi, %r15
leal -0x20000000(%r14), %eax
leaq 0xc(%rsp), %r12
movl %eax, (%r12)
movq %r12, %rsi
callq 0x7eb6
movb %bh, (%rax)
addl $0xe0000001, %r14d      # imm = 0xE0000001
movl %r14d, (%r12)
movq %r15, %rdi
movq %r12, %rsi
callq 0x7eb6
movb %bl, (%rax)
addq $0x70, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl $0x50, %edi
callq 0x5100
movq %rax, %rbx
leaq 0x60(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x372a(%rip), %rsi      # 0xb43a
leaq 0x3744(%rip), %rdx      # 0xb45b
leaq 0x50(%rsp), %rdi
callq 0x7e20
movb $0x1, %bpl
leaq 0x50(%rsp), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x58ea
xorl %ebp, %ebp
leaq 0x8063(%rip), %rsi      # 0xfda0
leaq -0x16f2(%rip), %rdx     # 0x6652
movq %rbx, %rdi
callq 0x5380
jmp 0x7da7
movl $0x50, %edi
callq 0x5100
movq %rax, %rbx
leaq 0x20(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x369c(%rip), %rsi      # 0xb407
leaq 0x36c7(%rip), %rdx      # 0xb439
leaq 0x10(%rsp), %rdi
callq 0x7e20
movb $0x1, %bpl
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x58ea
xorl %ebp, %ebp
leaq 0x8008(%rip), %rsi      # 0xfda0
leaq -0x174d(%rip), %rdx     # 0x6652
movq %rbx, %rdi
callq 0x5380
movq %rax, %r14
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x7dc1
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x5210
testb %r12b, %r12b
jne 0x7e04
jmp 0x7e0c
jmp 0x7e01
movq %rax, %r14
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x7dfa
movq 0x20(%rsp), %rsi
jmp 0x7df2
jmp 0x7e01
movq %rax, %r14
movq 0x50(%rsp), %rdi
cmpq %r15, %rdi
je 0x7dfa
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x5210
testb %bpl, %bpl
jne 0x7e04
jmp 0x7e0c
movq %rax, %r14
movq %rbx, %rdi
callq 0x5190
movq %r14, %rdi
callq 0x53a0