Exit branch and continue rest of code in ARM assembly (for home security system)

40 views Asked by At

I am working on a home security system in ARM assembly, where the system is enabled by a switch. Upon activation, it's ready to detect motion and requires the user to input a specific sequence of keys. If the sequence is incorrect (e.g., a wrong button is pressed), a red LED should light up, and if it's correct, a green LED lights up once while a white LED turns on permanently.

I'm struggling with the part of my code that handles an incorrect pin input. Here's the relevant section:

wrong
        MOV R6, #0x01; wrong key

I want to know how to exit from the 'wrong' branch and continue the rest of the code if an incorrect key is entered. Also, I'm seeking advice on whether I'm moving in the right direction with my current approach.

This is all of the code:

area Final, code, readonly
        export __main
__main  proc
    
    LDR R0,=0x40004C21 ;port 4 inputs
    LDR R1,=0x40004C40 ;port 5 outputs
    
    MOV R2, #0x00 ; all pin as input in DDIR
    STRB R2, [R0, #0x04]; 
    MOV R2, #0xFF ;all input pins as ren enabled
    STRB R2, [R0, #0x06]; 
    MOV R2, #0xFF ;all input pins as pullup
    STRB R2, [R0, #0x02]; 
    
    MOV R3, #0xFF ; all pin as output in DDIR
    STRB R3, [R1, #0x04]; port 5 is all outputs
    
repeat  
enable  LDRB R2, [R0, #0x00] ;load input regsiter
        AND R4,R2,#0x01 ; check if pin 0 is enabled 
        CMP R4, #0x00
        BEQ motion
        
motion  LDRB R2, [R0, #0x00] ;load input regsiter
        AND R4,R2,#0x02 ; check if pin 1 is enabled 
        CMP R4, #0x00
        MOV R5, #0x05; 5 attempts for user
        BEQ keys
        
keys        
        ;key1   
        LDRB R2, [R0, #0x00] ;load input regsiter
        AND R4,R2,#0x08 ; check if pin 3 is enabled 
        CMP R4, #0x00
        BNE wrong
                
        ;key2    
        LDRB R2, [R0, #0x00] ; Load input register
        AND R4, R2, #0x20    ; Check if pin 5 is enabled
        CMP R4, #0x00
        BNE wrong

        ;key3    
        LDRB R2, [R0, #0x00] ; Load input register
        AND R4, R2, #0x04    ; Check if pin 2 is enabled 
        CMP R4, #0x00
        BNE wrong

        ;key4    
        LDRB R2, [R0, #0x00] ; Load input register
        AND R4, R2, #0x20    ; Check if pin 5 is enabled 
        CMP R4, #0x00
        BNE wrong

        ;key5    
        LDRB R2, [R0, #0x00] ; Load input register
        AND R4, R2, #0x08    ; Check if pin 3 is enabled 
        CMP R4, #0x00
        BNE wrong
        
        ;key6    
        LDRB R2, [R0, #0x00] ; Load input register
        AND R4, R2, #0x10    ; Check if pin 4 is enabled 
        CMP R4, #0x00
        BNE wrong

        ;key7    
        LDRB R2, [R0, #0x00] ; Load input register
        AND R4, R2, #0x10    ; Check if pin 4 is enabled 
        CMP R4, #0x00
        BNE wrong

        ;key8    
        LDRB R2, [R0, #0x00] ; Load input register
        AND R4, R2, #0x08    ; Check if pin 3 is enabled 
        CMP R4, #0x00
        BNE wrong
        
wrong
        MOV R6, #0x01; wrong key
        
        
        ;check for wrong keys
        CMP R6,#0x01
        BEQ wrongseq
        BNE right
        
wrongseq    
        MOV R4,#0x04 ;red light
        STRB R4,[R2, #0x02]
        BL delay1
        SUB R5,R5, #0x01; decrease attempts
        CMP R5,#0x00
        BNE keys
        
        ;used all attempts
        MOV R4,#0x04 ;red light
        STRB R4,[R2, #0x02]
        BL delay2
        
right   ;right sequence
        MOV R4,#0x02 ;green light
        STRB R4,[R2, #0x02]
        BL delay1
        
        MOV R4,#0x01 ;white light
        STRB R4,[R2, #0x02]
        
        B repeat ; loop indefinitely
        
        endp
        end 
0

There are 0 answers