You are on page 1of 11

ELECTRICAL ENGINEERING DEPARTMENT

ACADEMIC SESSION: _____________


DEC30043 – MICROPROCESSOR FUNDAMENTALS
ASSEMBLY LANGUAGE: BRANCH INSTRUCTION
PRACTICAL WORK 3 : (UNCONDITIONAL BRANCH)
PRACTICAL WORK
DATE :
LECTURER’S NAME:
GROUP NO. :

TOTAL
STUDENT ID & NAME :
MARKS
NO REG. NO. NAME OF STUDENT (100%)
(1)
/100

(2) /100

(3) /100

DATE SUBMIT : DATE RETURN :


1
LEARNING OUTCOMES (LO):

Upon completion the experiment, students should be able to:

1. Produce inline assembler in C to perform logical, shift and rotate instruction


2. Familiarize in memory mapping and the changing in the data register’s contents.
3. Build the assembly language program to enable features of various peripherals in the ARM
processor (CLO2, PLO5)

2 OBJECTIVE

1. Build basic branches instruction


2. Construct assembly language programs to perform branches task
3. Construct flow chart on the related programming
4. Mends assembly language with correct programming code

3 THEORY

B and BL

Branch (B), Branch with Link (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).

Examples of Branch Instruction


• Branching forward, to skip over some code
• Branching backwards, creating a loop

• Using BL to call a subroutine

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

; 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, #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;;;;;;;;;;;;

END ;End of the program


Figure 3A
Activity 3.2

5. Execute the assembly program below.


6. Draw the flowchart for this program.
7. Observe changes in register value. Complete the Table 3B with the required answer.
8. 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, #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;;;;;;;;;;;;

END ;End of the program

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

;;;;;;;;;;User Code Ends;;;;;;;;;;;;

END ;End of the program


Figure 3C

6 RESULT

Table 3A: Activity 1 Observation:


Assembly Instructions Before Operation After Operation

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)

SUBS R1, R0, #2

R1 = R1 =

Calculation: (1 mark)

ADDS R0, R1, #4

R0 = R0 =

(5 marks)

Lecturer signature: _______________________ Date: _______

Flowchart: Activity 3.1

(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:

ADDS R0, R0, #3

R0= R0=
Calculation:

SUBS R1, R0, #2


R0= R0=
R1= R1=
Observation: (3 marks)
B DATA

Next Loop:
Calculation: ( 1 mark)

ADDS R0, R0, #3

R0= R0=
Calculation: ( 1 mark)

SUBS R1, R0, #2


R0= R0=
R1= R1=

(5 marks)

Lecturer signature: _______________________ Date: _______


Flowchart: Activity 3.2

(5 marks)

Table 3C: Activity 3.3 Observation:


Assembly Instructions Before Operation After Operation
MOVS R0, #5 R0= R0=
MOVS R1, #2 R1= R1=
MOVS R2, #1 R2= R2=
MOVS R3, #3 R3= R3=
Observation: R14, PC (3 marks)
BL CALC
Calculation:
ADDS R0, R0, R2
R0= R0=
Calculation:
SUBS R1, R0, R3
R1= R1=
Observation: (1 marks)
MOV PC, R14
MOVS R1, #2 R1= R1=
LDR R2, =0X03 R2= R2=
LDR R3, =0X02 R3= R3=
Calculation:
ADDS R0, R0, R2
R0= R0=
Calculation:
SUBS R1, R0, R3

R1= R1=
Observation: (1 marks)
MOV PC, R14
(5 marks)

Lecturer signature: _______________________ Date: _______

Flowchart: Activity 3.3

(5 marks)
7 DISCUSSION

1. Observe the result of this instruction:


MOVS R1, #0xAA
ASRS R1, R1, #0x55
Is this instruction valid or not? State the reason.

___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
(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

PSYCHOMOTOR PRACTICAL ASSESSMENT (80 Marks)


Un
Excellent Very Good Good Fair Marks Gained
Skills / Aspects satisfactory
5 4 3 2 1 S1 S2 S3
Ability to generate a new project
based on a microprocessor using
assembler simulator
Ability to build target and solve error □□□
□□□ Highly □□□ □□□ Not Yet □□□
Moderate
Ability to use the software to debug Competent Competent Competent Incompetent
Competent
the program
Ability to use the simulator to
manipulate ARM processor
/20 /20 /20
Total (40 marks) /40 /40 /40

Skills / Excellent Very Good Good Fair Unsatisfactory Marks Gained


weight
Aspects
5 4 3 2 1 S1 S2 S3
□□□ □□□ □□□ Demonstrate □□□ □□□
Demonstrate Demonstrate partial Demonstrate no Demonstrate no
Ability to
complete considerable understanding of yet understanding
identify
understanding understanding the task. Most of understanding of the task. No
problem X2
of the task. of the task. All the requirement of the task. Less response / task
statement
Respond to all requirement of of the task are response / task not attempted.
of the task
requirement of the task included not nearly
task. included attempted.
□□□ Able to □□□ Able to □□□ Able to □□□ Able to □□□ Unable to
Ability to
precisely predict and produce using produce using produce using
produce
predict and produce using inline assembler inline assembler inline assembler
using inline
produce using inline assembler to perform task to perform task to perform task X2
assembler
inline to perform task after being
to perform
assembler to assisted
task
perform task
□□□ Able to □□□ Able to □□□ Able to □□□ Able to □□□ Unable to
Ability to
produce and produce and produce output produce output produce output
produce an
explain output explain output according to according to according to
output
thoroughly briefly problem & problem & problem & X3
according to
according to according to question question after question
problem &
problem & problem & being assisted
question
question question
Ability to □□□ Able to □□□ Able to □□□ Able to □□□ Able to □□□ Unable to
relate relate theory to relate theory to relate theory to relate theory to relate theory to
theory to practical task practical task practical task practical task practical task X1
practical precisely and precisely after being
task fluently. assisted
Total (40 marks) /40 /40 /40

REPORT ASSESSMENT (20 Marks)


No Activity Observation Marks
Activity 1 /10
1 Result Activity 2 /10
Activity 3 /10
2 Discussion /5
3 Conclusion /5
/40
Total /20

You might also like