Professional Documents
Culture Documents
(RX63N-GR)_Exercises
Table of contents
Embedded Systems Fundamentals Exercise.......................................................................................... 2
Notes about the exercises ...................................................................................................................... 2
Exercise 1 Transfer................................................................................................................................. 5
Exercise 2 Arithmetic operation (Addition) ............................................................................................. 8
Exercise 3 Arithmetic operation (Subtraction)........................................................................................ 9
Exercise 4 Logical operations .............................................................................................................. 10
Exercise 5 Shift operation .....................................................................................................................11
Exercise 6 Bit manipulation .................................................................................................................. 12
Exercise 7 Conditional branch instructions .......................................................................................... 14
Exercise 8 Repeat ................................................................................................................................ 16
Exercise 9 Post-increment register indirect control.............................................................................. 17
Exercise 10 Pre-decrement register indirect control .......................................................................... 18
Exercise 11 Indexed register indirect control...................................................................................... 19
Exercise 12 Stack operation ............................................................................................................... 20
Exercise 13 Subroutine....................................................................................................................... 22
Additional exercises ................................................................................................................................. 23
Additional Exercise 1 Transfer ........................................................................................................... 23
Additional Exercise 2 Addition ........................................................................................................... 23
Additional Exercise 3 Subtraction ...................................................................................................... 24
Additional Exercise 4 Logical operations ........................................................................................... 24
Additional Exercise 5 Shift operations ............................................................................................... 24
Additional Exercise 6 Bit manipulation............................................................................................... 24
Additional Exercise 7 Conditional branch .......................................................................................... 25
Additional Exercise 8 Repeat............................................................................................................. 25
Additional Exercise 9 Post-increment register indirect control .......................................................... 25
Additional Exercise 10 Pre-decrement register indirect control......................................................... 25
Additional Exercise 11 Indexed register indirect control .................................................................... 25
Additional Exercise 12 Stack operation ............................................................................................. 25
Additional Exercise 13 Subroutine ..................................................................................................... 26
For instructions and addressing modes, always refer to the "RX Family User's Manual: Software." In
the Text, relevant pages are titled as "Instruction (UMSXXX)." (UMS: User's Manual: Software)
Where the number of Errors is found one or more as a result of build, it suggests some problems in
the editing of source file, so be sure to make proper corrections. In the Exercises, take no account of
the warnings listed below for the present.
W0561100:Cannot find "B_1" specified in option "start"
W0561100:Cannot find "R_1" specified in option "start"
W0561100:Cannot find "B_2" specified in option "start"
W0561100:Cannot find "R_2" specified in option "start"
…
Open the project for the exercise to work on. Click on the en01_MOV.mtpj file in the en01_MOV
folder to activate CS+.
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- - - -
; Project name : Embedded Systems Fundamentals with Renesas RX63N Exercise 1
; File name : en01_MOV.src
; Features : Transfer
; Question : Write the constant value 12H into the memory (1-byte variable RESULT).
; Revision history : 1.01 July 24, 2019 Newly issued by Kenshu Taro
; Copyright (c) 2018-2020 emBex Education inc. All Rights Reserved
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- - - -
Declare a constant.
Data for transfer
Program
Step-in execution
button
Register reference
Declare a constant.
Program
Power ON reset
Memory
reference
RX63N does not allow loading data into memory with a single instruction. Follow the steps listed
below.
Specify the address of variable RESULT in the general-purpose register.
Write the constant value 12H in the variable area in RAM (register indirect addressing).
Click on the en01a_MOV.mtpj file in the en01a_MOV folder to activate CS+. To the en01a_MOV.src,
into which pseudo-instructions have been loaded, enter the flowchart section with mnemonic.
; Declare a constant.
IMM .EQU 12H ; Value for transfer
START
; Power ON reset
.SECTION RESET,ROMDATA
.ORG 0FFFFFFFCH
.LWORD 0FFFF8100H
; Stop the assembling.
.END
Following build and download, check the operation on the simulator by step-in performance.
Click on the en01b_MOV2.mtpj file in the en01b_MOV folder to activate CS+. To the
en01b_MOV.src, into which pseudo-instructions have been loaded, enter the flowchart section with
mnemonic.
For transfer to the memory, give consider to the size of both source and destination of transfer.
; Program
Write the data designated by R10 into the .SECTION PROC,CODE
memory designated by R11. .ORG 0FFFF8100H
; Power ON reset
.SECTION RESET,ROMDATA
.ORG 0FFFFFFFCH
.LWORD 0FFFF8100H
; Stop the assembling.
.END
Following build and download, check the operation on the simulator by step-in performance.
START
MOV.L #DATA1,R11 ; Specify the address.
Read the data in variable DATA1 into R12. MOV.B [R11],R12 ; Read data.
・
・ ・
・ ・
・
・ ・
・ ・
END
Precautions when reading byte and word data out from memory
When reading byte and word data out from memory, remember to use the sign extension for MOV
instruction. Extend the MSB (most significant bit) for byte and word data up to 32 bit.
In case where you do not want to apply sign extension, use the MOVU instruction.
Click on the en02_ADD.mtpj file in the en02_ADD folder to activate CS+. To the en02_ADD.src, into
which pseudo-instructions have been loaded, enter the flowchart section with mnemonic.
; Program
Add R11 and R12 and write the result into R12. .SECTION PROC,CODE
.ORG 0FFFF8100H
Anticipate the result of addition and compare it with the result of simulator.
Anticipated result Result
Storage
Instruction location Binary number Hexadecimal Hexadecimal
number number
DATA1 0000 0000 0000 0000 1100 1011 1010 1001 0CBA9H
DATA2 0000 0000 0000 0000 0000 0100 0011 0010 432H
Addition R_ADD
In this Exercise, the instruction syntax ADD src,dest with the two (2) operands, src and dest, has
been used. For instructions with two operands, the result of addition of dest and src will be stored in
the dest and the dest is overwritten.
On the other hand, where the instruction syntax ADD src,src2,dest with the three (3) operands, src,
src2, and dest, is used, the result of addition of src and src2 will be stored in the dest and the src
and src2 are not either overwritten.
Click on the en03_SUB.mtpj file in the en03_SUB folder to activate CS+. To the en03_SUB.src, into
which pseudo-instructions have been loaded, enter the flowchart section with mnemonic.
; Program
.SECTION PROC,CODE
Subtract R12 from R11 and write the result into
.ORG 0FFFF8100H
R11.
Anticipate the result of subtraction and compare it with the result of simulator.
Anticipated result Result
Storage
Instruction location Binary number Hexadecimal Hexadecimal
number number
DATA1 0000 0000 0000 0000 1100 1011 1010 1001 0CBA9H
DATA2 0000 0000 0000 0000 0000 0100 0011 0010 432H
Subtraction R_SUB
In this Exercise, the instruction syntax SUB src,dest with the two (2) operands, src and dest, has
been used. For instructions with two operands, the result of subtraction of src from dest will be
stored in the dest and the dest is overwritten.
On the other hand, where the instruction syntax SUB src,src2,dest with the three (3) operands, src,
src2, and dest, is used, the result of subtraction of src from src2 will be stored in the dest and the src
and src2 are not either overwritten.
Click on the en04_LOG.mtpj file in the en04_LOG folder to activate CS+. To the en04_LOG.src, into
which pseudo-instructions have been loaded, enter the flowchart section with mnemonic.
Click on the en05_SHF.mtpj file in the en05_SHF folder to activate CS+. To the en05_SHF.src, into
which pseudo-instructions have been loaded, enter the flowchart section with mnemonic.
; Program
.SECTION PROC,CODE
Read the data of DATA into R14. .ORG 0FFFF8100H
; ↓↓↓Start of input by trainee↓↓↓
HAJIME: MOV.L #DATA,R10 ; Specify the address for DATA.
Logically shift R14 to left by 3 bits.
MOV.L [R10],R13 ; Set the value of DATA to R13.
SHLL #3,R13 ; Logically shift R13 to left by 3
Write the data in R14 into R_SHLR. bits.
MOV.L #R_SHLL,R10 ; Specify the address for R_SHLL.
MOV.L R13,[R10] ; Set the value for R13.
Anticipate the results of logical left shift and logical right shift and compare them with the results of
simulator.
Anticipated result Result
Storage
Instruction location
Binary number Hexadecimal Hexadecimal
number number
DATA 0000 1111 0000 1111 0000 1111 0000 1111 0F0F0F0FH
Logical left shift R_SHLL
Logical right shift R_SHLR
The instructions BCLR, BSET, and BNOT are executable on the memory (RAM) for 8-bit data.
Specify the address for the target memory in the register first then execute the instructions through
register indirect addressing. Data larger than 8 bit can only be processed in the general-purpose
register.
Click on the en06_BIT.mtpj file in the en06_BIT folder to activate CS+. To the en06_BIT.src, into
which pseudo-instructions have been loaded, enter the flowchart section with mnemonic.
; Declare a constant.
S_IMM .EQU 0FH ; Initial value
Anticipate the steps of bit manipulation and compare with the results of simulator.
Bit manipulation instructions also include BTST instruction to check specific bits, but its instruction
syntax is BTST src,src2 without dest. It checks the bit of src2 designated by src and reflects the
result into PSW. It behaves similarly to the CMP instruction discussed in the next Exercise.
The instructions BCLR, BSET, and BNOT will be processed in 32 bits in the general-purpose
register.
Click on the en06b_BIT.mtpj file in the en06b_BIT folder to activate CS+. To the en06b_BIT.src, into
which pseudo-instructions have been loaded, enter the flowchart section with mnemonic.
; Program
START .SECTION PROC,CODE
.ORG 0FFFF8100H
Anticipate the steps of bit manipulation and compare with the results of simulator.
For judgement criteria for the conditional branch instructions, use the CMP instruction as a rule. This
instruction refers to SUB instruction in practice and it does not affect any operand but only affect the
CZSO flag in PSW. It controls whether or not branch takes place with BCnd depending on the state
of PSW.
The instructions for arithmetic and logical operations affect the CZSO flag in PSW when being
executed. Consequently, the CMP instruction could be omitted in many cases.
Click on the en07_JUG.mtpj file in the en07_JUG folder to activate CS+. To the en07_JUG.src, into
which pseudo-instructions have been loaded, enter the flowchart section with mnemonic.
; Program
.SECTION PROC,CODE
Compare between R13 and R14. .ORG 0FFFF8100H
Following build and download, check the operation on the simulator by step-in performance.
Varying DATA1 and DATA2, repeat build and download and check the behaviors for any difference
through step-in performance.
Note Since interrupt priority levels for RX610 Group are from 0 to 7, b27 is reserved. Writing to b27 is ineffective.
Note 1 In the user mode, writing into IPL[3:0], PM, U, and I bits with either instruction, MVTC or POPC, becomes ignored. In additio n,
where an attempt is made for writing into IPL[3:0] with the MVTIPL instruction, the privileged operation exception results.
Note 2 In the supervisor mode, writing into PM bit with either instruction, MVTC or POPC, becomes ignored. Writing into any other
bits will be valid.
Note 3 When changing the supervisor mode to the user mode, set the PM bit in PSW saved in the stack to "1" then execute the RTE
instruction, or set the PM bit in backup PSW (BPSW) to "1" then execute the RTFI instruction.
Note 4 Since interrupt priority levels for RX610 Group are from 0 to 7, b27 is reserved. Writing to b27 is ineffective.
Click on the en08_LOP.mRpj file in the en08_LOP folder to activate CS+. To the en08_LOP.src, into
which pseudo-instructions have been loaded, enter the flowchart section with mnemonic.
; Constant definition
MAX_NUM .EQU 10 ; Maximum value to sum
START
; RAM variable area
.SECTION RAM,DATA
.ORG 00000080H
Set the first added number to R11.
SUM: .BLKL 1 ; Variable to write the sum total
; Program
.SECTION PROC,CODE
Initialize the register R12 into which the
result of addition is to be stored. .ORG 0FFFF8100H
END
Following build and download, check the operation on the simulator by step-in performance.
The post-increment register indirect control will add 1/2/4 to the data in the register based on the
size specifier after execution of the instruction. It can be used with the instructions, either MOV or
MOVU, so it is helpful when gaining access to the continuous regions in memory sequentially.
Click on the en09_PIN.mtpj file in the en09_PIN folder to activate CS+. To the en09_PIN.src, into
which pseudo-instructions have been loaded, enter the flowchart section with mnemonic.
; Set a constant.
CNT_LP .EQU 10 ; The number of data elements
START
; RAM variable area
Initialize R11 to serve as the counter of the .SECTION RAM,DATA
number of processing times. .ORG 00000080H
DATA_T: .BLKB 10 ; Variables array
Set the MAX value of processing times to R12.
; ROM constants area
.SECTION CONST,ROMDATA
.ORG 0FFFF8000H
Specify the address for array data in ROM.
DATA_S: .BYTE 97,34,78,60,56,87,03,71,15,67; Array data
; Power ON reset
.SECTION RESET,ROMDATA
.ORG 0FFFFFFFCH
.LWORD 0FFFF8100H
; Stop the assembling.
END
.END
Following build and download, check the operation on the simulator by step-in performance.
The post-increment register indirect control is often used in copying data area.
The pre-decrement register indirect control will subtract 1/2/4 from the data in the register based on
the size specifier before execution of the instruction and then execute the instruction. It can be used
with the instruction, either MOV or MOVU.
Click on the en10_PDE.mtpj file in the en10_PDE folder to activate CS+. To the en10_PDE.src, into
which pseudo-instructions have been loaded, enter the flowchart section with mnemonic.
; Set a constant.
START CNT_LP .EQU 10 ; The number of data elements
; RAM variable area
.SECTION RAM,DATA
Initialize R11 to serve as the counter of the .ORG 00000080H
number of processing times. DATA_T: .BLKB 10 ; Variables array
Set the MAX value of processing times to R12. ; ROM constants area
.SECTION CONST,ROMDATA
Specify the address for array data in ROM. .ORG 0FFFF8000H
DATA_S: .BYTE 97,34,78,60,56,87,03,71,15,67 ; Array data
; Power ON reset
.SECTION RESET,ROMDATA
END .ORG 0FFFFFFFCH
.LWORD 0FFFF8100H
; Stop the assembling.
.END
Following build and download, check the operation on the simulator by step-in performance.
The indexed register indirect is used to fetch specific data from sequential data such as array in
memory.
Describe the instruction in the format of MOV.B [Ri,Rb],Rd .
The content in the memory designated by the value of addition of the content in Rb (base) and Ri
(index) will be stored in Rd.
Click on the en11_IND.mtpj file in the en11_IND folder to activate CS+. To the en11_IND.src, into
which pseudo-instructions have been loaded, enter the flowchart section with mnemonic.
; Set a constant.
CNT_LP .EQU 10 ; The number of data elements
START
; RAM variable area
Initialize R11 to serve as the counter of the .SECTION RAM,DATA
number of processing times. .ORG 00000080H
DATA_T: .BLKB 10 ; Variables array
Set the MAX value of processing times to R12.
; ROM constants area
.SECTION CONST,ROMDATA
.ORG 0FFFF8000H
Specify the address for array data in ROM.
DATA_S: .BYTE 97,34,78,60,56,87,03,71,15,67; Array data
; Program
Specify the address for variable data in RAM.
.SECTION PROC,CODE
.ORG 0FFFF8100H
; Power ON reset
.SECTION RESET,ROMDATA
.ORG 0FFFFFFFCH
.LWORD 0FFFF8100H
END ; Stop the assembling.
.END
Following build and download, check the operation on the simulator by step-in performance.
Typical CPUs are allowed to use the special RAM space called stack. A stack puts up data on top
of each other in the order from higher to lower addresses. By only managing the stacking order of
data, there is no need to name and manage the individual data areas. In the following exercise,
let's try using the stack.
Once the PUSH instruction is executed, the CPU subtracts 4 (byte) from SP (stack pointer) then
saves the content in the specified general-purpose register into the address designated by SP.
* The 4 byte refers to the size of the register.
Once the POP instruction is executed, the CPU returns the data at the address designated by SP
to the specified general-purpose register.
Using the stack requires setting SP (R0).
Click on the en12_STC.mtpj file in the en12_STC folder to activate CS+. To the en12_STC.src, into
which pseudo-instructions have been loaded, enter the flowchart section with mnemonic.
1. It is automatically managed by the stack pointer (SP) that the RAM made
available as a stack has been used up to where (which address) and the
address used next is which. Simply by specifying the address of the stack area
first at SP, the programmer hereafter needs not to be conscious about where
the SP lies at present. Consequently, required is only setting the value of "the
final address in the area used as stack + 1" to SP (R0 acts as SP in the RX63
series) before using the stack for calling the subroutine. The stack area is
allowed to use any RAM space, but it normally uses the built-in RAM space.
2. For the program to use the stack area, the programmer must give consideration
to the capacity of stack (what byte is required as the whole). Determine the
stack capacity to be used after creating the program and check if the
corresponding RAM space is freely available.
END
Following build and download, check the operation on the simulator by step-in performance.
The subroutine is a sequence of procedures that performs a specified task composed of a set of
features in a program. So, once one subroutine is described, it becomes not necessary to describe
similar processing repeatedly.
Click on the en13_SRT.mtpj file in the en13_SRT folder to activate CS+. To the en13_SRT.src, into
which pseudo-instructions have been loaded, enter the flowchart section with mnemonic.
START
; Set a constant.
INIT_SP .EQU 100H ; Initial stack pointer
CNT_LP .EQU 10 ; The number of data elements
Set the initial stack pointer to R0.
; RAM variable area
Initialize R11 to serve as the counter of the .SECTION RAM,DATA
number of processing times. .ORG 00000080H
DATA_1: .BLKB 10 ; Variables array
Set the MAX value of the number of
processing times to R12. ; ROM constants area
.SECTION CONST,ROMDATA
Specify the address for array data in ROM. .ORG 0FFFF8000H
DATA: .BYTE 97,34,78,60,56,87,03,71,15,67 ; Array data
Following build and download, check the operation on the simulator by step-in performance.
2) Write 1-byte constant data DATA_1 (12H) into 1-byte variable SET_B, 2-byte constant data
DATA_2 (34ABH) into 2-byte variable SET_W, and 4-byte constant data DATA_3
(5F6E4D3CH) into 4-byte variable SET_L, respectively.
3) Write 1-byte constant data DATA_1 (8AH) into 4-byte variable SET_1 with a sign and into 4-
byte variable SET_2 without any sign, respectively.
2) Add 4-byte constant DATA1 (12345678H) and 4-byte constant DATA2 (0FEDCBA98H) to each
other with consideration given to occurrence of a carry. Write the result into 4-byte variable
R_ADD_L (storing lower data) and 4-byte variable R_ADD_H (storing higher data).
● The values stored after execution will be as shown below.
R_ADD_L : 11111110H
R_ADD_H : 00000001H
2) Assuming that the value of DATA2 in above 1) is (1234FF01H), anticipate the respective
values of R_SUB_1, R_SUB_2, and R_SUB_3.
Check the anticipated values against the values of actually executed results.
2) Store the value of combining higher order 8 bits of 2-byte constant data DATA1 (1357H) and
lower order 8 bits of 2-byte constant data DATA2 (9BDFH) into 2-byte variable R_ROG.
2) Increase 1-byte constant data DATA1 (5FH) ten (10) times with the shift and addition
instructions and write the result into 2-byte variable RESULT.
Write 1-byte constant data ROM_B in which 10 pieces of data are stored to 1-byte variable RAM_B
(with the number of arrays 10).
Write 2-byte constant data ROM_W in which 10 pieces of data are stored to 2-byte variable
RAM_W (with the number of arrays 10).
Write 4-byte constant data ROM_B in which 10 pieces of data are stored to 4-byte variable RAM_L
(with the number of arrays 10).