Professional Documents
Culture Documents
TOTAL
STUDENT ID & NAME :
MARKS
NO REG. NO. NAME OF STUDENT (100%)
(1)
/100
(2) /100
(3) /100
2 OBJECTIVE
3 THEORY
B and BL
Syntax
op1{cond}{.W} label
where:
op1 : is one of i. B (Branch)
ii. BL (Branch with link)
Cond : is an optional condition code. cond is not available on all forms of this instruction.
.W : is an optional instruction width specifier to force the use of a 32-bit B instruction in
Thumb-2.
Label : is a PC-relative expression.
Operation
• B is the simplest branch. Upon encountering a B instruction, the ARM processor will
jump immediately to the address given, and resume execution from there. Note that
the actual value stored in the branch instruction is an offset from the current value of
R15; rather than an absolute address.
• All these instructions cause a branch to label, or to the address contained in Rm. In
addition:
• The BL instructions copy the address of the next instruction into LR (R14, the link
register).
4 EQUIPMENT / TOOLS
Personal computer with ARM Keil µVision 5 with Development Kit (MDK)
5 PROCEDURE
Activity 3.1
1. Write the programming code ‘Branch forward instruction’ below in Figure 3-A using Keil
µVision 5.
2. Save the file as activity3A.s file
3. Observe changes in register value. Show the operation of branch manually and compare the
simulation result in Table 3A on the next page.
4. Draw a flowchart by referring the program
__Vectors
DCD 0x20084000 ; stack pointer value when stack is empty
DCD START
ALIGN
; The program
AREA MYCODE, CODE, READONLY
ENTRY
START
;;;;;;;;;;User Code Starts from the next line;;;;;;;;;;;;
MOVS R0, #7
MOV R1, R0
LDR R2, =0X5678
LDR R3, =0XABCD5678
DATA
ADDS R0, R0, #3
SUBS R1, R0, #2
B DATA ;goes back to DATA
;;;;;;;;;;User Code Ends;;;;;;;;;;;;
__Vectors
DCD 0x20084000 ; stack pointer value when stack is
empty
DCD START
ALIGN
; The program
AREA MYCODE, CODE, READONLY
ENTRY
START
;;;;;;;;;;User Code Starts from the next line;;;;;;;;;;;;
MOVS R0, #7
MOV R1, R0
LDR R2, =0X5678
LDR R3, =0XABCD5678
DATA
ADDS R0, R0, #3
SUBS R1, R0, #2
B DATA ;goes back to DATA
;;;;;;;;;;User Code Ends;;;;;;;;;;;;
Figure 3B
Activity 3.3
9. Write the programming code ‘Branch with link’ in Figure 3.3 below.
10. Draw flowchart for this program.
11. Observe changes in register value. Show the operation of branch manually and compare the
simulation result in Table 3.3.
12. Draw a flowchart by referring the program
; Always Start with Vector Table
; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
__Vectors
DCD 0x20084000 ; stack pointer value when stack is
empty
DCD START
ALIGN
; The program
AREA MYCODE, CODE, READONLY
ENTRY
START
;;;;;;;;;;User Code Starts from the next line;;;;;;;;;;;;
MOVS R0, #5
MOVS R1, #2
MOVS R2, #1
MOVS R3, #3
Figure 3A-3
BL CALC ; next instruction address is saved in LR (R14)
MOVS R1, #2
LDR R2, =0X03
LDR R3, =0X02
CALC
ADDS R0, R0, R2
SUBS R1, R0, R3
MOV PC, R14
6 RESULT
MOVS R0, #5 R0 = R0 =
R0 = R0 =
MOV R1, R0,
R1 = R1 =
LDR R2,
R2= R2 =
=0X1234
LDR R3,
R3 = R3 =
=0XABCD1234
Observation: (3 marks)
B FORWARD
Calculation: (1 mark)
R1 = R1 =
Calculation: (1 mark)
R0 = R0 =
(5 marks)
(5 marks)
Table 3B: Activity 2 Observation:
Assembly
Before Operation After Operation
Instructuons
MOVS R0, #7 R0= R0=
R0= R0=
MOV R1, R0
R1= R1=
LDR R2, =0X1234 R2= R2=
LDR R3,
R3= R3=
=0XABCD1234
Calculation:
R0= R0=
Calculation:
Next Loop:
Calculation: ( 1 mark)
R0= R0=
Calculation: ( 1 mark)
(5 marks)
(5 marks)
R1= R1=
Observation: (1 marks)
MOV PC, R14
(5 marks)
(5 marks)
7 DISCUSSION
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
(2.5 marks)
2. From your observation, conclude the differences between LSLS R0, R0, #1 and LSRS R0, R0,
R1.
LSLS R0, R0, #1 LSRS R0, R0, R1
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
(2.5 marks)
8 CONCLUSION
~ End of Practical 2 ~
DEC 30043: MICROPROCESSOR FUNDAMENTAL
PRACTICAL SKILL ASSESSMENT : Practical Work 3
NO REG. NO. NAME OF STUDENT TOTAL MARK
1 /100
2 /100
3 /100