Professional Documents
Culture Documents
DEC 30043
COURSE MICROPROCESSOR NO.
FUNDAMENTALS PRACTICAL:
2
PROGRAMME DTK 3
CLO2: Build the assembly language program to enable features of various peripherals in the
ARM processor. (P4)/CLS3a
DP5: Are encompassed by standards and/or documented codes of practice
Page | 1 of 7 DEC30043_eff_June2019
ELECTRICAL ENGINEERING DEPARTMENT
DEC 30043
COURSE MICROPROCESSOR NO.
FUNDAMENTALS PRACTICAL:
2
PROGRAMME DTK 3
Lecturer’s Comments:
Page | 2 of 7 DEC30043_eff_June2019
ELECTRICAL ENGINEERING DEPARTMENT
DEC 30043
COURSE MICROPROCESSOR NO.
FUNDAMENTALS PRACTICAL:
2
PROGRAMME DTK 3
EQUIPMENT : Personal Computer with ARM Keil µVision Microcontroller Development Kit (MDK)
software
THEORY:
LOGICAL INSTRUCTION
The Cortex-M processors support various instructions for logic operations such as AND, OR, exclusive
OR and so on that can be used to modify the contents of the general purpose registers. Like the
arithmetic instructions, the 16-bit versions of these instructions update the flags in APSR. If the “S” suffix
is not specified, the assembler will convert them into 32-bit instructions.
To use the 16-bit versions of these instructions, the operation must be between two registers with the
destination being one of the source registers. Also, the registers used must be low registers (R0-R7),
and the S suffix should be used (APSR update).
Cortex-M0 instruction
Operation Description Assembler
Logical AND ANDS Rd, Rd, Rm
Exclusive OR EORS Rd, Rd, Rm
OR ORRS Rd, Rd, Rm
Bit clear BICS Rd, Rd, Rm
The Cortex-M architecture support various shift and rotate instructions. There are 5 variations of a shift
that are supported:
ASR #n (arithmetic shift right)
LSL #n (logical shift left)
LSR #n (logical shift right)
ROR #n (rotate right)
RRX #n (rotate right one bit with extend)
If the S suffix is used, these rotate and shift instructions also update the Carry flag in the APSR. If the
shift or rotate operation shifts the register position by multiple bits, the value of the carry flag C will be
the last bit that shifts out of the register.
Page | 3 of 7 DEC30043_eff_June2019
ELECTRICAL ENGINEERING DEPARTMENT
DEC 30043
COURSE MICROPROCESSOR NO.
FUNDAMENTALS PRACTICAL:
2
PROGRAMME DTK 3
You might wonder why there are rotate right instructions but no instructions for rotate left. Actually, a
rotate left operation can be replaced by a rotate right operation with a different rotate amount. For
example, a rotate left by 4 bits can be written as a rotate right by 28 bits. This gives you the same result
in the destination register (note that the C flag will be different from rotate left) and takes same amount
of time to execute.
To use the 16-bit version of these instructions, the registers used must be low registers (R0-R7), and the
S suffix should be used (APSR update). The RRX instruction is not available in 16-bit form.
Rotate right
ROR
Cortex-M0 instruction
Operation Description Assembler
Shift Logical shift left by immediate LSLS Rd, Rm, #<shift>
Logical shift left by register LSLS Rd, Rd, Rs
Logical shift right by immediate LSRS Rd, Rm, #<shift>
Logical shift right by register LSRS Rd, Rd, Rs
Arithmetic shift right ASRS Rd, Rm, #<shift>
Arithmetic shift right by register ASRS Rd, Rd, Rs
Rotate Rotate right by register RORS Rd, Rd, Rs
Page | 4 of 7 DEC30043_eff_June2019
ELECTRICAL ENGINEERING DEPARTMENT
DEC 30043
COURSE MICROPROCESSOR NO.
FUNDAMENTALS PRACTICAL:
2
PROGRAMME DTK 3
PROCEDURES:
Activity 2-1
1. Enter the following code ‘logical instruction’ in Figure 1 in the Keil µVision 5.
2. Save the file as activity2-1.s file
3. Compile and if there are errors, correct it and assemble the program again.
4. Observe changes in register value. Show the operation of logical manually and compare the
simulation result in table below.
; The program
AREA MYCODE, CODE, READONLY
ENTRY
START
MOVS R0, #0x55 ; Set up parameters
MOVS R1, #0xAA
MOVS R2, #0x22
ANDS R0, R0, R1
EORS R0, R0, R1
ORRS R2, R2, R1
BICS R0, R0, R1
B START
END ; End of the program
Figure 1: Assembly code for “logical instruction”
Page | 5 of 7 DEC30043_eff_June2019
ELECTRICAL ENGINEERING DEPARTMENT
DEC 30043
COURSE MICROPROCESSOR NO.
FUNDAMENTALS PRACTICAL:
2
PROGRAMME DTK 3
Page | 6 of 7 DEC30043_eff_June2019
ELECTRICAL ENGINEERING DEPARTMENT
DEC 30043
COURSE MICROPROCESSOR NO.
FUNDAMENTALS PRACTICAL:
2
PROGRAMME DTK 3
Activity 2-2
1. Enter the following code ‘shift and rotate instruction’ in Figure 2 in the Keil µVision 5.
2. Save the file as activity2-2.s file
3. Compile and if there are errors, correct it and assemble the program again.
4. Observe changes in register value. Show the operation of shift and rotate manually and compare the
simulation result in table 2.2 below.
__Vectors
DCD 0x20084000 ; stack pointer value when stack is empty
DCD START
ALIGN
; The program
AREA MYCODE, CODE, READONLY
ENTRY
START
MOVS R0, #0x55 ; Set up parameters
MOVS R1, #0xAA
MOVS R2, #0x02
LSLS R0, R0, #1
LSLS R1, R1, R2
Page | 7 of 7 DEC30043_eff_June2019
ELECTRICAL ENGINEERING DEPARTMENT
DEC 30043
COURSE MICROPROCESSOR NO.
FUNDAMENTALS PRACTICAL:
2
PROGRAMME DTK 3
Page | 8 of 7 DEC30043_eff_June2019
ELECTRICAL ENGINEERING DEPARTMENT
DEC 30043
COURSE MICROPROCESSOR NO.
FUNDAMENTALS PRACTICAL:
2
PROGRAMME DTK 3
DISCUSSION:
1. Observe the result of this instruction:
MOVS R1, #0xAA
ASRS R1, R1, #0x55
Is this instruction valid or not? State the reason.
=Not valid, because the value of #0x55 cant use to number of shift
(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
-LSLS the value in register r0,shifted to the left by one bite - value in r0, shifted to left by numbers of bit R1
(2.5 marks)
Page | 9 of 7 DEC30043_eff_June2019
ELECTRICAL ENGINEERING DEPARTMENT
DEC 30043
COURSE MICROPROCESSOR NO.
FUNDAMENTALS PRACTICAL:
2
PROGRAMME DTK 3
1. Insert comments on each side of the instruction in activity 2-1 and 2-2 to clarify the meaning
of each step.
Page | 10 of 7 DEC30043_eff_June2019
ELECTRICAL ENGINEERING DEPARTMENT
DEC 30043
COURSE MICROPROCESSOR NO.
FUNDAMENTALS PRACTICAL:
2
PROGRAMME DTK 3
ACTIVITY 2.2
Page | 11 of 7 DEC30043_eff_June2019
ELECTRICAL ENGINEERING DEPARTMENT
DEC 30043
COURSE MICROPROCESSOR NO.
FUNDAMENTALS PRACTICAL:
2
PROGRAMME DTK 3
(5 marks)
Page | 12 of 7 DEC30043_eff_June2019
ELECTRICAL ENGINEERING DEPARTMENT
DEC 30043
COURSE MICROPROCESSOR NO.
FUNDAMENTALS PRACTICAL:
2
PROGRAMME DTK 3
(5 marks)
REFLECION :
At the end of this practical work, we able to use assembler in c to perform logical, shift and
rotate instruction. We understand and know how the logical instruction and shift and rotate
instruction used in this practical to obtain the value or number. Moreover, we also familiarize
the memory mapping and the changing in the data register’s content. Then we also able to
build the assembly language program to enable features of various peripherals in the ARM
processor. We also understand the logical instruction such as AND, OR, EOR or BICS uses to
obtain the value in register .Last but not least, we all able the get the value of activity 2-1 and
2-2
(5 marks)
~ End of Practical 2 ~
Page | 13 of 7 DEC30043_eff_June2019
ELECTRICAL ENGINEERING DEPARTMENT
DEC 30043
COURSE MICROPROCESSOR NO.
FUNDAMENTALS PRACTICAL:
2
PROGRAMME DTK 3
...................................
Fazny
Course Lecturer / NOOR FAZNYZAHUDA FUAD
Course Coordinator* PENSYARAH
POLITEKNIK PORT DICKSON
..................................................
..........................................
Course Coordinator /
Head of Programme /
Subject matter Expert*
Course Leader *
Date28.8.2023 Date:28.8..2023 Date:28.8.2023
Page | 14 of 7 DEC30043_eff_June2019