// File: ELD[P]HackAssembler/src/parser.cpp
// Function: hack::Parser::translateAssembly(std::ostream&)
void Parser::translateAssembly(std::ostream& oss)
    {
        collectLabels();
        while (advance()) {
            if (_currentCommand == "GARBAGE") {
                return;
            }

            if (commandType() == A_COMMAND) {
                int value;

                try {
                    value = stoi(getSymbol());
                } catch (std::invalid_argument exc) {
                    if (_symbols.contains(getSymbol())) {
                        value = _symbols.retrieveSymbol(getSymbol());
                    } else {
                        value = _mem;
                        _symbols.addSymbol(getSymbol(), _mem);
                        ++_mem;
                    }
                }

                oss << "0" + translateACode(value) << std::endl;
            } else if (commandType() == C_COMMAND) {
                oss << "111" + getCompBits() + getDestBits() + getJumpBits() << std::endl;
            }
        }
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
callq 0xb2b0
movq -0x1c0(%rbp), %rdi
callq 0xa4e0
testb $0x1, %al
jne 0xb3f8
jmp 0xb908
movq -0x1c0(%rbp), %rdi
addq $0x8, %rdi
leaq 0x2ee0b(%rip), %rsi     # 0x3a215
callq 0xba70
testb $0x1, %al
jne 0xb415
jmp 0xb41a
jmp 0xb908
movq -0x1c0(%rbp), %rdi
callq 0xa6c0
cmpl $0x1, %eax
jne 0xb72c
movq -0x1c0(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0xa960
jmp 0xb441
xorl %eax, %eax
movl %eax, %esi
leaq -0x38(%rbp), %rdi
movl $0xa, %edx
callq 0xbf90
movl %eax, -0x1c4(%rbp)
jmp 0xb45b
movl -0x1c4(%rbp), %eax
movl %eax, -0x14(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x62b0
jmp 0xb64e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xb495
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x62b0
movl -0x44(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0xb911
movq -0x40(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x6520
movq %rax, %rsi
leaq -0x58(%rbp), %rdi
callq 0xbfd0
movq -0x1d8(%rbp), %rdi
callq 0x6180
movq -0x1c0(%rbp), %rsi
movq %rsi, %rax
addq $0x78, %rax
movq %rax, -0x1d0(%rbp)
leaq -0x78(%rbp), %rdi
callq 0xa960
jmp 0xb4ed
movq -0x1d0(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x38990
movb %al, -0x1d9(%rbp)
jmp 0xb505
leaq -0x78(%rbp), %rdi
callq 0x62b0
movb -0x1d9(%rbp), %al
testb $0x1, %al
jne 0xb51d
jmp 0xb5bd
movq -0x1c0(%rbp), %rsi
movq %rsi, %rax
addq $0x78, %rax
movq %rax, -0x1e8(%rbp)
leaq -0x98(%rbp), %rdi
callq 0xa960
jmp 0xb540
movq -0x1e8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x389e0
movl %eax, -0x1ec(%rbp)
jmp 0xb55b
movl -0x1ec(%rbp), %eax
movl %eax, -0x14(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x62b0
jmp 0xb640
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xb6e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x62b0
jmp 0xb6e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x62b0
jmp 0xb6e0
movq -0x1c0(%rbp), %rsi
movl 0x74(%rsi), %eax
movl %eax, -0x14(%rbp)
movq %rsi, %rax
addq $0x78, %rax
movq %rax, -0x1f8(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0xa960
jmp 0xb5e6
movq -0x1f8(%rbp), %rdi
movq -0x1c0(%rbp), %rax
movl 0x74(%rax), %edx
leaq -0xb8(%rbp), %rsi
callq 0x38900
jmp 0xb605
leaq -0xb8(%rbp), %rdi
callq 0x62b0
movq -0x1c0(%rbp), %rax
movl 0x74(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x74(%rax)
jmp 0xb640
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x62b0
jmp 0xb6e0
leaq -0x58(%rbp), %rdi
callq 0x6670
callq 0x6650
movq -0x1c0(%rbp), %rsi
movq -0x10(%rbp), %rax
movq %rax, -0x208(%rbp)
movl -0x14(%rbp), %edx
leaq -0xf8(%rbp), %rdi
movq %rdi, -0x200(%rbp)
callq 0xb1f0
movq -0x200(%rbp), %rdx
leaq 0x2fa48(%rip), %rsi     # 0x3b0cc
leaq -0xd8(%rbp), %rdi
callq 0xc010
jmp 0xb692
movq -0x208(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x63c0
movq %rax, -0x210(%rbp)
jmp 0xb6ae
movq -0x210(%rbp), %rdi
movq 0x498c4(%rip), %rsi     # 0x54f80
callq 0x6460
jmp 0xb6c3
leaq -0xd8(%rbp), %rdi
callq 0x62b0
leaq -0xf8(%rbp), %rdi
callq 0x62b0
jmp 0xb903
leaq -0x58(%rbp), %rdi
callq 0x6670
callq 0x6650
jmp 0xb6f0
jmp 0xb911
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xb71b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x62b0
leaq -0xf8(%rbp), %rdi
callq 0x62b0
jmp 0xb911
movq -0x1c0(%rbp), %rdi
callq 0xa6c0
cmpl $0x2, %eax
jne 0xb901
movq -0x1c0(%rbp), %rsi
movq -0x10(%rbp), %rax
movq %rax, -0x220(%rbp)
leaq -0x178(%rbp), %rdi
movq %rdi, -0x218(%rbp)
callq 0xac70
movq -0x218(%rbp), %rdx
leaq 0x2f94b(%rip), %rsi     # 0x3b0bf
leaq -0x158(%rbp), %rdi
callq 0xc010
jmp 0xb782
movq -0x1c0(%rbp), %rsi
leaq -0x198(%rbp), %rdi
callq 0xaa90
jmp 0xb797
leaq -0x138(%rbp), %rdi
leaq -0x158(%rbp), %rsi
leaq -0x198(%rbp), %rdx
callq 0xc060
jmp 0xb7b3
movq -0x1c0(%rbp), %rsi
leaq -0x1b8(%rbp), %rdi
callq 0xb000
jmp 0xb7c8
leaq -0x118(%rbp), %rdi
leaq -0x138(%rbp), %rsi
leaq -0x1b8(%rbp), %rdx
callq 0xc060
jmp 0xb7e4
movq -0x220(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x63c0
movq %rax, -0x228(%rbp)
jmp 0xb800
movq -0x228(%rbp), %rdi
movq 0x49772(%rip), %rsi     # 0x54f80
callq 0x6460
jmp 0xb815
leaq -0x118(%rbp), %rdi
callq 0x62b0
leaq -0x1b8(%rbp), %rdi
callq 0x62b0
leaq -0x138(%rbp), %rdi
callq 0x62b0
leaq -0x198(%rbp), %rdi
callq 0x62b0
leaq -0x158(%rbp), %rdi
callq 0x62b0
leaq -0x178(%rbp), %rdi
callq 0x62b0
jmp 0xb901
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xb8f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xb8e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xb8db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xb8cf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xb8c3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x62b0
leaq -0x1b8(%rbp), %rdi
callq 0x62b0
leaq -0x138(%rbp), %rdi
callq 0x62b0
leaq -0x198(%rbp), %rdi
callq 0x62b0
leaq -0x158(%rbp), %rdi
callq 0x62b0
leaq -0x178(%rbp), %rdi
callq 0x62b0
jmp 0xb911
jmp 0xb903
jmp 0xb3e3
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x6710
movq %rax, %rdi
callq 0x84b0
nopw %cs:(%rax,%rax)