0% found this document useful (0 votes)
19 views27 pages

Notes Topic 5 - set 1

Chapter 5 covers assembly language concepts related to decision-making, including branch instructions, flags in APSR, and structured programming techniques. It explains unconditional and conditional branching, compares operations, and provides examples and exercises for practical application. The chapter emphasizes the importance of flow control in programming through various branching and looping structures.

Uploaded by

Mirshanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views27 pages

Notes Topic 5 - set 1

Chapter 5 covers assembly language concepts related to decision-making, including branch instructions, flags in APSR, and structured programming techniques. It explains unconditional and conditional branching, compares operations, and provides examples and exercises for practical application. The chapter emphasizes the importance of flow control in programming through various branching and looping structures.

Uploaded by

Mirshanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

CHAPTER 5 ASSEMBLY LANGUAGE:

DECISIONS, COMPARE AND


CONDITIONAL BRANCHES
5.1 UNDERSTANDING
BRANCH INSTRUCTION 5.3 Apply in line assembler
5.1.1 Elaborate basic branch in C to perform the
instruction.
5.1.2 Elaborate call function
branches task.
technique 5.3.1 Draw the flowchart for a processing
branches problem.
5.2 Understanding Flag in
5.3.2 Apply assembly-level structured
APSR programming techniques using flag
5.2.1 Explain flag bit in APSR that can be condition and branches.
used for conditional branches.
5.3.3 Apply assembly-level structured
5.2.2 Explain combination of the flag to programming techniques using
create branches conditions. compare and branches.

5.2.3 Explain a compare with zero and


conditional branches operation.
5.1.1 Elaborate basic branch
instruction.
 A branch instruction changes the flow
of execution or is used to call a
routine
5.1.1 Elaborate basic branch
instruction.
Two types of branching

(A) (B)
Unconditional Conditional
branching branching
Instruction: Instruction:
BEQ BGE BCS
B - branch BNE BGT BCC
BL – branch link BLE BMI BVS
BLT BPL BVC
(A)
Unconditional branching

Instruction:
B – branch BL – branch link

Syntax:
B label BL label

 these instructions cause a branch to label (a PC-relative


expression)
(A)
Unconditional branching
Instruction:
B – branch BL – branch
link
5.1.2 Elaborate call function technique
BL – branch link

subroutine  a sequence of instructions that performs a specific


task
 a set of instructions designed to perform a frequently
5.2 Understanding Flag in
APSR
Conditional branching

 change the flow of execution with a


condition

Instruction:
BEQ BGE BCS
BNE BGT BCC
BLE BMI BVS
BLT BPL BVC
5.2 Understanding Flag in
APSR
Example:

 BCS add_again ; goto to label add_again when


carry = 1
CMP R3, #0
SUBGT R0,R1,R2 ; perform R0=R1-R2 when (R3) is
greater than #0 (Z=0 & N=V)
ADDLE R4,R5,R6 ; perform R4=R5+R6 when (R3) is
lesser than or equal #0
(Z=1 & N!=V)
Example:

CMP R3, #3
BGT mul_5 ;goto mul_3 (label) when

(R3) is greater than #3


(Z=0 & N=V)
DIVS R0,R2,R1 ;if not, perform
R0=R2/R1
B END
mul_5 MULS R0,R2,R1 ;perform R0=R2*R1
END
Try It Yourself

1. Write the programming code to inspect the


content of R4 and if the content is greater than
0x55, divide the value with 0x5 and store the
result at register R5. Otherwise, multiply it with
0x3 and store the result in register R6.
5.3 Apply in line assembler in C to perform
the branches task.

Structured Programming Techniques


Selection Structure
Example:
Try It Yourself

1. Draw the flow chart and write the programming


code to inspect the content of R1 and R2. If the
content of R1 is same as content of R2, multiply
the content of R1 with 0xA and store the result
at register R3. Otherwise, divide the content of
R2 with 0x3 and store the result in register R4.
Try It Yourself

1. Draw the flow chart and write the programming


code to inspect the content of R4 and R5. If the
content of R4 is lesser than content of R5,
subtract the content of R4 with 0x1 and store
the result at register R3. Otherwise, add the
content of R4 with 0x3 and store the result in
register R6.
teration @ Looping Structure

3 types of Iteration structure:

i. for  numbers of loop has been determine

ii. while number of loops


has/hasn’t been
iii. do..while determined
i. for loop
Assembly codes:
Syntax in C:
Initial Test Increment
counter counter counter
Sum = 0;
for( i=0 ; i<=10 ; i++)
{
Sum=sum+i;
}
ii. do..while loop
Example (Lab work 4):
Try It Yourself

Write a assembly program to solve the algebraic


problem below. Then, draw the flow chart to
express the problem:
15
2 - 163
START
Answer SET
R02
SET
R12
MOVS R0, #0x2 ;multiplication by 2
SET
MOVS R1, #0x2 ;base 2 R0 R2E
= R1 X
MOVS R2, #0xE ;14 times of looping R0
X
process (2 )

loop_xMULS R0,R1,R0 ;R0 = R1 X R0 R2 - 1


SUBS R2, #1 ;R2=R2 – 1 
looping process N
14 X
BNE loop_x ;loops for 14 times LOOPS?
O
SUBS R0, R0,#0xA3 ; 215 - 163
END YES

215 - 163

END
Try It Yourself

Write a assembly program to solve the algebraic


problems below. Then, draw the flow chart to
express the problem:
12
i. 4 – 890
20 13
ii. 5 +6
Try It Yourself

Write a assembly
program to solve
the algebraic
problem below.
Then, draw the
flow chart to
express the
problem:
THE END

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy