Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
11 views

Lecture-08 ARM Assembly Language Programming _ Control Flow Instructions

Uploaded by

Vani telluri
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Lecture-08 ARM Assembly Language Programming _ Control Flow Instructions

Uploaded by

Vani telluri
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 32

Lecture-09

Control Flow Instructions


Control Flow Instructions
• CFI determines which instructions get executed next

• Branch

• Example: ?

• Conditional Branch

• Example: ?
Control Flow Instructions
• CFI determines which instructions get executed next

• Branch

• Example: B LABEL1

• Conditional Branch:

• Example: ?
Control Flow Instructions
• CFI determines which instructions get executed next

• Branch

• Example: B LABEL1

• Conditional Branch: B{condition} LABEL

• Example: ?
Control Flow Instructions
• CFI determines which instructions get executed next

• Branch

• Example: B LABEL1

• Conditional Branch: B{condition} LABEL

• Example: BNZ LABEL1


LOOP
MOV R0, #01; initialise R0
LOOP ADD R0, R0, #1; increment R0 by 1
CMP R0, #10; compare R0 contents with decimal value 10
BNE LOOP; branch if R0 != 10 to LOOP
LOOP
MOV R0, #01; initialise R0
LOOP ADD R0, R0, #1; increment R0 by 1
CMP R0, #10; compare R0 contents with decimal value 10
BNE LOOP; branch if R0 != 10 to LOOP
LOOP
MOV R0, #01; initialise R0
LOOP ADD R0, R0, #1; increment R0 by 1
CMP R0, #10; compare R0 contents with decimal value 10
BNE LOOP; branch if R0 != 10 to LOOP
LOOP
MOV R0, #01; initialise R0
LOOP ADD R0, R0, #1; increment R0 by 1
CMP R0, #10; compare R0 contents with decimal value 10
BNE LOOP; branch if R0 != 10 to LOOP
LOOP
MOV R0, #01; initialise R0
LOOP ADD R0, R0, #1; increment R0 by 1
CMP R0, #10; compare R0 contents with decimal value 10
BNE LOOP; branch if R0 != 10 to LOOP
BYPASS
Program-1:
CMP R0, #5
BEQ BYPASS;
ADD R1, R1, R0;
SUB R1, R1, R2;
BYPASS MUL R1, R2, R0;

Program-2:
CMP R0, #5
ADDSNE R1, R1, R0;
SUBNE R1, R1, R2
MUL R1, R2, R0
BYPASS
Program-1:
CMP R0, #5;
BEQ BYPASS;
ADD R1, R1, R0;
SUB R1, R1, R2;
BYPASS MUL R1, R2, R0;

Program-2:
CMP R0, #5
ADDNE R1, R1, R0;
SUBNE R1, R1, R2
MUL R1, R2, R0
BYPASS
Program-1:
CMP R0, #5;
BEQ BYPASS;
ADD R1, R1, R0;
SUB R1, R1, R2;
BYPASS MUL R1, R2, R0;

Program-2:
CMP R0, #5
ADDNE R1, R1, R0;
SUBNE R1, R1, R2
MUL R1, R2, R0
BYPASS
Program-1:
CMP R0, #5;
BEQ BYPASS;
ADD R1, R1, R0;
SUB R1, R1, R2;
BYPASS MUL R1, R2, R0;

Program-2:
CMP R0, #5
ADDNE R1, R1, R0;
SUBNE R1, R1, R2
MUL R1, R2, R0
BYPASS
Program-1:
CMP R0, #5;
BEQ BYPASS;
ADD R1, R1, R0;
SUB R1, R1, R2;
BYPASS MUL R1, R2, R0;

Program-2:
CMP R0, #5
ADDNE R1, R1, R0;
SUBNE R1, R1, R2
MUL R1, R2, R0
BYPASS
Program-1:
CMP R0, #5;
BEQ BYPASS; EQ means R0 == #5
ADD R1, R1, R0;
SUB R1, R1, R2;
BYPASS MUL R1, R2, R0;

Program-2:
CMP R0, #5
ADDNE R1, R1, R0;
SUBNE R1, R1, R2
MUL R1, R2, R0
BYPASS
Program-1:
CMP R0, #5;
BEQ BYPASS; EQ means R0 == #5
ADD R1, R1, R0;
SUB R1, R1, R2;
BYPASS MUL R1, R2, R0;

Program-2:
CMP R0, #5
ADDNE R1, R1, R0; if R0 != 5 perform Addition
SUBNE R1, R1, R2
MUL R1, R2, R0
BYPASS
Program-1:
CMP R0, #5;
BEQ BYPASS; EQ means R0 == #5
ADD R1, R1, R0;
SUB R1, R1, R2;
BYPASS MUL R1, R2, R0;

Program-2:
CMP R0, #5
ADDNE R1, R1, R0; if R0 != 5 perform Addition
SUBNE R1, R1, R2 ; if R0 != 5 perform Subtraction
MUL R1, R2, R0
If((a == b) && ( c == d)) e++
• CMP R0, R1
• CMPEQ R2, R3
• ADDEQ R4, R4, #01
If((a == b) && ( c == d)) e++
• CMP R0, R1; execute the CMP
• CMPEQ R2, R3
• ADDEQ R4, R4, #01
If((a == b) && ( c == d)) e++
• CMP R0, R1
• CMPEQ R2, R3; execute CMP if R0 == R1
• ADDEQ R4, R4, #01
If((a == b) && ( c == d)) e++
• CMP R0, R1
• CMPEQ R2, R3
• ADDEQ R4, R4, #01; execute ADD if R2 == R3
Branch and Link (R14)
BL SUBR
ADD
SUB
SUBR ?
?
MOV PC, R14
Branch and Link (R14)
BL SUBR; SUBR is a label short cut of Subroutine
ADD
SUB
SUBR ?
?
MOV PC, R14
Branch and Link (R14)
BL SUBR; SUBR is a label short cut of Subroutine
ADD ; some random instruction
SUB
SUBR ?
?
MOV PC, R14
Branch and Link (R14)
BL SUBR; SUBR is a label short cut of Subroutine
ADD ; some random instruction
SUB ; some random instruction
SUBR ?
?
MOV PC, R14
Branch and Link (R14)
BL SUBR; SUBR is a label short cut of Subroutine
ADD ; some random instruction
SUB ; some random instruction
SUBR STM R13!
?
MOV PC, R14
Branch and Link (R14)
BL SUBR; SUBR is a label short cut of Subroutine
ADD ; some random instruction
SUB ; some random instruction
SUBR STM R13!, {R0-R2, R14}; save work regs & link register
?
MOV PC, R14
Branch and Link (R14)
BL SUBR; SUBR is a label short cut of Subroutine
ADD ; some random instruction
SUB ; some random instruction
SUBR STM R13!, {R0-R2, R14}; save work regs & link register
LDM R13!, {R0-R2}; restore work regs
MOV PC, R14
Branch and Link (R14)
BL SUBR; SUBR is a label short cut of Subroutine
ADD ; some random instruction
SUB ; some random instruction
SUBR STM R13!, {R0-R2, R14}; save work regs & link BL
LDM R13!, {R0-R2, PC}; restore work regs & link BL
Thank You

You might also like