// File: akshayrajput[P]ARMV8_Simulator/./instructions.cpp
// Function: SUB(int, int, int, int, int)
void SUB(int sf, int sw,int op1, int op2, int op3 )
{
	//op1 - RD , op2 - RN , op3 - immRM
    if(sf) //use 64 bit register
    {
        if(sw == 0) //immediate
        {
            printf("[log] - subracting immediate 64 bit\n");
            uint64_t dat;
            dat = R[op2].getData() - op3; 
            R[op1].setData(dat);
        }
        
        if (sw == 1)    //register
        {
            printf("[log] - subracting register 64 bit\n");
            uint64_t dat;
            dat = R[op2].getData() - R[op3].getData();
            R[op1].setData(dat);
        }
    }
    
    else    //use 32 bit register
    {
         if(sw == 0) //immediate
        {
            printf("[log] - subracting immediate 32 bit\n");
            uint64_t dat;
            dat = R[op2].getLowerData() - op3; 
            R[op1].setLowerData(dat);
        }
        
        if (sw == 1)    //register
        {
            printf("[log] - subracting register 32 bit\n");
            int dat;
            dat = R[op2].getLowerData() - R[op3].getLowerData();
            R[op1].setLowerData(dat);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
movl %ecx, -0x10(%rbp)
movl %r8d, -0x14(%rbp)
cmpl $0x0, -0x4(%rbp)
je 0x22b7
cmpl $0x0, -0x8(%rbp)
jne 0x2243
leaq 0x9144(%rip), %rdi      # 0xb343
movb $0x0, %al
callq 0x1030
movslq -0x10(%rbp), %rax
leaq 0xbecf(%rip), %rdi      # 0xe0e0
shlq $0x3, %rax
addq %rax, %rdi
callq 0xa6c0
movslq -0x14(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x20(%rbp)
movslq -0xc(%rbp), %rax
leaq 0xbead(%rip), %rdi      # 0xe0e0
shlq $0x3, %rax
addq %rax, %rdi
movq -0x20(%rbp), %rsi
callq 0xa710
cmpl $0x1, -0x8(%rbp)
jne 0x22b2
leaq 0x9118(%rip), %rdi      # 0xb368
movb $0x0, %al
callq 0x1030
movslq -0x10(%rbp), %rax
leaq 0xbe7e(%rip), %rdi      # 0xe0e0
shlq $0x3, %rax
addq %rax, %rdi
callq 0xa6c0
movq %rax, -0x40(%rbp)
movslq -0x14(%rbp), %rax
leaq 0xbe63(%rip), %rdi      # 0xe0e0
shlq $0x3, %rax
addq %rax, %rdi
callq 0xa6c0
movq %rax, %rcx
movq -0x40(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x28(%rbp)
movslq -0xc(%rbp), %rax
leaq 0xbe3e(%rip), %rdi      # 0xe0e0
shlq $0x3, %rax
addq %rax, %rdi
movq -0x28(%rbp), %rsi
callq 0xa710
jmp 0x2373
cmpl $0x0, -0x8(%rbp)
jne 0x2308
leaq 0x90c8(%rip), %rdi      # 0xb38c
movb $0x0, %al
callq 0x1030
movslq -0x10(%rbp), %rax
leaq 0xbe0a(%rip), %rdi      # 0xe0e0
shlq $0x3, %rax
addq %rax, %rdi
callq 0xa6e0
subl -0x14(%rbp), %eax
movl %eax, %eax
movq %rax, -0x30(%rbp)
movslq -0xc(%rbp), %rax
leaq 0xbdea(%rip), %rdi      # 0xe0e0
shlq $0x3, %rax
addq %rax, %rdi
movq -0x30(%rbp), %rax
movl %eax, %esi
callq 0xa730
cmpl $0x1, -0x8(%rbp)
jne 0x2371
leaq 0x909c(%rip), %rdi      # 0xb3b1
movb $0x0, %al
callq 0x1030
movslq -0x10(%rbp), %rax
leaq 0xbdb9(%rip), %rdi      # 0xe0e0
shlq $0x3, %rax
addq %rax, %rdi
callq 0xa6e0
movl %eax, -0x44(%rbp)
movslq -0x14(%rbp), %rax
leaq 0xbd9f(%rip), %rdi      # 0xe0e0
shlq $0x3, %rax
addq %rax, %rdi
callq 0xa6e0
movl %eax, %ecx
movl -0x44(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x34(%rbp)
movslq -0xc(%rbp), %rax
leaq 0xbd7e(%rip), %rdi      # 0xe0e0
shlq $0x3, %rax
addq %rax, %rdi
movl -0x34(%rbp), %esi
callq 0xa730
jmp 0x2373
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)