M306NAFGTFP MITSUBISHI, M306NAFGTFP Datasheet

no-image

M306NAFGTFP

Manufacturer Part Number
M306NAFGTFP
Description
M306NAFGTFPM16C/60.M16C/20 Series Sample Programs Collection
Manufacturer
MITSUBISHI
Datasheet
The semiconductor operations of Hitachi and Mitsubishi Electric were transferred to Renesas
Technology Corporation on April 1st 2003. These operations include microcomputer, logic, analog
and discrete devices, and memory chips other than DRAMs (flash memory, SRAMs etc.)
Accordingly, although Mitsubishi Electric, Mitsubishi Electric Corporation, Mitsubishi
Semiconductors, and other Mitsubishi brand names are mentioned in the document, these names
have in fact all been changed to Renesas Technology Corp. Thank you for your understanding.
Except for our corporate trademark, logo and corporate statement, no changes whatsoever have been
made to the contents of the document, and these changes do not constitute any alteration to the
contents of the document itself.
Note : Mitsubishi Electric will continue the business operations of high frequency & optical devices
To all our customers
Regarding the change of names mentioned in the document, such as Mitsubishi
Electric and Mitsubishi XX, to Renesas Technology Corp.
and power devices.
Renesas Technology Corp.
Customer Support Dept.
April 1, 2003

Related parts for M306NAFGTFP

M306NAFGTFP Summary of contents

Page 1

... Except for our corporate trademark, logo and corporate statement, no changes whatsoever have been made to the contents of the document, and these changes do not constitute any alteration to the contents of the document itself. Note : Mitsubishi Electric will continue the business operations of high frequency & optical devices and power devices. Renesas Technology Corp. ...

Page 2

... MITSUBISHI 16-BIT SINGLE-CHIP MICROCOMPUTER M16C FAMILY M16C/60 M16C/20 SERIES <Sample program> Application note ADVANCED AND EVER ADVANCING MITSUBISHI ELECTRIC ...

Page 3

... All information contained in these materials, including product data, diagrams, charts, programs and algorithms represents information on products at the time of publication of these materials, and are subject to change by Mitsubishi Electric Corporation without notice due to product improvements or other reasons therefore recommended that customers contact Mitsubishi Electric Corporation or an authorized Mitsubishi Semiconductor product distributor for the latest product information before purchasing a product listed herein ...

Page 4

... Preface This collection of reference programs relate to the M16C/60, M16C/20 series of Mitsubishi 16-bit single-chip microcomputers. It contains sample programs and arithmetic libraries that have been prepared in an attempt to provide a useful means of understanding the instruction set available for the M16C/60, M16C/20 series and materials that can be referenced when actually developing your applications software ...

Page 5

M16C Family-related document list Usages (Microcomputer development flow) Selection of microcomputer Outline design of system Detail design of system Hard- Soft- ware ware devel- devel- opment opment System evaluation M16C Family Line-up M16C Family Type of document Data sheet and ...

Page 6

Chapter 1 Guide to Using This Manual 1.1 Program Configuration ........................................................................................................... 2 1.2 Guide to Using Programs .................................................................................................... 10 Chapter 2 Collection of General-purpose Programs Function List ...................................................................................................... 2.1 Clearing RAM .................................................................................................................... 16 2.2 Transferring Blocks ............................................................................................................ 20 2.3 Changing ...

Page 7

Converting from Lowercase Alphabet to Uppercase Alphabet ........................................ 122 2.27 Converting from Uppercase Alphabet to Lowercase Alphabet ........................................ 126 2.28 Converting from ASCII to Hexadecimal Data .................................................................. 130 2.29 Converting from Hexadecimal Data to ASCII Code ......................................................... 134 2.30 ...

Page 8

Chapter 1 Guide to Using This Manual 1.1 Program Configuration 1.2 Guide to Using Programs ...

Page 9

Guide to Using This Manual This manual contains sample programs in Chapter 2, “Collection of General-purpose Programs,” and arith- metic libraries in Chapter 3, “Collection of Mathematic/Trigonometric Programs.” These programs are ex- pected to provide you with useful ...

Page 10

Outline The following shows the format of the item “Outline” and how to read it. 2 2.8 Comparing 32 Bits 2.8.1 Outline This program compares 32-bit data between registers. This program compares 32-bit data between memory locations. (1) ...

Page 11

Function name It indicates the name of the function performed. (2) Outline It indicates the outline function of the program. (3) Number of execution cycles It indicates the number of execution cycles required when the program is executed. ...

Page 12

Input It indicates the input arguments required when executing the program. If any input argument is re- quired, store the data in the register or memory location to be operated on before executing the program. If there is ...

Page 13

Explanation The following shows the format of the item “Explanation”. 2 2.8.2 Explanation This program compares 32-bit data between registers. Set the comparing data in R2 and R0 and the compared data in R3 and R1 beginning with ...

Page 14

Flowchart The following shows the format of the item “Flowchart”. 2 2.8.3 Flowchart Compare high-order bits Necessary to compare low-order bits? Compare low-order bits (1) Function name It indicates the name of the function performed. (2) Flowchart It ...

Page 15

Program list The following shows the format of the item “Program list” and how to read it. 2 2.8.4 Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VromTOP ; ;============================================================== ; Title: ...

Page 16

Function name It indicates the name of the function performed. (2) Initial setup section This is the program’s initial setup section. Following settings are made here as necessary: • Declares the start address of a memory area. • ...

Page 17

Guide to Using Programs This manual contains programs in subroutine form and those in routine form. (Refer to Chapter 2, “Func- tion List”.) Use the programs in subroutine form by calling them from your application program following the ...

Page 18

User program . . . . . . . . . . MOV.W MOV.W JSR JC Processing result . . . . . . . . SIN_ERR: Processing error Example of a subroutine call WORK1[SB],R0 ........ Sets arguments. WORK2[SB],R2 ...

Page 19

MEMO Guide to Using This Manual 1.2 Guide to Using Programs 12 ...

Page 20

Collection of General-purpuse Programs Chapter 2 ...

Page 21

Function List Item No. 2.1 Clearing RAM 2.2 Transferring block 2.3 Changing blocks 2.4 Indirect subroutine call 2.5 Compressing BCD 2.6 Caluculating sum-of-products 2.7 Processing bits 2.8 Comparing 32 bits 2.9 Adding 32 bits 2.10 Subtracting 32 bits 2.11 ...

Page 22

Item No. 2.18 Converting from HEX code (1 byte) to BCD code (2 bytes) 2.19 Converting from HEX code (4 bytes) to BCD code (5 bytes) 2.20 Converting from BCD code (1 byte) to HEX code (1 byte) 2.21 ...

Page 23

Clearing RAM 2.1.1 Outline This program initializes memory by using a block constant setup instruction (SSTR). Subroutine name : Interrupt during execution: Accepted Register/memory Specified area Usage precautions Memory is initialized in ...

Page 24

Explanation This program stores 0s in memory in units of words by using a block constant setup instruction (SSTR). The program sets the transfer data (0H) in R0, the number of transfers performed (half the number of bytes ...

Page 25

Flowchart Set transfer conditions Excute transfer Collection of General-purpose Programs ENTER EXIT 18 2.1 Clearing RAM ...

Page 26

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VramTOP VramEND VromTOP ; ;============================================================== ; Title: Clearing RAM ; Outline: Clears RAM using block constant setup instruction ; Input: ------------------------------> ...

Page 27

Transferring Blocks 2.2.1 Outline This program transfers memory contents from one location to another by using a block transfer instruc- tion (SMOVF). Subroutine name : Interrupt during execution: Accepted Register/memory R0 R1H R1L Content ...

Page 28

Explanation This program transfers memory contents from one location to another by using a block transfer instruc- tion (SMOVF). The program sets the number of transfers performed in R3, the high-order 4 bits of the source’s start address ...

Page 29

Flowchart Set transfer conditions Excute transfer Collection of General-purpose Programs ENTER EXIT 22 2.2 Transferring Blocks ...

Page 30

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VramTOP VromTOP ; LENGTH BLOCK1: BLOCK2: ; ;============================================================== ; Title: Transferring blocks ; Outline: Example for using block transfer instruction ; Input: ------------------------------> ; ...

Page 31

Changing Blocks 2.3.1 Outline This program changes memory contents consisting of the same number of bytes with each other memory location. Subroutine name : Interrupt during execution: Accepted Register/memory R0L R0H Content of ...

Page 32

Explanation This program changes memory contents consisting of the same number of bytes with each other memory location. An add and conditional branch instruction (ADJNZ) is used to count the number of transfers performed. In this program, memory ...

Page 33

Flowchart ENTER Set the number of transfers performed Change data Number of transfers set completed? Yes EXIT Collection of General-purpose Programs No 26 2.3 Changing Blocks ...

Page 34

Program List ;******************************************************************************************** ; ; M16C Program Collection No.3 ; CPU ; ;******************************************************************************************** VramTOP VromTOP ; LENGTH BLOCK1: BLOCK2: ; ;============================================================== ; Title: Changing blocks ; Outline: Changes data in units of blocks. ; Input: ------------------------------> ; R0L ...

Page 35

Indirect Subroutine Call 2.4.1 Outline This program executes an indirect subroutine call instruction after setting the relative jump address for indirect jump. It also executes an indirect subroutine call instruction by using a 20-bit absolute address. (1) Indirect ...

Page 36

Indirect subroutine call (absolute) Subroutine name : SUBIND_A Interrupt during execution: Accepted Register/memory MODE Current processing status Next processing status Usage precautions The indirect jump address set here is a 20-bit absolute ...

Page 37

Explanation For indirect jump based on relative addresses, this program uses an extended access instruction (LDE) to set the relative jump address for the indirect jump. In this program, since relative addresses are within the range that can ...

Page 38

Flowchart Processing 1 Collection of General-purpose Programs ENTER Set status Set processed addresses EXIT 31 2.4 Indirect Subroutine Call Processing 2 ...

Page 39

Program List ;******************************************************************************************** ; M16C Program Collection No CPU ;******************************************************************************************** VramTOP VromTOP Vsb MODE: MD_0 MD_1 ;============================================================== ; Title: Indirect subroutine call ; Outline: Branches processing using an indirect subroutine call (relative) ; Input: ------------------------------> ; ...

Page 40

Compressing BCD 2.5.1 Outline This program converts 2-digit unpacked BCD data into 1-digit packed BCD. Subroutine name : Interrupt during execution: Accepted Register/memory R0L R1H UNPACK_BCDhi Upper half of unpacked BCD UNPACK_BCDlow Lower ...

Page 41

Explanation This program converts 2-digit unpacked BCD data into 1-digit packed BCD. Set the 2-digit unpacked BCD data in a variable area (UNPACK_BCDhi, UNPACK_BCDlow). When the program is executed, 1- digit packed BCD data is output to a ...

Page 42

Flowchart Transfer low-order 4 bits of the upper digit of unpacked BCD in high-order bits of register Transfer low-order 4 bits of the lower digit of unpacked BCD in low-order bits of register Transfer the result to packed ...

Page 43

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VramTOP VromTOP Vsb ; UNPACK_BCDhi: UNPACK_BCDlow: PACK_BCD: ; ;============================================================== ; Title: Compressing BCD ; Outline: Converts 2-digit unpacked BCD to 1-digit packed BCD. ; ...

Page 44

Calculating Sum-of-Products 2.6.1 Outline This program calculates a sum of products using a sum-of-products calculating instruction (RMPA). Subroutine name : Interrupt during execution: Accepted Register/memory DATA11 to 13 DATA21 to 23 ANS ...

Page 45

Explanation This program calculates a sum of products using a sum-of-products calculating instruction (RMPA). Set the multiplier in a variable area (DATA11-13) and the multiplicand in a variable area (DATA21-23). The result of sum-of-products calculation is output to ...

Page 46

Flowchart Set sum-of-products calculation condition Execute sum-of-products calculation Set calculation result Collection of General-purpose Programs ENTER EXIT 39 2.6 Calculating Sum-of-Products ...

Page 47

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VramTOP VromTOP Vsb ; DATA11: DATA12: DATA13: DATA21: DATA22: DATA23: ANS: ; ;============================================================== ; Title: Calculating sum-of-products ; Outline: Calculates a sum of products. ...

Page 48

Processing Bits 2.7.1 Outline This program processes bits. Subroutine name : Interrupt during execution: Accepted Register/memory Usage precautions Collection of General-purpose Programs ROM capacity : Number of stacks used : Input Output ...

Page 49

Explanation This program uses bit processing instructions (BTSTC, BTST, BNTST) and condition store instructions (STZ, STZX) to perform its function. When it is executed, a value is output to PORT1,or PORT2 that corresponds to the bit content of ...

Page 50

Flowchart ENTER Requested? (Request cleared) Yes Content of F_IOdata1 0 O _IOd ata1 Content of F_IOdata2 1 Output "FFH" to PORT1 Content of F_IOdata3 0 Output "55H" to PORT2 EXIT Collection of General-purpose Programs ...

Page 51

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VramTOP VromTOP ; PORT0 O_IOdata1 PORT1 PORT2 ; FLAG1: F_REQ F_IOdata1 F_IOdata2 F_IOdata3 ; ;============================================================== ; Title: Setting bit after accepting event ; Outline: ...

Page 52

Comparing 32 Bits 2.8.1 Outline This program compares 32-bit data between registers. This program compares 32-bit data between memory locations. (1) 32-bit comparison (register) Subroutine name : COMP32 Interrupt during execution: Accepted Register/memory R0 Lower half of comparing ...

Page 53

Subroutine name : COMPmemory32 Interrupt during execution: Accepted Register/memory Address of comparing data A0 Address of compared data A1 Memory indicated by A0 Memory indicated by A1 Z/C flag Usage precautions ...

Page 54

Explanation This program compares 32-bit data between registers. Set the comparing data in R2 and R0 and the compared data in R3 and R1 beginning with the upper half, respectively. The comparison result is output to the Z ...

Page 55

Flowchart ENTER Compare high-order bits Necessary to compare low-order bits? Yes Compare low-order bits EXIT Collection of General-purpose Programs No 48 2.8 Comparing 32 Bits ...

Page 56

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VromTOP ; ;============================================================== ; Title: Comparing 32 bits ; Outline: Compares 32-bit data between registers. ; Input: ------------------------------> (Lower half of comparing ...

Page 57

Adding 32 Bits 2.9.1 Outline This program performs a 32-bit unsigned addition using registers. This program performs a 32-bit unsigned addition between memory locations. (1) 32-bit addition (register) Subroutine name : ADDITION32 Interrupt during execution: Accepted Register/memory R0 ...

Page 58

Subroutine name : ADDITIONmemory32 Interrupt during execution: Accepted Register/memory Augend address Addend address A1 Memory indicated by A0 Memory indicated flag Usage precautions The augend is destroyed ...

Page 59

Explanation This program performs a 32-bit unsigned addition using registers. Set the augend in R2 and R0 and the addend in R3 and R1 beginning with the upper half, respectively. The addition result is output to R2 and ...

Page 60

Flowchart Add low-order bits Add high-order bits including Collection of General-purpose Programs ENTER carry EXIT 53 2.9 Adding 32 Bits ...

Page 61

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VromTOP ; ;============================================================== ; Title: Adding 32 bits ; Outline: Adds 32-bit data using registers. ; Input: ------------------------------> (Lower half of augend) ...

Page 62

Subtracting 32 Bits 2.10.1 Outline This program performs a 32-bit unsigned subtraction using registers. This program performs a 32-bit unsigned subtraction between memory locations. (1) 32-bit subtraction (register) Subroutine name : SUBTRACT32 Interrupt during execution: Accepted Register/memory R0 ...

Page 63

Subroutine name : SUBTRACTmemory32 Interrupt during execution: Accepted Register/memory Minuend address Subtrahend address A1 Memory indicated by A0 Memory indicated by A1 Subtrahend C flag Usage precautions The minuend is ...

Page 64

Explanation This program performs a 32-bit unsigned subtraction using registers. Set the minuend in R2 and R0 and the subtrahend in R3 and R1 beginning with the upper half, respectively. The subtraction result is output to R2 and ...

Page 65

Flowchart Subtract low-order bits Subtract high-order bits including borrow Collection of General-purpose Programs ENTER EXIT 58 2.10 Subtracting 32 Bits ...

Page 66

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VromTOP ; ;============================================================== ; Title: Subtracting 32 bits ; Outline: Subtracts 32-bit data using registers. ; Input: ------------------------------> (Lower half of minuend) ...

Page 67

Multiplying 32 Bits 2.11.1 Outline This program performs a 32-bit unsigned multiplication using registers. Subroutine name : MULTIPLE32 Interrupt during execution: Accepted Register/memory R0 Lower half of multiplicand R1 Lower half of multiplier R2 Upper half of multiplicand ...

Page 68

Explanation This program performs a 32-bit unsigned multiplication using registers. Set the multiplicand in R2 and R0 beginning with the upper half and the multiplier in R3 and R1, respectively. The multiplication result is output to R3, R1, ...

Page 69

Flowchart ENTER Save multiplier Multiply upper half of multiplicand by lower half of multiplier Move calculation result to intermediate calculation value Multiply lower half of multiplicand by upper half of multiplier Add calculation result to intermediate calculation value ...

Page 70

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VromTOP .EQU ; ;============================================================== ; Title: Multiplying 32 bits ; Outline: Multiplies 32-bit data together using registers ; Input: ------------------------------> (Lower half ...

Page 71

Dividing 32 Bits 2.12.1 Outline This program performs a 32-bit unsigned division using registers. Subroutine name : DIVIDE32 Interrupt during execution: Accepted Register/memory R0 Lower half of dividend Lower half of quotient R1 Lower half of divisor R2 ...

Page 72

Explanation This program performs a 32-bit unsigned division using registers. Set the dividend in R2 and R0 and the divisor in R3 and R1 beginning with the upper half, respectively. The quotient and the remainder are output to ...

Page 73

Flowchart ENTER Initialize remainder area Zero division? No Sets number of shifts to be performed Create shift dividend and carry quotient Shift dividend - divisor --> Shift dividend Set quotient Could be subtracted? No Shift dividend + divisor ...

Page 74

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VromTOP FBcnst ;============================================================== ; Title: Dividing 32 bits ; Outline: Divides 32-bit data together using registers ; Input: ------------------------------> (Lower half of ...

Page 75

Dividing 64 Bits 2.13.1 Outline This program performs an unsigned division on a 64-bit dividend and a 32-bit divisor using registers. Subroutine name : DIVIDE64 Interrupt during execution: Accepted Register/memory R0 Lower part of dividend Lower part of ...

Page 76

Explanation This program performs an unsigned division on a 64-bit dividend and a 32-bit divisor using registers. Set the dividend in R3, R1, R2, and R0 beginning with the most significant part, and the divisor in A1 and ...

Page 77

Flowchart ENTER Initialize remainder area Zero division? No Sets number of shifts to be performed Create shift dividend and carry quotient Shift dividend - divisor --> Shift dividend Set quotient Could be subtracted? No Shift dividend + divisor ...

Page 78

Program List ;******************************************************************************************** ; M16C Program Collection No CPU ;******************************************************************************************** VromTOP FBcnst ;============================================================== ; Title: Dividing 64 bits ; Outline: Divides 64-bit dividend by 32-bit divisor ; Input: ------------------------------> (Lower part of dividend) ; ...

Page 79

Adding BCD 2.14.1 Outline This program adds 8 digits of BCD data together by using registers. This program adds 8 digits of BCD data together between memory locations. (1) BCD addition (register) Subroutine name : BCD_ADDITION8 Interrupt during ...

Page 80

BCD addition (memory) Subroutine name : BCD_ADDITIONmemory8 Interrupt during execution: Accepted Register/memory Augend address Addend address A1 Memory indicated by A0 Memory indicated flag Usage precautions The augend is destroyed ...

Page 81

Explanation This program adds 8 digits of BCD data between registers by using a decimal add instruction (DADD). Set the augend in R2 and R0 and the addend in R3 and R1 beginning with the upper half, respectively. ...

Page 82

Flowchart ENTER Add low-order bits Move added data Add high-order bits including carry Move added data EXIT Collection of General-purpose Programs 75 2.14 Adding BCD ...

Page 83

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VromTOP ; ;============================================================== ; Title: Adding 8-digit BCD. ; Outline: Adds 8-digit BCD together using registers. ; Input: ------------------------------> (Lower half of ...

Page 84

Subtracting BCD 2.15.1 Outline This program subtracts 8-digit BCD data using registers. This program subtracts 8-digit BCD data between memory locations. (1) BCD subtraction (register) Subroutine name : BCD_SUBTRACT8 Interrupt during execution: Accepted Register/memory R0 Lower half of ...

Page 85

BCD subtraction (memory) Subroutine name : BCD_SUBTRACTmemory8 Interrupt during execution: Accepted Register/memory Minuend address Subtrahend address A1 Memory indicated by A0 Minuend data Memory indicated by A1 Subtrahend data C flag Usage precautions ...

Page 86

Explanation This program subtracts 8-digit BCD data between registers by using a decimal subtract instruction (DSUB). Set the minuend in R2 and R0 and the subtrahend in R3 and R1 beginning with the upper half, respectively. The subtraction ...

Page 87

Flowchart ENTER Subtract low-order bits Move subtracted data Subtract high-order bits including borrow Move subtracted data EXIT Collection of General-purpose Programs 80 2.15 Subtracting BCD ...

Page 88

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VromTOP ; ;============================================================== ; Title: Subtracting 8-digit BCD ; Outline: Subtracts 8-digit BCD using registers ; Input: ------------------------------> (Lower half of minuend) ...

Page 89

Multiplying BCD 2.16.1 Outline This program multiplies 4-digit BCD using registers. Subroutine name : BCD_MULTIPLE4 Interrupt during execution: Accepted Register/memory Usage precautions The multiplier is destroyed as a result of program execution. ...

Page 90

Explanation This program multiplies 4-digit BCD together by using registers. Set the multiplicand in R1 and the multiplier in R3, respectively. The multiplication result is output to R2 and R0 beginning with the upper half. In this program, ...

Page 91

Flowchart ENTER Initialize multiplication result area Set number of digits to be multiplied Carry of multiplication result One digit of multiplier --> Addition count Addition count = 0? No Multiplicand + multiplier --> Multiplication result Addition count finished? ...

Page 92

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VromTOP ; ;============================================================== ; Title: Multiplying 4-digit BCD ; Outline: Multiplies 4-digit BCD using registers. ; Input: ------------------------------> ...

Page 93

Dividing BCD 2.17.1 Outline This program divides 8-digit BCD by using registers. Subroutine name : BCD_DIVIDE8 Interrupt during execution: Accepted Register/memory R0 R1 Lower half of divisor R2 R3 Upper half of divisor Lower half of dividend A0 ...

Page 94

Explanation This program divides 8-digit BCD together by using registers. Set the dividend in A1 and A0 and the divisor in R3 and R1 beginning with the upper half, respectively. The quotient and the remainder are output to ...

Page 95

Flowchart ENTER Initialize remainder area Zero division? No Set shift count Create shift dividend and carry 1 into next position of quotient (done in units of 4 bits because of BCD) Count quotient Shift dividend - divisor --> ...

Page 96

Program List ;******************************************************************************************** ; M16C Program Collection No CPU ;******************************************************************************************** VromTOP FBcnst ;============================================================== ; Title: Dividing 8-digit BCD ; Outline: Divides 8-digit BCD using registers ; Input: ------------------------------> (Lower half ...

Page 97

Converting from HEX Code to BCD Code 2.18.1 Outline This program converts 1-byte HEX code into 2-byte BCD code. Subroutine name : HEXtoBCD_1byte Interrupt during execution: Accepted Register/memory R0 R1H R1L Usage precautions HEX ...

Page 98

Explanation This program converts 1-byte HEX code into 2-byte BCD code. Set the HEX code in R1L. The BCD code is output to R0. In this program, the HEX code is doubled by decimal calculation sequentially beginning with ...

Page 99

Flowchart ENTER Initialize BCD area Set loop count Shift most significant bit to C flag Save register BCD area flag --> BCD area Restore register Loop count finished? Yes EXIT Collection of General-purpose Programs ...

Page 100

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VromTOP ; ;============================================================== ; Title: Converting from HEX code to BCD code ; Outline: Converts 1-byte HEX code into 2-byte BCD code ; Input: ...

Page 101

Converting from HEX Code to BCD Code 2.19.1 Outline This program converts 4-byte HEX code into 5-byte BCD code. Subroutine name : HEXtoBCD_4byte Interrupt during execution: Accepted Register/memory R0 R1 Lower half of HEX code R2 R3 Upper ...

Page 102

Explanation This program converts 4-byte HEX code into 5-byte BCD code. Set the HEX code in R3 and R1 begin- ning with the upper half. The BCD code is output to A1, R2, and R0 beginning with the ...

Page 103

Flowchart ENTER Initialize BCD area Set loop count Shift most significant bit to C flag Save register BCD area flag --> BCD area Restore register Loop count finished? Yes EXIT Collection of General-purpose Programs ...

Page 104

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VromTOP ; ;============================================================== ; Title: Converting from HEX code to BCD code ; Outline: Converts 4-byte HEX code into 5-byte BCD code ; Input: ...

Page 105

Converting from BCD Code to HEX Code 2.20.1 Outline This program converts 1-byte BCD code into 1-byte HEX code. Subroutine name : BCDtoHEX_1byte Interrupt during execution: Accepted Register/memory R0L R0H R1L R1H Usage precautions ...

Page 106

Explanation This program converts 1-byte BCD code into 1-byte HEX code. Set the BCD code in R0H. The HEX code is output to R0L. In this program, the BCD code is divided by 2 (shifted right) and the ...

Page 107

Flowchart ENTER Initialize HEX area Set loop count Set remainder of BCD code vid MSB of HEX data Correct BCD code Loop count finished? Yes EXIT Collection of General-purpose Programs 2.20 Converting from BCD Code to ...

Page 108

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VromTOP ; ;============================================================== ; Title: Converting from BCD code to HEX code ; Outline: Converts 1-byte BCD code into 1-byte HEX code ; Input: ...

Page 109

Converting from BCD Code to HEX Code 2.21.1 Outline This program converts 4-byte BCD code into 4-byte HEX code. Subroutine name : BCDtoHEX_4byte Interrupt during execution: Accepted Register/memory R0 Lower half of BCD code R1 R2 Upper half ...

Page 110

Explanation This program converts 4-byte BCD code into 4-byte HEX code. Set the BCD code in R2 and R0 begin- ning with the upper half. The HEX code is output to R3 and R1 beginning with the upper ...

Page 111

Flowchart ENTER Initialize HEX area Set loop count Set remainder of BCD code vid MSB of HEX data Set loop count Change upper and lower halves for each other Execute 1-digit correction processing Change digits 4th ...

Page 112

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VromTOP ; ;============================================================== ; Title: Converting from BCD code to HEX code ; Outline: Converts 4-byte BCD code into 4-byte HEX code ; Input: ...

Page 113

Converting from Floating-point Number to Binary Number 2.22.1 Outline This program converts a single-precision, floating- point number into a 32-bit singed binary number. Subroutine name : FLOATINGtoBIN Interrupt during execution: Accepted Register/memory R0 Mid and lower parts of ...

Page 114

Explanation This program converts a single-precision, floating- point number into a 32-bit singed binary number. Set the single-precision, floating-point number in R2 and R0. A signed binary number is output to R3 and R1 beginning with the upper ...

Page 115

Flowchart ENTER Initialize binary area Save sign bit 0? No Create exponent and mantissa data Less than 1? No Within range of binary numbers represented with 31 bits? Yes Shift mantissa data 1 bit left Load binary data ...

Page 116

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU : M16C ; ;******************************************************************************************** VromTOP .EQU ; ;============================================================== ; Title: Converting from single-precision, floating-point number to binary number ; Outline: Converts single-precision, floating-point number into 32-bit ...

Page 117

Converting from Binary Number to Floating-point Number 2.23.1 Outline This program converts a 32-bit signed binary number into a single-precision, floating-point number. Subroutine name : BINtoFLOATING Interrupt during execution: Accepted Register/memory R0 Lower half of signed binary R1 ...

Page 118

Explanation This program converts a 32-bit signed binary number into a single-precision, floating-point number. Set the 32-bit signed binary number in R2 and R0 beginning with the upper half. A single-precision, floating- point number is output to R2 ...

Page 119

Flowchart ENTER Zero ? Save sign bit Positive number ? Create 2's complement Set maximum value to exponent part Set exponent data by searching for maximum bit position Set floating-point format Set exponent part Set sign bit EXIT ...

Page 120

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VromTOP ; ;============================================================== ; Title: Converting from binary number to single-precision, floating-point number ; Outline: Converts 32-bit signed binary number into single-precision, floating-point number ...

Page 121

Sorting 2.24.1 Outline This program sorts data consisting of a specified number of bytes (sizes in bytes) in ascending order. Subroutine name : SORT Interrupt during execution: Accepted Register/memory R0L Number of compare bytes - 1 R0H R1L ...

Page 122

Explanation This program sorts data consisting of a specified number of bytes (sizes in bytes) in ascending order beginning with a specified address. Set the “number of bytes to be compared - 1” in R0L and the start ...

Page 123

Flowchart ENTER Number of bytes to be sorted = Set compare address and number of compare bytes Change compare address Compare data compare data ? No Change compared data and compare data for each other ...

Page 124

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VromTOP .EQU ; ;============================================================== ; Title: Sorting ; Outline: Sorts given data (2 to 256 bytes) in ascending order ; Input: ------------------------------> ; R0L ...

Page 125

Searching Array 2.25.1 Outline This program searches for specified data from a two-dimensional array of a given size (maximum 255 x 255 bytes). Subroutine name : ARRANGE Interrupt during execution: Accepted Register/memory R0L Row size of array R0H ...

Page 126

Explanation This program searches for specified data from a two-dimensional array of a given size (maximum 255 x 255 bytes). Set the start address of the array in A0, the row size of the array in R0L, the ...

Page 127

Flowchart ENTER Row setting of array = 0? No Column setting of array = 0? No Calculate entire area of array Coincidence data? No Set address difference from start to coincidence data Decompose coincidence data into row and ...

Page 128

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VromTOP ; ;============================================================== ; Title: Searching array ; Outline: Searches for data from two-dimensional array of given size (within 255 x 255 bytes) ; ...

Page 129

Converting from Lowercase Alphabet to Uppercase Alphabet 2.26.1 Outline This program converts a lowercase English alphabet in ASCII code into an uppercase English alphabet in ASCII code. Subroutine name : TOUPPER Interrupt during execution: Accepted Register/memory R0L Lowercase ...

Page 130

Explanation This program converts a lowercase English alphabet in ASCII code into an uppercase English alphabet in ASCII code. Set the lowercase English alphabet in ASCII code in R0L. The converted uppercase English alphabet in ASCII code is ...

Page 131

Flowchart ENTER R0L 'a' ? Yes R0L 'z' ? Yes R0L - 20H -> R0L Conversion succeeded Clear C flag EXIT Collection of General-purpose Programs 2.26 Converting from Lowercase Alphabet to Uppercase Alphabet No No Conversion failed Set ...

Page 132

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VromTOP ;============================================================== ; Title: Converting ASCII code lowercase alphabet into uppercase alphabet ; Contents of processing: ; The ASCII code input in R0L is ...

Page 133

Converting from Uppercase Alphabet to Lowercase Alphabet 2.27.1 Outline This program converts an uppercase English alphabet in ASCII code into a lowercase English alphabet in ASCII code. Subroutine name : TOLOWER Interrupt during execution: Accepted Register/memory R0L Uppercase ...

Page 134

Explanation This program converts an uppercase English alphabet in ASCII code into a lowercase English alphabet in ASCII code. Set the uppercase English alphabet in ASCII code in R0L. The converted lowercase English alphabet in ASCII code is ...

Page 135

Flowchart ENTER R0L 'A' ? Yes R0L 'Z' ? Yes R0L + 20H -> R0L Conversion succeeded Clear C flag EXIT Collection of General-purpose Programs 2.27 Converting from Uppercase Alphabet to Lowercase Alphabet No No Conversion failed Set ...

Page 136

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VromTOP ; ;============================================================== ; Title: Converting ASCII code uppercase alphabet into lowercase alphabet ; Contents of processing: ; The ASCII code input in R0L ...

Page 137

Converting from ASCII to Hexadecimal Data 2.28.1 Outline This program converts ASCII code into hexadecimal data. Subroutine name : ATOH Interrupt during execution: Accepted Register/memory R0L R0H flag Usage precautions Collection of ...

Page 138

Explanation This program converts ASCII code into hexadecimal data. The ASCII code that can be converted are numbers from ‘0’ to ‘9’ and alphabets from ‘a’ to ‘f’ and ‘A’ to ‘F’. Set ASCII code in R0L. The ...

Page 139

Flowchart ENTER No R0L = 'A' to 'F' ? Yes R0L - ' --> R0L Conversion succeeded Clear C flag EXIT Collection of General-purpose Programs 2.28 Converting from ASCII to Hexadecimal Data No R0L = 'a' ...

Page 140

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VromTOP ;============================================================== ; Title: Converting ASCII code into hexadecimal ; Contents of processing: ; The ASCII code input in R0L is converted into hexadecimal ...

Page 141

Converting from Hexadecimal Data to ASCII Code 2.29.1 Outline This program converts hexadecimal data into ASCII code. Subroutine name : HTOA Interrupt during execution: Accepted Register/memory R0L R0H flag Usage precautions Collection ...

Page 142

Explanation This program converts hexadecimal data into ASCII code. The hexadecimal data that can be converted are from “00H” to “0FH.” The converted ASCII code are numbers from ‘0’ to ‘9’ and alphabets from ‘A’ to ‘F’. Set ...

Page 143

Flowchart ENTER R0L 0FH ? Yes R0L 0AH ? Yes R0L + ' --> R0L Conversion succeeded Clear C flag EXIT Collection of General-purpose Programs 2.29 Converting from Hexadecimal Data to ASCII Code No No R0L ...

Page 144

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VromTOP ;============================================================== ; Title: Converting hexadecimal into ASCII code ; Contents of processing: ; The hexadecimal data input in R0L is converted into ASCII ...

Page 145

Example for Initial Setting Assembler 2.30.1 Outline This program is an example of initial settings accomplished by using the directive commands of the assembler. 2.30.2 Explanation The program shown here consists of the following: (1) Map file information ...

Page 146

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** ;============================================================== ; Title: Initial settings using assembler’s directive commands ; Outline: ; (1) Assemble control ; (2) Address control ; (3) Link control ; ...

Page 147

RAM area allocation ;//////////////////////////////////////////////////////////////////////////////////// CHAR: .BLKB ; SHORT: .BLKW ; ADDR: .BLKA ; LONG: .BLKL ; SFLOAT: .BLKF ; DFLOAT: .BLKD ; CHECK: .BLKW ; ;//////////////////////////////////////////////////////////////////////////////////// ; Bit symbol definition ;//////////////////////////////////////////////////////////////////////////////////// BIT4 .BTEQU MSB .BTEQU P0_7 .BTEQU ...

Page 148

Main program ;=============================================== MAIN: MOV MOV JSR BSET ROUTINE: (Processing) RTS ROUTINE: (Processing) RTS .PAGE 'VECTOR' .SECTION .ORG ;=============================================== ; Peripheral I/O interrupt vector table ;=============================================== .LWORD .LWORD .SECTION .ORG ;=============================================== ; Nonmaskable ...

Page 149

Special Page Subroutine 2.31.1 Outline This program is an example for using a special subroutine call. 2.31.2 Explanation The program branches to a subroutine at an address that is the address set in one of the special page ...

Page 150

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VromTOP ; ;============================================================== ; Title: Special page subroutine call ; Outline: Description example of special page subroutine call ; Input: ------------------------------> ...

Page 151

Special Page Jump 2.32.1 Outline This program is an example for using a special page jump. 2.32.2 Explanation Control jumps to an address that is set in one of the special page vector tables (in 2 bytes each) ...

Page 152

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VromTOP ; ;============================================================== ; Title: Special page subroutine call ; Outline: Description example of special page subroutine call ; Input: ------------------------------> ...

Page 153

Variable Vector Table 2.33.1 Outline This program shows an example for setting variable vector tables and an example for using software interrupts. 2.33.2 Explanation A variable vector table is a 256-byte interrupt vector table whose start address (IntBase) ...

Page 154

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VromTOP VIstack Vintbase ; ;============================================================== ; Title: Variable vector table ; Outline: Description example of variable vector table and software interrupt ;============================================================== MAIN: LDC ...

Page 155

Peripheral I/O interrupt vector table ;---------------------------------------------------------------------------------- ; ; ;---------------------------------------------------------------------------------- ; Software interrupt vector table ;---------------------------------------------------------------------------------- ; .END Collection of General-purpose Programs .LWORD NOTUSE .LWORD NOTUSE .ORG Vintbase+84 .LWORD TIMER_A0 .LWORD TIMER_A1 .ORG Vintbase+128 .LWORD SOFTINT .LWORD NOTUSE ...

Page 156

Saving and Restoring Context 2.34.1 Outline This program shows a usage example for saving context (STCTX instruction) and restoring context (LDCTX instruction). 2.34.2 Explanation Tasks are executed in the main routine and context save and restore operations are ...

Page 157

Program List ;******************************************************************************************** ; ; M16C Program Collection No CPU ; ;******************************************************************************************** VramTOP VromTOP Vcontext Vsubtbl ; TASK: ; ;============================================================== ; Title: Saving/restoring context ; Outline: Example for using STCTX/LDCTX instructions ; Notes: ;============================================================== MAIN: MOV.B ...

Page 158

Processing of task 2 ;---------------------------------------------------------------------------------- TASK_2: STCTX Processing LDCTX RTS ; ;---------------------------------------------------------------------------------- ; Context information table ;---------------------------------------------------------------------------------- ; ; ; ;---------------------------------------------------------------------------------- ; Subroutine table ;---------------------------------------------------------------------------------- ; .END Collection of General-purpose Programs TASK,Vcontext TASK,Vcontext .SECTION BASE,ROMDATA .ORG Vcontext ...

Page 159

MEMO Collection of General-purpose Programs 2.34 Saving and Restoring Context 152 ...

Page 160

Program Collection of Mathematic/Trigonometric Functions Chapter 3 ...

Page 161

Function list Item No. 3.1 Single-precision, floating-point format 3.2 Addition 3.3 Subtraction 3.4 Multiplication 3.5 Division 3.6 Sine function 3.7 Cosine function 3.8 Tangent function 3.9 Inverse sine function 3.10 Inverse cosine function 3.11 Inverse tangent function 3.12 Square ...

Page 162

Single-precision, Floating-point Format 3.1.1 Outline The floating-point data used in this arithmetic library conforms to the single-precision (4-byte), floating- point format in IEEE standards. All calculations in this arithmetic library are performed by replacing or referencing register contents. ...

Page 163

Exponent Part The exponent part uses an 8-bit unsigned binary number to express ‘e’ expressed by a value that is prebiased by adding 7F numbers.) Consequently, the actual exponent value and the representation of the exponent ...

Page 164

Arguments and Return Values This section explains the floating-point arguments and return values used in this arithmetic library. The first operand (or the number to be operated on argument is assigned to registers (R2R0) and the ...

Page 165

Addition 3.2.1 Outline This program adds float-point numbers. The first operand (R2R0) is added to the second operand (R3R1) and the result is stored in (R2R0). Calculation result (R2R0) = first operand (R2R0) + second operand (R3R1) Subroutine ...

Page 166

Explanation Procedure: (1) Store the first operand (normalized single-precision, floating-point number and R0 sign, exponent, upper part of mantissa R0 = mid and lower parts of mantissa (2) Store the second operand (normalized single-precision, ...

Page 167

Subtraction 3.3.1 Outline This program subtracts floating-point numbers. The first operand (R2R0) and second operand (R3R1) are subtracted and the result is stored in (R2R0). Calculation result (R2R0) = first operand (R2R0) – second operand (R3R1) Subroutine name: ...

Page 168

Explanation Procedure: (1) Store the first operand (normalized single-precision, floating-point number and R0 sign, exponent, upper part of mantissa R0 = mid and lower parts of mantissa (2) Store the second operand (normalized single-precision, ...

Page 169

Multiplication 3.4.1 Outline This program multiplies floating-point numbers. The first operand (R2R0) and second operand (R3R1) are multiplied and the result is stored in (R2R0). Calculation result (R2R0) = first operand (R2R0) x second operand (R3R1) Subroutine name: ...

Page 170

Explanation Procedure: (1) Store the first operand (normalized single-precision, floating-point number and R0 sign, exponent, upper part of mantissa R0 = mid and lower parts of mantissa (2) Store the second operand (normalized single-precision, ...

Page 171

Division 3.5.1 Outline This program divides floating-point numbers. The first operand (R2R0) and second operand (R3R1) are multiplied and the result is stored in (R2R0). Calculation result (R2R0) = first operand (R2R0) Subroutine name: FDIV Interrupt during execution: ...

Page 172

Explanation Procedure: (1) Store the first operand (normalized single-precision, floating-point number and R0 sign, exponent, upper part of mantissa R0 = mid and lower parts of mantissa (2) Store the second operand (normalized single-precision, ...

Page 173

Sine Function 3.6.1 Outline This program finds a sine of the operand (R2R0) comprised of a single-precision, floating-point number and stores the result in (R2R0). (R2R0) = SIN(R2R0) The unit is radian. Make sure the operand is smaller ...

Page 174

Explanation Procedure: (1) Store the operand (normalized single-precision, floating-point number and R0 sign, exponent, upper part of mantissa R0 = mid and lower parts of mantissa (2) Call the subroutine (FSIN). Calculation result: The ...

Page 175

Cosine Function 3.7.1 Outline This program finds a cosine of the operand (R2R0) comprised of a single-precision, floating-point num- ber and stores the result in (R2R0). (R2R0) = COS(R2R0) The unit is radian. Make sure the operand is ...

Page 176

Explanation Procedure: (1) Store the operand (normalized single-precision, floating-point number and R0 sign, exponent, upper part of mantissa R0 = mid and lower parts of mantissa (2) Call the subroutine (FCOS). Calculation result: The ...

Page 177

Tangent Function 3.8.1 Outline This program finds a tangent of the operand (R2R0) comprised of a single-precision, floating-point num- ber and stores the result in (R2R0). (R2R0) = TAN(R2R0) The unit is radian. Make sure the operand is ...

Page 178

Explanation Procedure: (1) Store the operand (normalized single-precision, floating-point number and R0 sign, exponent, upper part of mantissa R0 = mid and lower parts of mantissa (2) Call the subroutine (FTAN). Calculation result: The ...

Page 179

Inverse Sine Function 3.9.1 Outline This program finds an inverse sine of the operand (R2R0) comprised of a single-precision, floating-point number and stores the result in (R2R0). –1 (R2R0) = SIN (R2R0) The unit is radian. Make sure ...

Page 180

Explanation Procedure: (1) Store the operand (normalized single-precision, floating-point number and R0 sign, exponent, upper part of mantissa R0 = mid and lower parts of mantissa (2) Call the subroutine (FASN). Calculation result: The ...

Page 181

Inverse Cosine Function 3.10.1 Outline This program finds an inverse cosine of the operand (R2R0) consisting of a single-precision, floating- point number and stores the result in (R2R0). –1 (R2R0) = COS (R2R0) The unit is radian. Make ...

Page 182

Explanation Procedure: (1) Store the operand (normalized single-precision, floating-point number and R0 sign, exponent, upper part of mantissa R0 = mid and lower parts of mantissa (2) Call the subroutine (FACN). Calculation result: The ...

Page 183

Inverse Tangent Function 3.11.1 Outline This program finds an inverse tangent of the operand (R2R0) consisting of a single-precision, floating- point number and stores the result in (R2R0). –1 (R2R0) = TAN (R2R0) The unit is radian. Make ...

Page 184

Explanation Procedure: (1) Store the operand (normalized single-precision, floating-point number and R0 sign, exponent, upper part of mantissa R0 = mid and lower parts of mantissa (2) Call the subroutine (FATN). Calculation result: The ...

Page 185

Square Root 3.12.1 Outline This program finds a square root of the operand (R2R0) consisting of a single-precision, floating-point number and stores the result in (R2R0). (R2R0) = (R2R0) Subroutine name: FSQR Interrupt during execution: Accepted Register/memory R0 ...

Page 186

Explanation Procedure: (1) Store the operand (normalized single-precision, floating-point number and R0 sign, exponent, upper part of mantissa R0 = mid and lower parts of mantissa (2) Call the subroutine (FSQR). Calculation result: The ...

Page 187

Power 3.13.1 Outline This program finds a product of the operand (R2R0) consisting of a single-precision, floating-point num- ber raised to the power of exponent data (R3R1) and stores the result in (R2R0). (R3R1) (R2R0) = (R2R0) Subroutine ...

Page 188

Explanation Procedure: (1) Store the operand (normalized single-precision, floating-point number and R0 sign, exponent, upper part of mantissa R0 = mid and lower parts of mantissa (2) Store the exponent data (normalized single-precision, floating-point ...

Page 189

Exponential Function 3.14.1 Outline This program finds an exponential function of the operand (R2R0) consisting of a single-precision, float- ing- point number and stores the result in (R2R0). (R2R0) (R2R0 Subroutine name: FEXP Interrupt during execution: ...

Page 190

Explanation Procedure: (1) Store the operand (normalized single-precision, floating-point number and R0 sign, exponent, upper part of mantissa R0 = mid and lower parts of mantissa (2) Call the subroutine (FEXP). Calculation result: The ...

Page 191

Natural Logarithmic Function 3.15.1 Outline This program finds a natural logarithmic function of the operand (R2R0) consisting of a single-precision, floating-point number and stores the result in (R2R0). (R2R0) = LN(R2R0) Subroutine name: FLN Interrupt during execution: Accepted ...

Page 192

Explanation Procedure: (1) Store the operand (normalized single-precision, floating-point number and R0 sign, exponent, upper part of mantissa R0 = mid and lower parts of mantissa (2) Call the subroutine (FLN). Calculation result: The ...

Page 193

Common Logarithmic Function 3.16.1 Outline This program finds a common logarithmic function of the operand (R2R0) consisting of a single-preci- sion, floating- point number and stores the result in (R2R0). (R2R0) = LOG(R2R0) Subroutine name: FLOG Interrupt during ...

Page 194

Explanation Procedure: (1) Store the operand (normalized single-precision, floating-point number and R0 sign, exponent, upper part of mantissa R0 = mid and lower parts of mantissa (2) Call the subroutine (FLOG). Calculation result: The ...

Page 195

Data Comparison 3.17.1 Outline This program compares the operand (R2R0) consisting of a single-precision, floating-point number with comparison data (R3R1) and sets the result in flags. Flag = operand (R2R0): comparison data (R3R1) Subroutine name: FCMP Interrupt during ...

Page 196

Explanation Procedure: (1) Store the operand (normalized single-precision, floating-point number and R0 sign, exponent, upper part of mantissa R0 = mid and lower parts of mantissa (2) Store the comparison data (normalized single-precision, floating-point ...

Page 197

Conversion from FLOAT Type to WORD Type 3.18.1 Outline This program converts the content of the registers (R2R0) consisting of a single-precision, floating-point number into an integer of the WORD (16-bit) type and stores the result in (R3R1). ...

Page 198

Explanation Procedure: (1) Store FLOAT data (normalized single-precision, floating-point number and R0 sign, exponent, upper part of mantissa R0 = mid and lower parts of mantissa (2) Call the subroutine (FTOI). Result: The result ...

Page 199

Conversion from WORD Type to FLOAT Type 3.19.1 Outline This program converts the content of a WORD (16-bit) type integer (R0) into a normalized single-preci- sion, floating-point number and stores the result in (R2R0). Subroutine name: ITOF Interrupt ...

Page 200

Explanation Procedure: (1) Store a WORD type integer in R0. (2) Call the subroutine (ITOF). Result: The result is placed in R2 and R0 sign, exponent, upper part of mantissa R0 = mid and lower parts ...

Related keywords