convert the following segment of c code to assmebly language

convert the following segment of c code to assmebly language

#include #define BUTTON1 ((P2IN & 0x02) == 0x00) #define BUTT0N2 ((P2IN & 0x04) == 0x00) #define BUTT0N3 ((P2IN & 0x08) == 0x00) #define BUTT0N4 ((P2IN & 0x10) == 0x00) #define B1 (PUN & 0x10) #define B2 (PUN & 0x20) #define B3 (P1IN & 0x40) #define B4 (P1IN & 0x80) #define YellowLedOn (P10UT | = 0x01) #define GreenLedOn (P10UT | = 0x02) #define RedLedOn (PlOUT |= 0x04) #define AllLedsOff (PlOUT & =^-0x07) void main(void){WDTCTL = WDTPW|WDTHOLD; int Control = 0; int NewPassword[4]; int YourPassword[4]; int EnterNewPassword = 0; int EnterYourPassword = 0; P2SEL = 0x00;

Solution

main:
        push    rbp
        mov     rbp, rsp
        mov     DWORD PTR [rbp-4], 0    # control=0
        mov     DWORD PTR [rbp-8], 0    # EnterPassword=0;
        mov     DWORD PTR [rbp-12], 0    # EnterYourPassword = 0;
.L4:
        cmp     DWORD PTR [rbp-4], 0    # if (control ==0)
        jne     .L2
        mov     DWORD PTR [rbp-8], 1   # EnterPassword = 1;
        cmp     DWORD PTR [rbp-8], 1   # if (EnterPassword == 1)
        jne     .L2
        mov     DWORD PTR [rbp-32], 0   # NewPassword[0] = B1;
        mov     DWORD PTR [rbp-28], 0   # NewPassword[1] = B2;
        mov     DWORD PTR [rbp-24], 0   # NewPassword[2] = B3;
        mov     DWORD PTR [rbp-20], 0   # NewPassword[3] = B4;
        mov     DWORD PTR [rbp-8], 0   # EnterPassword=0;
        mov     DWORD PTR [rbp-4], 1   # control = 1;
.L2:
        cmp     DWORD PTR [rbp-4], 1   # if (control ==1)
        jne     .L4
        mov     DWORD PTR [rbp-12], 1   # EnterYourPassword = 1;
        cmp     DWORD PTR [rbp-12], 1    # # if (EnterYourPassword == 1)
        jne     .L4
        mov     DWORD PTR [rbp-48], 0   # YourPassword[0] = B1;
        mov     DWORD PTR [rbp-44], 0   # YourPassword[1] = B2;
        mov     DWORD PTR [rbp-40], 0   # YourPassword[2] = B3;
        mov     DWORD PTR [rbp-36], 0   # YourPassword[3] = B4;
        mov     DWORD PTR [rbp-12], 0   # EnterYourPassword=0;
        mov     edx, DWORD PTR [rbp-48] # move YourPassword[0]
        mov     eax, DWORD PTR [rbp-32] # move NewPassword[0]
        cmp     edx, eax               # compare YourPassword[0] == NewPassword[0]
        jne     .L4
        mov     edx, DWORD PTR [rbp-44] # move YourPassword[1]
        mov     eax, DWORD PTR [rbp-28] # move NewPassword[1]
        cmp     edx, eax               # compare YourPassword[1] == NewPassword[1]
        jne     .L4
        mov     edx, DWORD PTR [rbp-40] # move YourPassword[2]
        mov     eax, DWORD PTR [rbp-24] # move NewPassword[2]
        cmp     edx, eax               # compare YourPassword[2] == NewPassword[2]
        jmp     .L4
       mov     edx, DWORD PTR [rbp-36] # move YourPassword[3]
        mov     eax, DWORD PTR [rbp-20] # move NewPassword[3]
        cmp     edx, eax               # compare YourPassword[3] == NewPassword[3]
        jmp     .L4
using gcc 6.3

convert the following segment of c code to assmebly language #include #define BUTTON1 ((P2IN & 0x02) == 0x00) #define BUTT0N2 ((P2IN & 0x04) == 0x00) #d

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site