// File: tmtxt[P]microcontroller-emulation/rotamola34hc22.cpp
// Function: mcontroller::Rotamola34HC22::executeBranchIfALessThanB(int)
void Rotamola34HC22::executeBranchIfALessThanB(int address){

		if((address + 3) < this->getMemorySize()){
			
			// compare the value of A and B
			if(this->getA() < this->getB()){

				// get the high byte and low byte address of the destination address
				unsigned char addressHighByte = this->getMemoryValueAtLocation(address + 1);
				unsigned char addressLowByte = this->getMemoryValueAtLocation(address + 2);

				// compute the destination address
				int destinationAddress = (addressHighByte << 8) | addressLowByte;

				if(destinationAddress >= 0 && destinationAddress < this->getMemorySize()){
					


					// set the program counter to the new address
					this->setProgramCounter(destinationAddress);

					cout << "Message: Execution completed." << endl;

				} else {
					cout << "Error: Invalid memory address." << endl;
					this->executeHalt(address);
				}
			
			} else {
			
				// set the program counter to the third byte after the opcode
				this->setProgramCounter(address + 3);
				cout << "Message: Execution completed." << endl;
			}
			
		} else {
			cerr << "Error: SIGWEED. Program executed past top of memory" << endl;
			this->executeHalt(address);
		}

	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x20(%rbp)
movl -0xc(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x18(%rbp)
callq 0x4d90
movl %eax, %ecx
movl -0x18(%rbp), %eax
cmpl %ecx, %eax
jge 0x6e6f
movq -0x20(%rbp), %rdi
callq 0x66c0
movq -0x20(%rbp), %rdi
movzbl %al, %eax
movl %eax, -0x24(%rbp)
callq 0x66e0
movb %al, %cl
movl -0x24(%rbp), %eax
movzbl %cl, %ecx
cmpl %ecx, %eax
jge 0x6e3c
movq -0x20(%rbp), %rdi
movl -0xc(%rbp), %esi
addl $0x1, %esi
callq 0x4df0
movq -0x20(%rbp), %rdi
movb %al, -0xd(%rbp)
movl -0xc(%rbp), %esi
addl $0x2, %esi
callq 0x4df0
movb %al, -0xe(%rbp)
movzbl -0xd(%rbp), %eax
shll $0x8, %eax
movzbl -0xe(%rbp), %ecx
orl %ecx, %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jl 0x6e0c
movq -0x20(%rbp), %rdi
movl -0x14(%rbp), %eax
movl %eax, -0x28(%rbp)
callq 0x4d90
movl %eax, %ecx
movl -0x28(%rbp), %eax
cmpl %ecx, %eax
jge 0x6e0c
movq -0x20(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x4dd0
movq 0x81d9(%rip), %rdi      # 0xefc8
leaq 0x38b6(%rip), %rsi      # 0xa6ac
callq 0x31e0
movq %rax, %rdi
movq 0x81b3(%rip), %rsi      # 0xefb8
callq 0x3220
jmp 0x6e3a
movq 0x81b5(%rip), %rdi      # 0xefc8
leaq 0x38e4(%rip), %rsi      # 0xa6fe
callq 0x31e0
movq %rax, %rdi
movq 0x818f(%rip), %rsi      # 0xefb8
callq 0x3220
movq -0x20(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x7030
jmp 0x6e6d
movq -0x20(%rbp), %rdi
movl -0xc(%rbp), %esi
addl $0x3, %esi
callq 0x4dd0
movq 0x8176(%rip), %rdi      # 0xefc8
leaq 0x3853(%rip), %rsi      # 0xa6ac
callq 0x31e0
movq %rax, %rdi
movq 0x8150(%rip), %rsi      # 0xefb8
callq 0x3220
jmp 0x6e9d
movq 0x817a(%rip), %rdi      # 0xeff0
leaq 0x384d(%rip), %rsi      # 0xa6ca
callq 0x31e0
movq %rax, %rdi
movq 0x812c(%rip), %rsi      # 0xefb8
callq 0x3220
movq -0x20(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x7030
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)