![]() |
|
If you can't view the Datasheet, Please click here to try to view without PDF Reader . |
|
Datasheet File OCR Text: |
S3FB42F 8-bit cmos microcontroller user's manual revision 1
important notice the information in this publication has been carefully checked and is believed to be entirely accurate at the time of publication. samsung assumes no responsibility, however, for possible errors or omissions, or for any consequences resulting from the use of the information contained herein. samsung reserves the right to make changes in its products or product specifications with the intent to improve function or design at any time and without notice and is not required to update this documentation to reflect such changes. this publication does not convey to a purchaser of semiconductor devices described herein any license under the patent rights of samsung or others. samsung makes no warranty, representation, or guarantee regarding the suitability of its products for any particular purpose, nor does samsung assume any liability arising out of the application or use of any product or circuit and specifically disclaims any and all liability, including without limitation any consequential or incidental damages. "typical" parameters can and do vary in different applications. all operating parameters, including " typicals" must be validated for each customer application by the customer's technical experts. samsung products are not designed, intended, or authorized for use as components in systems intended for surgical implant into the body, for other applications intended to support or sustain life, or for any other application in which the failure of the samsung product could create a situation where personal injury or death may occur. should the buyer purchase or use a samsung product for any such unintended or unauthorized application, the buyer shall indemnify and hold samsung and its officers, employees, subsidiaries, affiliates, and distributors harmless against all claims, costs, damages, expenses, and reasonable attorney fees arising out of, either directly or indirectly, any claim of personal injury or death that may be associated with such unintended or unauthorized use, even if such claim alleges that samsung was negligent regarding the design or manufacture of said product. S3FB42F 8-bit cmos microcontroller user's manual, revision 1 publication number: 2 1 - s3-fb42f - 052001 ? 2001 samsung electronics all rights reserved. no part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electric or mechanical, by photocopying, recording, or otherwise, without the prior written consent of samsung electronics. samsung electronics' microcontroller business has been awarded full iso- 140 01 certification (b vq1 certificate no. 9330 ). all semiconductor products are designed and manufactured in accordance with the highest quality standards and objectives. samsung electronics co., ltd. san #24 nongseo-lee, kiheung-eup yongin-city kyungi-do, korea c.p.o. box #37, suwon 449-900 tel: (82)-(331 ) -209-1907 fax: ( 8 2) -(331)-209-1889 home-page url: http:// www.samsung semi .com/ printed in the republic of korea S3FB42F microcontroller iii preface the S3FB42F microcontroller user's manual is designed for application designers and progr ammers who are using the S3FB42F microcontroller for application development. it is organized in two main parts: part i programming model part ii hardware descriptions part i contains software-related information to familiarize you with the microcontroller's architecture, programming model, instruction set, and interrupt structure. it has nine chapter s: chapter 1 product overview chapter 2 address spaces chapter 3 register chapter 4 memory map chapter 5 hardware stack chapter 6 exceptions chapter 7 coprocessor interface chapter 8 instruction set chapter 1, "product overview," is a high-l evel introduction to S3FB42F with general product descriptions, as well as detailed information about individual pin characteristics and pin circuit types. chapter 2, "address spaces," describes program and data memory spaces . chapter 2 also describes rom code option. chapter 3, " register ," describes the special registers. chapter 4, " memory map ," describes the internal register file. chapter 5, " hardware stack," describes the S3FB42F hardware stack structure in detail . chapter 6, " exception ," describes the S3FB42F exception structure in detail . chapter 7, ?coprocessor interface,? describes the S3FB42F coprocessor interface in detail. chapter 8, ?instruction set,? describes the features and conventions of the instruction set used for all s3fb-series microcontrollers. a basic familiarity with the information in part i will help you to understand the hardware module descriptions in part ii. if you are not yet familiar with the s3fb-series microcontroller family and are reading this manual for the first time, we recommend that you first read chapter s 1 ? 3 carefully. then, briefly look over the detailed information in chapter s 4, 5, 6, 7, and 8 . later, you can reference the information in part i as necessary. part ii "hardware descriptions," has detailed information about specific hardware components of the S3FB42F microcontroller. also included in part ii are electrical, mechanical. it has 19 chapter s: chapter 9 pll (phase locked loop) chapter 10 reset and power-down chapter 1 1 i/o ports chapter 1 2 basic timer chapter 1 3 real timer (watch timer) chapter 1 4 16-bit timer (8-bit timer a & b) chapter 1 5 serial i/o interface chapter 16 uart chapter 17 i 2 s bus (inter-ic sound) chapter 18 ssfdc (solid state floppy disk card) chapter 19 parallel port interface chapter 20 8-bit analog-to-digital converter chapter 21 i 2 c-bus interface chapter 22 random number generator chapter 23 usb chapter 24 embedded flash memory interface chapter 25 mac2424 chapter 26 electrical data chapter 27 mechanical data chapter 25 , "mac2424" describes the mac2424 structure in detail, as well as instructions. iv ks86c6204/c6208/p6 208 ( preliminary spec ) one order form is included at the back of this manual to facilitate customer order for S3FB42F microcontrollers: the flash factory writing order form. you can photocopy this form, fill it out, and then forward it to your local samsung sales representative. S3FB42F microcontroller v table of contents part i ? programming model chapter 1 product overview calmrisc overview ................................ ................................ ................................ ............................... 1-1 features ................................ ................................ ................................ ................................ ............. 1-1 pin description ................................ ................................ ................................ ................................ .... 1-9 pin circuit diagrams ................................ ................................ ................................ ............................ 1-13 chapter 2 address spaces overview ................................ ................................ ................................ ................................ ............. 2-1 program memory (rom) ................................ ................................ ................................ ...................... 2-2 data memory organization ................................ ................................ ................................ ................... 2-3 chapter 3 register overview ................................ ................................ ................................ ................................ ............. 3-1 index registers: idh, idl0 and idl1 ................................ ................................ .............................. 3-2 link registers: ilx, ilh and ill ................................ ................................ ................................ .... 3-2 status register 0: sr0 ................................ ................................ ................................ ................ 3-3 status register 1: sr1 ................................ ................................ ................................ ................ 3-4 chapter 4 memory map overview ................................ ................................ ................................ ................................ ............. 4-1 chapter 5 hardware stack overview ................................ ................................ ................................ ................................ ............. 5-1 vi S3FB42F microcontroller table of contents (continued) chapter 6 exceptions overview ................................ ................................ ................................ ................................ ............. 6-1 hardware reset ................................ ................................ ................................ ........................... 6-1 nmi exception (edge sensitive) ................................ ................................ ................................ .... 6-2 irq[0] exception (level-sensitive) ................................ ................................ ................................ . 6-2 irq[1] exception (level-sensitive) ................................ ................................ ................................ . 6-2 hardware stack full exception ................................ ................................ ................................ ..... 6-2 break exception ................................ ................................ ................................ .......................... 6-2 exceptions (or interrupts) ................................ ................................ ................................ ............. 6-3 interrupt mask registers ................................ ................................ ................................ .............. 6-5 interrupt priority register ................................ ................................ ................................ .............. 6-6 chapter 7 coprocessor interface overview ................................ ................................ ................................ ................................ ............. 7-1 chapter 8 instruction set overview ................................ ................................ ................................ ................................ ............. 8-1 glossary ................................ ................................ ................................ ................................ ..... 8-1 instruction set map ................................ ................................ ................................ ............................. 8-2 quick reference ................................ ................................ ................................ ................................ .. 8-9 instruction group summary ................................ ................................ ................................ .................. 8-12 alu instructions ................................ ................................ ................................ .......................... 8-12 shift/rotate instructions ................................ ................................ ................................ ............... 8-16 load instructions ................................ ................................ ................................ ......................... 8-18 branch instructions ................................ ................................ ................................ ...................... 8-21 bit manipulation instructions ................................ ................................ ................................ ......... 8-25 miscellaneous instruction ................................ ................................ ................................ ............. 8-26 pseudo instructions ................................ ................................ ................................ ..................... 8-29 S3FB42F microcontroller vii table of contents (continued) part ii ? hardware descriptions chapter 9 pll (phase locked loop) overview ................................ ................................ ................................ ................................ ............. 9-1 pll register description ................................ ................................ ................................ ...................... 9-2 pll control register (pllcon) ................................ ................................ ................................ .... 9-2 pll frequency divider data register (plldata) ................................ ................................ ........... 9-2 system control circuit ................................ ................................ ................................ ......................... 9-4 oscillator control register (osccon) ................................ ................................ ........................... 9-4 power control register (pcon) ................................ ................................ ................................ .... 9-5 chapter 10 reset and power-down overview ................................ ................................ ................................ ................................ ............. 10-1 chapter 11 i/o ports port data registers ................................ ................................ ................................ ............................. 11-1 port control registers ................................ ................................ ................................ .......................... 11-2 port 0 control register (p0con) ................................ ................................ ................................ ... 11-2 port 1 control register (p1con) ................................ ................................ ................................ ... 11-2 port 2 control low register (p2conl) ................................ ................................ .......................... 11-3 port 2 control high register (p2conh) ................................ ................................ ......................... 11-4 port 3 control low register (p3conl) ................................ ................................ .......................... 11-5 port 3 control high register (p3conh) ................................ ................................ ......................... 11-6 port 3 pull-up register (p3pur) ................................ ................................ ................................ ... 11-6 port 4 control register (p4con) ................................ ................................ ................................ ... 11-7 port 4 interrupt control register (p4intcon) ................................ ................................ ................. 11-7 port 4 interrupt mode register (p4intmod) ................................ ................................ ................... 11-8 port 5 control register (p5con) ................................ ................................ ................................ ... 11-8 port 5 pull-up register (p5pur) ................................ ................................ ................................ ... 11-9 port 5 interrupt control register (p5intcon) ................................ ................................ ................. 11-9 port 5 external interrupt pending register (eintpnd) ................................ ................................ ..... 11-9 port 5 interrupt mode low register (p5intmodl) ................................ ................................ .......... 11-9 port 5 interrupt mode high register (p5intmodh) ................................ ................................ ......... 11-10 port 6 control register (p6con) ................................ ................................ ................................ ... 11-11 port 2 control high register or p6pur (p2conh) ................................ ................................ ........... 11-12 port 7 control register (p7con) ................................ ................................ ................................ ... 11-12 port 8 control register (p8con) ................................ ................................ ................................ ... 11-13 port 9 control register (p9con) ................................ ................................ ................................ ... 11-14 viii S3FB42F microcontroller table of contents (continued) chapter 12 basic timer overview ................................ ................................ ................................ ................................ ............. 12-1 watchdog timer ................................ ................................ ................................ ................................ .. 12-2 block diagram ................................ ................................ ................................ ............................ 12-3 chapter 13 real timer (watch timer) overview ................................ ................................ ................................ ................................ ............. 13-1 watch timer circuit diagram ................................ ................................ ................................ ........ 13-2 chapter 14 16-bit timer (8-bit timer a & b) overview ................................ ................................ ................................ ................................ ............. 14-1 chapter 15 serial i/o interface overview ................................ ................................ ................................ ................................ ............. 15-1 sio pre-scaler register (siops) ................................ ................................ ................................ .......... 15-2 block diagram ................................ ................................ ................................ ................................ .... 15-2 serial i/o timing diagram ................................ ................................ ................................ ..................... 15-3 chapter 16 uart overview ................................ ................................ ................................ ................................ ............. 16-1 uart special registers ................................ ................................ ................................ ....................... 16-2 uart line control register ................................ ................................ ................................ .......... 16-2 uart control register ................................ ................................ ................................ ................. 16-3 uart status register ................................ ................................ ................................ .................. 16-4 uart transmit buffer register ................................ ................................ ................................ ..... 16-5 uart receive buffer register ................................ ................................ ................................ ....... 16-5 uart baud rate prescaler registers ................................ ................................ ........................... 16-6 uart interrupt pending register (upend) ................................ ................................ ...................... 16-6 S3FB42F microcontroller ix table of contents (continued) chapter 17 i 2 s bus (inter-ic sound) overview ................................ ................................ ................................ ................................ ............. 17-1 the i 2 s bus ................................ ................................ ................................ ................................ ........ 17-2 i 2 s special register description ................................ ................................ ................................ ........... 17-6 i 2 s control registers ................................ ................................ ................................ ................... 17-6 i 2 s control registers (iiscon) ................................ ................................ ................................ ..... 17-6 i 2 s mode registers (iismode) ................................ ................................ ................................ ..... 17-8 i 2 s pointer registers (iisptr) ................................ ................................ ................................ ...... 17-9 i 2 s buffer registers (iisbuf) ................................ ................................ ................................ ........ 17-9 chapter 18 ssfdc ( soild state floppy disk card) overview ................................ ................................ ................................ ................................ ............. 18-1 ssfdc register description ................................ ................................ ................................ ................ 18-3 smartmedia control register (smcon) ................................ ................................ ......................... 18-3 smartmedia ecc count register (eccnt) ................................ ................................ .................... 18-3 smartmedia ecc data register (eccdata) ................................ ................................ .................. 18-4 smartmedia ecc result data register (eccrst) ................................ ................................ .......... 18-4 chapter 19 parallel port interface overview ................................ ................................ ................................ ................................ ............. 19-1 ppic operating modes ................................ ................................ ................................ ................ 19-2 ppic special registers ................................ ................................ ................................ ........................ 19-5 parallel port data/command data register ................................ ................................ .................... 19-5 parallel port status control and status register ................................ ................................ ............ 19-6 parallel port control register ................................ ................................ ................................ ........ 19-8 parallel port interrupt event registers ................................ ................................ ........................... 19-11 parallel port ack width register ................................ ................................ ................................ ... 19-12 chapter 20 8-bit analog-to-digital converter overview ................................ ................................ ................................ ................................ ............. 20-1 function description ................................ ................................ ................................ ............................ 20-1 conversion timing ................................ ................................ ................................ ............................... 20-2 a/d c special registers ................................ ................................ ................................ ...................... 20-3 a/d c control registers ................................ ................................ ................................ ............... 20-3 a/d converter data registers ................................ ................................ ................................ ....... 20-3 x S3FB42F microcontroller table of contents (continued) chapter 21 i 2 c bus interface overview ................................ ................................ ................................ ................................ ............. 21-1 functional description ................................ ................................ ................................ ................. 21-2 i 2 c special registers ................................ ................................ ................................ ........................... 21-3 multi-master i 2 c-bus control register ................................ ................................ ........................... 21-3 multi-master i 2 c-bus control/status register (iicsr) ................................ ................................ ..... 21-4 multi-master i 2 c-bus transmit/receive data register (iicdata) ................................ ...................... 21-5 multi-master i 2 c-bus address register (iicaddr) ................................ ................................ .......... 21-5 prescaler counter register (iiccnt) ................................ ................................ .............................. 21-6 chapter 22 random number generator overview ................................ ................................ ................................ ................................ ............. 22-1 functional description ................................ ................................ ................................ ................. 22-3 random number control register ................................ ................................ ................................ . 22-3 ring oscillator ................................ ................................ ................................ ............................ 22-4 linear feedback shift register 8 (lfsr8) ................................ ................................ ..................... 22-5 linear feedback shift register 16 (lfsr16) ................................ ................................ .................. 22-5 chapter 23 usb usb peripheral features ................................ ................................ ................................ ..................... 23-1 functional specification ................................ ................................ ................................ ............... 23-1 usb module block diagram ................................ ................................ ................................ ................. 23-2 function description ................................ ................................ ................................ ............................ 23-3 usb function registers description ................................ ................................ ................................ ..... 23-5 usb releated registers ................................ ................................ ................................ ...................... 23-6 chapter 24 embedded flash memory interface overview ................................ ................................ ................................ ................................ ............. 24-1 tool program mode ................................ ................................ ................................ ..................... 24-1 flash memory control register ................................ ................................ ................................ ..... 24-3 S3FB42F microcontroller xi table of contents (continued) chapter 25 mac2424 introduction ................................ ................................ ................................ ................................ ......... 25-1 architecture features ................................ ................................ ................................ .......................... 25-2 block diagram ................................ ................................ ................................ ................................ .... 25-3 i/o description ................................ ................................ ................................ ................................ .... 25-4 programming model ................................ ................................ ................................ ............................. 25-6 multiplier and accumulator unit ................................ ................................ ................................ .... 25-7 arithmetic unit ................................ ................................ ................................ ............................ 25-11 status register 1 (msr1) ................................ ................................ ................................ ............ 25-16 ram pointer unit ................................ ................................ ................................ ................................ . 25-18 address modification ................................ ................................ ................................ ................... 25-18 data memory spaces and organization ................................ ................................ ......................... 25-23 arithmetic unit ................................ ................................ ................................ ................................ .... 25-24 a, b accumulators ................................ ................................ ................................ ...................... 25-25 overflow protection in a/b accumulators ................................ ................................ ....................... 25-25 arithmetic unit ................................ ................................ ................................ ............................ 25-26 external condition generation unit ................................ ................................ ................................ 25-27 status register 0 (msr0) ................................ ................................ ................................ ............ 25-27 status register 2 (msr2) ................................ ................................ ................................ ............ 25-30 barrel shifter and exponent unit ................................ ................................ ................................ ........... 25-31 barrel shifter ................................ ................................ ................................ ............................... 25-32 exponent block ................................ ................................ ................................ ........................... 25-35 instruction set map and summary ................................ ................................ ................................ ........ 25-37 addressing modes ................................ ................................ ................................ ....................... 25-37 instruction coding ................................ ................................ ................................ ........................ 25-42 quick reference ................................ ................................ ................................ .......................... 25-55 quick reference ................................ ................................ ................................ .......................... 25-56 instruction set ................................ ................................ ................................ ................................ ..... 25-60 glossary ................................ ................................ ................................ ................................ ..... 25-60 instruction description ................................ ................................ ................................ ................. 25-61 chapter 26 electrical data overview ................................ ................................ ................................ ................................ ............. 26-1 chapter 27 mechanical data overview ................................ ................................ ................................ ................................ ............. 27-1 S3FB42F microcontroller xiii list of figures figure title page number number 1-1 top block diagram ................................ ................................ .............................. 1-3 1-2 calmrisc pipeline diagram ................................ ................................ ................. 1-4 1-3 calmrisc pipeline stream diagram ................................ ................................ ...... 1-5 1-4 block diagram ................................ ................................ ................................ .... 1-6 1-5 100-qfp pin assignment ................................ ................................ ..................... 1-7 1-6 100-tqfp pin assignment ................................ ................................ ................... 1-8 1-7 pin circuit type 1 (port 0, p1.0-p1.4, p6.0-p6.5, and port 7) ................................ .. 1-13 1-8 pin circuit type 2 (p6.6 and p6.7) ................................ ................................ ........ 1-13 1-9 pin circuit type 3 (p4.2) ................................ ................................ ...................... 1-14 1-10 pin circuit type 4 (port 2, port 8, and port 9) ................................ ........................ 1-15 1-11 pin circuit type 5 (port 3) ................................ ................................ .................... 1-15 1-12 pin circuit type 6 (p4.0, and p4.1) ................................ ................................ ....... 1-16 1-13 pin circuit type 7 (port 5) ................................ ................................ .................... 1-16 1-14 pin circuit type 8 (reset) ................................ ................................ .................. 1-17 1-15 pin circuit type 9 (test) ................................ ................................ ..................... 1-17 2-1 flash memory (code memory area) ................................ ................................ ...... 2-2 2-2 data memory map ................................ ................................ ............................... 2-3 2-3 data memory map in calmrisc side ................................ ................................ .... 2-4 2-4 data memory map in mac-2424 side ................................ ................................ .... 2-5 2-5 data memory map ................................ ................................ ............................... 2-6 3-1 bank selection by setting of grb bits and idb bit ................................ ................ 3-3 4-1 memory map area ................................ ................................ ............................... 4-1 5-1 hardware stack ................................ ................................ ................................ ... 5-1 5-2 even and odd bank selection example ................................ ................................ . 5-2 5-3 stack operation with pc [19:0] ................................ ................................ ............. 5-3 5-4 stack operation with registers ................................ ................................ ............. 5-4 5-5 stack overflow ................................ ................................ ................................ .... 5-5 6-1 interrupt structure ................................ ................................ ................................ 6-3 6-2 interrupt structure ................................ ................................ ................................ 6-4 6-3 interrupt mask register ................................ ................................ ........................ 6-5 6-4 interr upt priority register ................................ ................................ ...................... 6-6 xiv S3FB42F microcontroller list of figures (continued) figure title page number number 7-1 coprocessor interface diagram ................................ ................................ ............. 7-1 7-2 coprocessor instruction pipeline ................................ ................................ ........... 7-3 9-1 simple circuit diagram ................................ ................................ ........................ 9-1 9-2 pll frequency divider data register (plldata) ................................ ................... 9-3 9-3 system clock circuit diagram ................................ ................................ .............. 9-6 11-1 port data register structure ................................ ................................ ................. 11-1 12-1 basic timer control register (btcon) ................................ ................................ .. 12-1 12-2 watchdog timer control register (wdtcon) ................................ ........................ 12-2 12-3 watchdog timer enable register (wdten) ................................ ........................... 12-2 12-4 basic timer & watchdog timer functional block diagram ................................ ...... 12-3 13-1 watch timer circuit diagram ................................ ................................ ................ 13-2 14-1 timer a control register (tacon) ................................ ................................ ........ 14-1 14-2 timer b control register (tbcon) ................................ ................................ ........ 14-2 14-3 timer a, b function block diagram ................................ ................................ ...... 14-3 15-1 serial i/o module control registers (siocon) ................................ ....................... 15-1 15-2 sio pre-scaler register (siops) ................................ ................................ .......... 15-2 15-3 sio function block diagram ................................ ................................ ................ 15-2 15-4 serial i/o timing in transmit/receive mode (tx at falling, siocon.4=0) ................... 15-3 15-5 serial i/o timing in transmit/receive mode (tx at rising, siocon.4=1) ................... 15-3 16-1 uart block diagram ................................ ................................ ........................... 16-1 16-2 uart line control register (lcon) ................................ ................................ ...... 16-2 17-1 simple system configuration ................................ ................................ ................ 17-1 17-2 i 2 s basic interface format (phillips) ................................ ................................ ...... 17-2 17-3 lsi interface format (sony) ................................ ................................ .................. 17-2 17-4 timing for i 2 s transmitter ................................ ................................ ..................... 17-4 17-5 timing for i 2 s receiver ................................ ................................ ......................... 17-4 18-1 simple system configuration ................................ ................................ ................ 18-2 18-2 ecc processor block diagram ................................ ................................ ............. 18-5 S3FB42F microcontroller xv list of figures (continued) figure title page number number 19-1 compatibility hardware handshaking timing ................................ .......................... 19-3 19-2 ecp hardware handshaking timing (forward) ................................ ........................ 19-4 19-3 ecp h ardware handshaking timing (reverse) ................................ ........................ 19-4 20-1 a/d c block diagram ................................ ................................ ........................... 20-2 21-1 i 2 c-bus block diagram ................................ ................................ ........................ 22-1 21-2 multi-master i 2 c-bus tx/rx data register (iicdata) ................................ .............. 22-5 21-3 multi-master i 2 c-bus address register (iicaddr) ................................ .................. 22-6 22 -1 top block diagram of random number generator ................................ .................. 22-2 22-2 ring oscillator block ................................ ................................ ........................... 22-4 23-1 usb module block diagram ................................ ................................ ................. 23-2 23-2 function address register ................................ ................................ ................... 23-6 23-3 power management register ................................ ................................ ................ 23-7 23-4 frame number low register ................................ ................................ ................ 23-8 23-5 frame number high register ................................ ................................ ................ 23-8 23-6 interrupt pe nding register ................................ ................................ .................... 23-9 23-7 interrupt enable register ................................ ................................ ...................... 23-11 23-8 endpoint index register ................................ ................................ ....................... 23-12 23-9 endpoint direction register ................................ ................................ .................. 23-12 23-10 ep0 csr register (ep0csr) ................................ ................................ ............... 23-14 23-11 incsr register ................................ ................................ ................................ ... 23-16 23-12 out control status register ................................ ................................ ................ 23-18 23-13 in max packet register (inmaxp) ................................ ................................ ........ 23-19 23-14 out max packet register ................................ ................................ ................... 23-20 23-15 ep0 max packet register ................................ ................................ ................... 23-21 23-16 write counter lo regsiter ................................ ................................ ................... 23-22 23-17 write counter hi register ................................ ................................ ..................... 23-22 23-18 usb enable register ................................ ................................ ........................... 23-24 24-1 flash memory structure ................................ ................................ ....................... 24-2 24-2 flash memory control register ................................ ................................ ............. 24-4 xvi S3FB42F microcontroller list of figures (continued) figure title page number number 25-1 mac2424 block diagram ................................ ................................ ..................... 25-3 25-2 mac2424 pin diagram ................................ ................................ ......................... 25-4 25-3 multiplier and accumulator unit block diagram ................................ ...................... 25-7 25-4 mau registers configuration ................................ ................................ ................ 25-10 25-5 integer division example ................................ ................................ ...................... 25-13 25-6 fractional division example ................................ ................................ .................. 25-14 25-7 msr1 register configuration ................................ ................................ ................ 25-16 25-8 ram pointer unit block diagram ................................ ................................ .......... 25-19 25-9 pointer register and index register configuration ................................ ................... 25-20 25-10 modulo control register configuration ................................ ................................ ... 25-21 25-11 data memory space map ................................ ................................ ..................... 25-23 25-12 arithmetic unit block diagram ................................ ................................ .............. 25-24 25-13 ai accumulator register configuration ................................ ................................ ... 25-25 25-14 msr0 register configuration ................................ ................................ ................ 25-27 25-15 msr2 register configuration ................................ ................................ ................ 25-30 25-16 barrel shifter and exponent unit block diagram ................................ ..................... 25-31 25-17 various barrel shifter instruction operation ................................ ............................ 25-34 25-18 indirect addressing example i (read operation) ................................ ..................... 25-37 25-19 indirect addressing example ii (write operation) ................................ .................... 25-38 25-20 short direct addressing example ................................ ................................ ......... 25-39 25-21 long direct addressing example ................................ ................................ .......... 25-40 26-1 input timing for external interrupts (port 4, port5) ................................ ................... 26-3 26-2 input timing for reset ................................ ................................ ........................ 26-3 26-3 stop mode release timing when initiated by a reset ................................ .......... 26-6 26-4 stop mode release timing when initiated by interrupts ................................ .......... 26-7 26-5 serial data transfer timing ................................ ................................ ................... 26-8 26-6 clock timing measurement at x in ................................ ................................ ......... 26-11 27-1 100-qfp-1420c package dimensions ................................ ................................ ... 27-1 27-2 100-tqfp-1414 package dimensions ................................ ................................ ... 27-2 S3FB42F microcontroller xvii list of tables table title page number number 1-1 S3FB42F pin descriptions (100-tqfp) ................................ ................................ . 1-9 3-1 general and special purpose registers ................................ ................................ . 3-1 3-2 status register 0: sr0 ................................ ................................ ........................ 3-3 3-3 status register 1: sr1 ................................ ................................ ........................ 3-4 4-1 registers ................................ ................................ ................................ ............ 4-1 6-1 exceptions ................................ ................................ ................................ ......... 6-1 7-1 coprocessor instructions ................................ ................................ ...................... 7-2 8-1 instruction notation conventions ................................ ................................ ........... 8-1 8-2 overall instruction set map ................................ ................................ ................... 8-2 8-3 instruction encoding ................................ ................................ ............................ 8-4 8-4 index code information ("idx") ................................ ................................ ............... 8-7 8-5 index modification code information ("mod") ................................ ........................... 8-7 8-6 condition code information ("cc") ................................ ................................ .......... 8-7 8-7 "aluop1" code information ................................ ................................ .................. 8-8 8-8 "aluop2" code information ................................ ................................ .................. 8-8 8-9 "modop1" code information ................................ ................................ ................. 8-8 9-1 pll register description ................................ ................................ ...................... 9-2 9-2 system control circuit register description ................................ ........................... 9-4 11-1 port data register summary ................................ ................................ ................ 11-1 13-1 watch timer control register (wtcon): 8-bit r/w ................................ ................ 13-1 17-1 master transmitter with data rate of 2.5 mhz (10%) (unit: ns) ................................ 17-5 17-2 slave receiver with data rate of 2.5 mhz (10%) (unit: ns) ................................ ...... 17-5 17-3 function register description ................................ ................................ ............... 17-6 xviii S3FB42F microcontroller list of tables (continued) table title page number number 18-1 control register description ................................ ................................ ................. 18-3 23-1 general usb features ................................ ................................ ......................... 23-1 23-2 general function features ................................ ................................ ................... 23-1 23-3 usb function registers description ................................ ................................ ..... 23-5 23-4 interrupt pending register ................................ ................................ .................... 23-10 25-1 mac2424 pin description ................................ ................................ .................... 25-5 25-2 exponent evaluation and normalization example ................................ ................... 25-35 26-1 absolute maximum ratings ................................ ................................ .................. 26-1 26-2 d.c. electrical characteristics ................................ ................................ .............. 26-1 26-3 a.c. electrical characteristics ................................ ................................ .............. 26-3 26-4 input/output capacitance ................................ ................................ ..................... 26-3 26-5 a/d converter electrical characteristics ................................ ................................ 26-4 26-6 i 2 s master transmitter with data rate of 2.5 mhz (10%) (unit: ns) .......................... 26-4 26-7 i 2 s slave receiver with data rate of 2.5 mhz (10%) (unit: ns) ................................ 26-5 26-8 flash memory d.c. electrical characteristics ................................ ........................ 26-5 26-9 flash memory a.c. electrical characteristics ................................ ........................ 26-5 26-10 data retention supply voltage in stop mode ................................ ......................... 26-6 26-11 synchronous sio electrical characteristics ................................ ........................... 26-8 26-12 main oscillator frequency (fosc1) ................................ ................................ ......... 26-9 26-13 sub oscillator frequency (fosc2) ................................ ................................ .......... 26-10 S3FB42F microcontroller xix list of programming tips description page number chapter 6 : exceptions interrupt programming tip 1 ................................ ................................ ................................ .................. 6-7 interrupt programming tip 2 ................................ ................................ ................................ .................. 6-8 S3FB42F microcontroller xxi list of instruction descriptions instruction full instruction name page mnemonic number adc add with carry ................................ ................................ ................................ .... 8-31 add add ................................ ................................ ................................ .................... 8-32 and bit-wise and ................................ ................................ ................................ ...... 8-33 and sr0 bit-wise and with sr0call procedure ................................ ................................ ... 8-34 bank bank gpr selection ................................ ................................ ............................ 8-35 bitc bit complement ................................ ................................ ................................ .. 8-36 bitr bit reset ................................ ................................ ................................ ............ 8-37 bits bit set ................................ ................................ ................................ ................ 8-38 bitt bit test ................................ ................................ ................................ .............. 8-39 bmc/bms tf bit clear/set ................................ ................................ ................................ .... 8-40 call conditional subroutine call (pseudo instruction) ................................ ..................... 8-41 calls call subroutine ................................ ................................ ................................ .... 8-42 cld load into coprocessor ................................ ................................ ......................... 8-43 cld load from coprocessor ................................ ................................ ........................ 8-44 com 1's or bit-wise complement ................................ ................................ .................. 8-45 com2 2's complement ................................ ................................ ................................ .. 8-46 comc bit-wise complement with carry ................................ ................................ ........... 8-47 cop coprocessor ................................ ................................ ................................ ....... 8-48 cp compare ................................ ................................ ................................ ............. 8-49 cpc compare with carry ................................ ................................ ............................. 8-50 dec decrement ................................ ................................ ................................ .......... 8-51 decc decrement with carry ................................ ................................ .......................... 8-52 di disable interrupt (pseudo instruction) ................................ ................................ .... 8-53 ei enable interrupt (pseudo instruction) ................................ ................................ .... 8-54 idle idle operation (pseudo instruction) ................................ ................................ ....... 8-55 inc increment ................................ ................................ ................................ ........... 8-56 incc increment with carry ................................ ................................ ............................ 8-57 iret return from interrupt handling ................................ ................................ ............... 8-58 jnzd jump not zero with delay slot ................................ ................................ .............. 8-59 jp conditional jump (pseudo instruction) ................................ ................................ .. 8-60 jr conditional jump relative ................................ ................................ ..................... 8-61 lcall conditional subroutine call ................................ ................................ ................... 8-62 ld adr:8 load into memory ................................ ................................ ................................ 8-63 xxii S3FB42F microcontroller list of instruction descriptions (continued) instruction full instruction name page mnemonic number ld @ idm load into memory indexed ................................ ................................ ................... 8-64 ld load register ................................ ................................ ................................ ...... 8-65 ld load gpr:bankd, gpr:banks ................................ ................................ .............. 8-66 ld load gpr, tbh/tbl ................................ ................................ ............................ 8-67 ld load tbh/tbl, gpr ................................ ................................ ............................ 8-68 ld spr load spr ................................ ................................ ................................ ........... 8-69 ld spr0 load spr0 immediate ................................ ................................ ......................... 8-70 ldc load code ................................ ................................ ................................ .......... 8-71 ljp conditional jump ................................ ................................ ................................ . 8-72 llnk linked subroutine call conditional ................................ ................................ ........ 8-73 lnk linked subroutine call (pseudo instruction) ................................ .......................... 8-74 lnks linked subroutine call ................................ ................................ ......................... 8-75 lret return from linked subroutine call ................................ ................................ ....... 8-76 nop no operation ................................ ................................ ................................ ....... 8-77 or bit-wise or ................................ ................................ ................................ ........ 8-78 or sr0 bit-wise or with sr0 ................................ ................................ .......................... 8-79 pop pop ................................ ................................ ................................ ................... 8-80 pop pop to register ................................ ................................ ................................ .. 8-81 push push register ................................ ................................ ................................ ..... 8-82 ret return from subroutine ................................ ................................ ........................ 8-83 rl rotate left ................................ ................................ ................................ .......... 8-84 rlc rotate left with carry ................................ ................................ .......................... 8-85 rr rotate right ................................ ................................ ................................ ........ 8-86 rrc rotate right with carry ................................ ................................ ........................ 8-87 sbc subtract with carry ................................ ................................ .............................. 8-88 sl shif t left ................................ ................................ ................................ ............. 8-89 sla shift left arithmetic ................................ ................................ ............................. 8-90 sr shift right ................................ ................................ ................................ ........... 8-91 sra shift right arithmetic ................................ ................................ ........................... 8-92 stop stop operation (pseudo instruction) ................................ ................................ ..... 8-93 sub subtract ................................ ................................ ................................ ............. 8-94 swap swap ................................ ................................ ................................ .................. 8-95 sys system ................................ ................................ ................................ .............. 8-96 tm test multiple bits ................................ ................................ ................................ 8-97 xor exclusive or ................................ ................................ ................................ ...... 8-98 S3FB42F product ove rview 1- 1 1 product overview calmrisc overview the S3FB42F single-chip cmos microcontroller is designed for high performance using samsung's newest 8-bit cpu core, calmrisc. calmrisc is an 8-bit low power risc microcontroller. its basic architecture follows harvard style, that is, it has separate program memory and data memory. both instruction and data can be fetched simultaneously without causing a stall, using separate paths for memory access. represented below is the top block diagram of the calmrisc microcontroller. features cpu 8-bit calmrisc core dsp architecture (24 x 24-bit mac) memory code memory: 144k byte (72k word) half flash type memory data memory: 48k byte sram + 69k byte flash type memory stack size: maximu m 16 (word)-level. 65 i/o pins i/o: 59 pins input only: 6 pins 8-bit serial i/o interface 8-bit transmit/receive or 8-bit receive mode. lsb first or msb first transmission selectable. internal and external clock source. 8-bit basic timer & watchdog timer programmable basic timer 8-bit counter + wdt 3-bit counter 8 kinds of clock source overflow signal of 8-bit counter makes a basic timer interrupt. and control the oscillation warm-up time overflow signal of 3-bit counter makes a system reset. one 16-bit timer/counter programmable interval timer two 8-bit timer counter mode and one 16-bit timer counter mode, selectable by s/w one real time clock real time clock generation (0.5 or 1 second) buzzer signal generation (1, 2, 4 or 8 khz) rom code options basic timer counter clock source selecting reset value product overview s3 fb42f 1- 2 features ( continued) i 2 c, i 2 s interface one- ch multi-master i 2 c controller two- ch sony/phillips i 2 s controller uart interface one full-duplex uart controller usb specification compliance (ver1.0, ver1.1) built in full speed transceiver support 1 device address and 4 endpoints. 1 control endpoint and 3 data endpoints one 16 bytes endpoint, one 32 bytes end point, and two 64 bytes end points. each data endpoint can be configurable as interrupt, bulk and isochronous. parallel port interface controller interrupt-based operation support ieee standard 1284 communication mode (compatibility, nibble, byte and ecp mode). automatic handshaking mode for any forward or reverse protocol with software enable/disable ssfdc (smart media tm card) interface control signals are operated by cpu instruction random number generator two ring oscillators linear feedback shifter register lfsr8/lfsr16 external interrupt 8 source (edge triggered 6 + level triggered 2) adc six 8-bit resolution channels and normal input two power-down modes idle mode: only cpu clock stop. stop mode: system clock and cpu clock stop. oscillation sources clock synthesizer (phase-locked loo p circuit) based on 32.768 khz cpu clock divider circuit (div by 1, 2, 4, 8, 16, 32, 64, 128) instruction execution times 33.3ns at fxx = 30 mhz when 1 cycle instruction 66.6ns at fxx = 30 mhz when 2 cycle instruction operating temperature - 40 c to 85 c operating voltage range 3.0 v to 3.6 v at 30 mhz package types 100-qfp, 100-tqfp S3FB42F product ove rview 1- 3 bbus[7:0] 20 program memory address generation unit pc[19:0] hardware stack hs[0] hs[15] 8 8 r0 r3 r1 r2 alu abus[7:0] alul alur pa[19:0] pd[15:0] idl0 idl1 sr0 sr1 ilh ilx ill spr idh do[7:0] di[7:0] gpr data memory address generation unit da[15:0] 20 flag rbus tbh tbl figure 1-1. top block diagram product overview s3 fb42f 1- 4 the calmrisc building blocks consist of: ? an 8-bit alu ? 16 general pur pose registers (gpr) ? 11 special purpose registers (spr) ? 16-level hardware stack ? program memory address generation unit ? data memory address generation unit 16 gpr's are grouped into four banks (bank0 to bank3) and each bank has four 8-bit registers (r0, r1, r2, and r3). spr's, designed for special purposes, include status registers, link registers for branch-link instructions, and data memory index registers. the data memory address generation unit provides the data memory address (denoted as da[15:0] in the top block diagram) for a data memory access instruction. data memory contents are accessed through di[7:0] for read operations and do[7:0] for write operations. the program memory address generation unit contains a program counter, pc[19:0], and supplies the program memory address through pa[19:0] and fetches the corresponding instruction through pd[15:0] as the result of the program memory access. calmrisc has a 16-level hardware stack for low power stack operations as well as a temporary storage area. calmrisc has a 3-stage pipeline as discribed below: instruction fetch (if) instruction decode/ data memory access (id/mem) execution/writeback (exe/wb) figure 1-2. calmrisc pipeline diagram as can be seen in the pipeline scheme, calmrisc adopts a register-memory instruction set. in other words, data memory where r is a gpr, can be one operand of an alu instruction as shown below: the first stage (or cycle) is instruction fetch stage (if for short), where the instruction pointed to by the program counter, pc[19:0] , is read into the instruction register (ir for short). the second stage is instruction decode and data memory access stage (id/mem for short), where the fetched instruction (stored in ir) is decoded and data memory access is performed, if necessary. the final stage is execute and write-back stage (exe/wb), where the required alu operation is executed and the result is written back into the destination registers. since calmrisc instructions are pipelined, the next instruction fetch is not postponed until the current instruction is completely finished, but is performed immediately after the current instruction fetch is done. the pipeline stream of instructions is illustrated in the following diagram. S3FB42F product ove rview 1- 5 exe/wb if if if if if if if id/mem id/mem id/mem id/mem id/mem id/mem exe/wb exe/wb exe/wb exe/wb exe/wb i 1 i 2 i 3 i 4 i 6 i 5 figure 1-3. calmrisc pipeline stream diagram most calmrisc instructions are 1-word instructions, while same branch instructions such as "lcall" and "ljt" instructions are 2-word instructions. in figure 1-3, the instruction, i 4 , is a long branch instruction and it takes two clock cycles to fetch the instruction. as indicated in the pipeline stream, the number of clocks per instruction (cpi) is 1 except for long branches, which take 2 clock cycles per instruction. product overview s3 fb42f 1- 6 i/o0-i/o7 p9.0-p9.5 p8.0-p8.3 p7.0-p7.7 p6.0-p6.7 p5.0-p5.5 calmrisc cpu flash memory 213-kbytes sram 48-kbytes dsp core mac 2424 osc & pll control rtc basic timer wdt ssfdc port 9 port 8 port 7 port 6 sio/uart iic/iis so, tx, sod sck, scl, soc si, rx, sda, soi usb dp, dm 8-bit a/d c avss adc0-adc5 avref ext interrupt int0-int5 int8-int9 ppic nstrobe/ninit busy/perror pd0-pd7 timer 0/1 tack/tbck taout port 5 p4.0-p4.3 port 4 p3.0-p3.7 port 3 p2.0-p2.7 port 2 p1.0-p1.4 port 1 p0.0-p0.7 port 0 random number gen. buz x in x out cp, cz fvco figure 1-4. block diagram S3FB42F product ove rview 1- 7 v dd v ss nwe/p6.7 i/o0/p7.0 i/o1/p7.1 i/o2/p7.2 i/o3/p7.3 v dd v ss i/o4/p7.4 i/o5/p7.5 i/o6/p7.6 sdat /i/o7/p7.7 sclk /nslctin/p8.0 v dd /v dd v ss /v ss x i n x out v pp /test xt in xt o ut reset reset /reset v dd v ss n.c f vco /nstrobe/p8.1 nautofd/p8.2 cp cz v ss p6.6/nre p6.5/nwp p6.4/r/nb p6.3/ale p6.2/cle p6.1/nce1 p6.0/nce0 v dd av ss av ref p5.5/adc5/int5 p5.4/adc4/int4 p5.3/adc3/int3 p5.2/adc2/int2 p5.1/adc1/int1 p5.0/adc0/int0 p4.2/nce2 p4.1/int8 p4.0/int9 p9.6/mclk ninit/p8.3 ppd0/p0.0 ppd1/p0.1 ppd2/p0.2 ppd3/p0.3 ppd4/p0.4 ppd5/p0.5 ppd6/p0.6 ppd7/p0.7 v dd nack/p1.0 busy/p1.1 select/p1.2 perror/p1.3 nfault/p1.4 taclk/p2.0 tbclk/p2.1 taout/p2.2 buz/p2.3 rx/p2.4 v ss v ss v dd p9.5/sd1 p9.4/sclk1 p9.3/ws1 v ss v dd p9.2/sd0 p9.1/sclk0 p9.0/ws0 p3.7 p3.6 p3.5 p3.4/sda v ss v dd p3.3/scl p3.2/sck dm v ss v dd dp p3.1/so p3.0/si p2.7 p2.6 p2.5/tx v ss v dd S3FB42F (100-qfp) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 note: n.c means no - connection. figure 1-5. 100-qfp pin assignment product overview s3 fb42f 1- 8 v ss v dd p6.6/nre p6.5/nwp p6.4/r/nb p6.3/ale p6.2/cle p6.1/nce1 p6.0/nce0 v dd av ss av ref p5.5/adc5/int5 p5.4/adc4/int4 p5.3/adc3/int3 p5.2/adc2/int2 p5.1/adc1/int1 p5.0/adc0/int0 p4.2/nce2 p4.1/int8 p4.0/int9 p9.6/mclk v ss v ss v dd cp cz v ss ninit/p8.3 ppd0/p0.0 ppd1/p0.1 ppd2/p0.2 ppd3/p0.3 ppd4/p0.4 ppd5/p0.5 ppd6/p0.6 ppd7/p0.7 v dd nack/p1.0 busy/p1.1 select/p1.2 perror/p1.3 nfault/p1.4 tack/p2.0 tbck/p2.1 taout/p2.2 buz/p2.3 rx/p2.4 v dd v ss p9.5/sd1 p9.4/sclk1 p9.3/ws1 v ss v dd p9.2/sd0 p9.1/sclk0 p9.0/ws0 p3.7 p3.6 p3.5 p3.4/sda v ss v dd p3.3/scl p3.2/sck dm v ss v dd dp p3.1/so p3.0/si p2.7 p2.6 p2.5/tx nwe/p6.7 i/o0/p7.0 i/o1/p7.1 i/o2/p7.2 i/o3/p7.3 v dd v ss i/o4/p7.4 i/o5/p7.5 i/o6/p7.6 sdat /i/o7/p7.7 sclk /nslctin/p8.0 v dd /v dd v ss /v ss x in x out v pp /test xt i n xt o ut reset v dd v ss n.c f vco /nstrobe/p8.1 nautofd/p8.2 S3FB42F (100-tqfp-1414c) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 note: n.c means no - connection figure 1-6. 100-tqfp pin assignment S3FB42F product ove rview 1- 9 pin description table 1-1. S3FB42F pin descriptions (100-tqfp) pin name pin type pin description circuit type pin number share pins p0.0-p0.7 i/o i/o port with bit programmable pins; input or output mode selected by software; alternately can be used as parallel port data bus pins, ppd0-ppd7. p0.0/ppd0-p0.7/ppd7: parallel port data bus 1 30-37 (32-39) ppd0- ppd7 p1.0-p1.4 i/o i/o port with bit programmable pins; push-pull output mode is selected by software; alternately can be used as parallel port control bus pins, nack, busy, select, perror and nfault pin. p1.0/nack: not parallel port acknowledge. p1.1/busy: parallel port busy. p1.2/select: parallel port select. p1.3/perror: parallel port paper error p1.4/nfault: not parallel port fault. 1 39-43 (41-45) nack- nfault p2.0-p2.7 i/o i/o port with bit programmable pins; input and output mode are selected by software; alternately can be used as taclk, tbclk, taout, buz, rx and tx. p2.0/ taclk: timer 0 clock or capture input p2.1/tbclk: timer 1 clock input p2.2/taout: timer 2 capture input or, pwm or toggle output p2.3/buz: buzzer output p2.4/rx: receive input in uart p2.5/tx: transmit output in uart p2.6: normal input/output pin p2.7: normal input/output pin 4 44-48, 51-53 (46-50, 53-55) taclk- tx p3.0-p3.7 i/o i/o port with bit programmable pins; input or output mode selected by software; alternately can be used as si, so, sck, scl and sda. n-channel open drains are configurable. p3.0/si: serial data input pin in sio(spi) p3.1/so: serial data output pin in sio(spi) p3.2/sck: serial clock pin in sio(spi) p3.3/scl: serial clock pin in i 2 c p3.4/sda: serial data pin in i 2 c p3.5: normal input/output pin p3.6: normal input/output pin p3.7: normal input/output pin 5 54-55, 60-61, 64-67 (56-57, 62-63, 66-69) si-sda note: parentheses indicate pin number for 100-qfp package. product overview s3 fb42f 1- 10 table 1 - 1. S3FB42F pin descriptions (100-tqfp) (continued) pin name pin type pin description circuit type pin number share pins p4.0-p4.2 i/o i/o port with bit programmable pins; input and output mode are selected by software; p4.0-p4.1 can be used as inputs for external interrupts int9-int8. (with noise filter) and assigned pull-up by software; alternately p4.2 can be used as ce2 for smartmedia chip select signal. p4.0/int9: external interrupt 9 input p4.1 /int8: external interrupt 8 input p4.2/ ce2 : normal in/output pin 6, 3 80-82 (82-84) int9-int8 ce2 p5.0-p5.5 i input port with bit programmable pins; input or adc input mode selected by software; software assignable pull-up; port 5 can be used as inputs for external interrupts int0-int5 or adc block. p5.0/int0/adc0: ext interrupt 0 or adc0 input p5.1/int1/adc1: ext interrupt 1 or adc1 input p5.2/int2/adc2: ext interrupt 2 or adc2 input p5.3/int3/adc3: ext interrupt 3 or adc3 input p5.4/int4/adc4: ext interrupt 4 or adc4 input p5.5 /int5/adc5: ext interrupt 5 or adc5 input 7 83-88 (85-90) int0/adc0- int5/adc5 p6.0-p6.7 i/o i/o port with bit programmable pins; alternately port 6 can be used as ce0 , ce1 , cle, ale, we , wp, re and r/ b for smartmedia control signal. p6.0/ ce0 : chip select strobe output 0 for sm. p6.1/ ce1 : chip select strobe output 1 for sm. p6.2/cle: command latch enable output for sm. p6.3/ale: address latch enable output for sm. p6.4/r/ b : ready and busy status input for sm. p6.5/wp: write protect output for sm. p6.6/ re : read enable strobe output for sm. p6.7/ we : write enable strobe output for sm. 1, 2 92-98, 1 (94-100, 3) ce0 - we p7.0-p7.7 i/o i/o port with bit programmable pins; alternately port 7 can be used as i/o port for smartmedia control signal. p7.0/i/o0-p7.7/i/o7: i/o port for smartmedia control signal. 1 2-5, 8-11 (4-7, 10-13) i/o0-i/o7 note: parentheses indicate pin number for 100-qfp package. S3FB42F product ove rview 1- 11 table 1 - 1. S3FB42F pin descriptions (100-tqfp) (continued) pin name pin type pin description circuit type pin number share pins p8.0-p8.3 i/o i/o port with bit programmable pins; alternately can be used as parallel port control bus pins, nslctin, nstrobe, nautofd and ninit pin. p8.0/nslctin: not select information input. p8.1/nstrobe/f vco : not strobe input or f vco output p8.2/nautofd: not auto-feed input p8.3/ninit: not parallel port initialization. 4 12, 24, 25, 29 (14, 26, 27, 31) nslctin- ninit p9.0-p9.6 i/o i/o port with bit programmable pins; alternately can be used as serial data interface pins, ws0, sclk0, sd0, ws1, sclk1, sd1 and mclk. p9.0/ws0: word select pin in i 2 s0 p9.1/sclk0: bit serial clock pin in i 2 s0. p9.2/sd0: serial data pin in i 2 s0 p9.3/ws1: word select pin in i 2 s1. p9.4/sclk1: bit serial clock pin in i 2 s1. p9.5/sd1: serial data pin in i 2 s1. p9.6/mclk: master clock pin in i 2 s0. 4 68-70, 73-76, 79 (70-72, 75-77, 79) ws0- mclk dm i/o only be used usb transceive/receive port ? 59 (61) ? dp i/o only be used usb transceive/receive port ? 56 (58) ? v dd, v dd ? power supply ? 6, 13, 21, 26, 38, 49, 57, 62, 71, 76, 91, 99 (1, 8, 15, 23, 28, 40, 52, 59, 64, 73, 78, 93) ? v ss, v ss ? ground ? 7, 14, 22, 27, 28, 50, 58, 63, 72, 77, 78, 100 (2, 9, 16, 24, 29, 30, 51, 60, 65, 74, 79, 80) ? note: parentheses indicate pin number for 100-qfp package. product overview s3 fb42f 1- 12 S3FB42F product ove rview 1- 13 table 1 - 1. S3FB42F pin descriptions (100-tqfp) (continued) pin name pin type pin description circuit type pin number share pins x in, x out ? crystal, ceramic oscillator signal for pll reference frequency (for external clock input, use x in and input x in 's reverse phase to x out ) ? 15, 16 (17, 18) ? xt in, xt out ? crystal, ceramic oscillator (for external clock input, use xt in and input xt in 's reverse phase to xt out ) ? 18, 19 (20,21) ? cp, cz ? low pass filter circuit for pll ? 26, 27 (28, 29) ? test i test signal input 9 17 (19) ? reset i reset signal 8 20 (22) ? av ref , av ss ? power supply pin and ground pin for a/d converter. ? 89, 90 (91, 92) ? sdat i/o serial data in/output pin for serial program block 1 11 (13) p7.7 sclk i serial clock input pin for serial program block 1 12 (14) p8.0 v dd ? power supply pin for serial program block ? 13 (15) ? v ss ? ground pin for serial program block ? 14 (16) ? v pp ? flash cell power supply pin or mode selection pin for serial program block ? 17 (19) test reset i reset pin for serial program block 8 20 (22) reset note: parentheses indicate pin number for 100-qfp package. product overview s3 fb42f 1- 14 pin circuit diagrams v dd in/out m u x v ss select port data alternative signal output disable alternative input normal input data figure 1-7. pin circuit type 1 (port 0, p1.0-p1.4, p6.0-p6.5, and port 7) v dd in/out m u x v ss select port data alternative signal output disable alternative input normal input pull-up resistor v dd pull-up enable data figure 1-8. pin circuit type 2 (p6.6 and p6.7) S3FB42F product ove rview 1- 15 v dd in/out m u x v ss select port data alternative signal output disable alternative input normal input pull-up resistor v dd pull-up enable data figure 1-9. pin circuit type 3 (p4.2) product overview s3 fb42f 1- 16 v dd in/out m u x v ss select port data alternative signal output disable alternative input normal input data figure 1-10. pin circuit type 4 (port 2, port 8, and port 9) v dd m u x v ss select port data alternative signal output disable alternative input normal input pull-up resistor v dd pull-up enable data open-drain in/out figure 1-11. pin circuit type 5 (port 3) S3FB42F product ove rview 1- 17 v dd in/out v ss output disable input external interrupt input pull-up resistor v dd pull-up enable noise filter data figure 1-12. pin circuit type 6 (p4.0, and p4.1) normal input mode normal input interrupt input noise filter in pull-up resistor v dd pull-up resistor enable v ref a/d c logic + - figure 1-13. pin circuit type 7 (port 5) product overview s3 fb42f 1- 18 in v dd figure 1-14. pin circuit type 8 ( reset reset ) in figure 1-15. pin circuit type 9 (test) S3FB42F product ove rview 1- 19 notes S3FB42F address spa ce 2- 1 2 address space overview calmrisc has 20-bit program address lines, pa[19:0] , which supports up to 1m-word program memory. the 1m-word program memory space is divided into 256 pages and each page is 4k words long as shown in the next page. the upper 8 bits of the program counter, pc[19:12], points to a specific page and the lower 12 bits, pc[11:0], specify the offset address of the page. calmrisc also has 16-bit data memory address lines, da[15:0], which supports up to 64k-byte data memory. the 64k-byte data memory space is divided into 256 pages and each page has 256 bytes. the upper 8 bits of the data address, da[15:8], points to a specific page and the lower 8 bits, da[7:0], specify the offset address of the page. S3FB42F has 72k-word (144k-byte) flash rom type program memory, 34.5k-word (69k-byte) flash rom type data memory and 48k-byte ram type data memory. memory configuration in calmrisc side data memory: total size - 117k bytes (flash rom type, 69k bytes and sram type, 48k bytes) code memory: total size - 144k bytes (flash rom type, 144k bytes) memory configuration in mac-2424 side data memory: x-memory area - sram, 12k lwords (36k bytes) y-memory area - sram, 4k lwords (12k bytes) and flash rom, 23k lwords (69k bytes) code memory: total size - 72k words (flash rom type, 144k byte) memory type flash rom: 213k bytes sram: 48k bytes address space s3fb4 2f 2- 2 program memory (rom) 00h fffh 18 page 72k-word (144k-byte) 00h fffh 4k-word (8k-byte) 16-bit 00000h 11fffh 00020h 0001fh vector and option area flash rom memory (4k-word x 18 page = 72k-word) 72k-word code momory ~ ~ ~ ~ figure 2-1. flash memory (code memory area) from 00000h to 00004h addresses are used for the vector address of exceptions, and 0001eh, 0001fh are used for the option only. aside from these addresses others are reserved in the vector and option area. program memory area from the address 00020h to 11ffh can be used for normal programs. S3FB42F's program memory is 72k words (144k bytes). S3FB42F address spa ce 2- 3 data memory organization the total data memory bank address space is 64 k-byte, addressed by da[15:0], which is also divided into 256 pages, each page consists of 256 bytes as shown below. S3FB42F has 2 data bank memory. 64k-byte ffh 00h 8-bit bank 0 00h ffh 256 pages ffh 00h 128 pages (x-memory) 128 pages (y-memory) 8-bit bank 1 256-byte ffh 256-byte figure 2-2. data memory map address space s3fb4 2f 2- 4 sram sram blank 8000h 7fffh 4000h 3fffh 0100h 12k-byte page 144 page 128 page 63 page 16 bank 1 sram blank 9fffh 8000h 7fffh 2000h 1fffh 0100h 8k-byte 24k-byte 7.75k-byte page 128 page 127 page 1 bank 0 y-memory x-memory sram page 0 00ffh page address i/o area 4k-byte blank 8fffh 1000h page 31 page 32 ffffh c000h b800h d000h 16kb 18kb 12kb 2 1 yrom bank 0 flash rom ffffh e000h dc00h e800h 8kb 9kb 6kb 2 1 yrom bank 0 flash rom 0000h mac access unit, lword = 3-byte long. (1-byte to bank 1, and 2-byte of bank 0) bank 0 xm = 2000h + mac offset x 2 ym = 8000h + mac offset x 2 bank 1 xm = 1000h + mac offset ym = 8000h + mac offset figure 2-3. data memory map in calmrisc side S3FB42F address spa ce 2- 5 4000h 3fffh 1000h 0fffh 0000h 4k-lword 12k-lword sram y-memory x-memory sram blank 7fffh 6000h 5c00h 6800h 2 1 yrom bank 0 flash rom 6k-lw 9k-lw 8k-lw where, lword: 3-byte long. (1-byte of bank 1, and 2-byte of bank 0) xm mac offset = mac address - 1000h ym mac offset = mac address - 4000h 4fffh 4k-lword figure 2-4. data memory map in mac-2424 side address space s3fb4 2f 2- 6 sram (24kb) 9fffh 8000h 7fffh 2000h sram (8kb) y-memory x-memory bank 1 bank 0 page 0 00ffh 0000h 8000h 3fffh 1000h calmrisc memory space mac2424 memory space e000h dc00h e800h flash rom (8kb) 9kb 6kb 8fffh ffffh c000h b800h flash rom (16kb) 18kb d000h 12kb 3fffh 1000h sram (12k-lword) 5fffh 4fffh 4000h 5000h blank (4k-lword) sram (4k-lword) 7fffh 6000h 5c00h flash rom (8k-lword) 9k-lw 6800h 6k-lw sram (4kb) sram (12kb) i/o area figure 2-5. data memory map S3FB42F registers 3- 1 3 registers overview the registers of calmrisc are grouped into 2 parts: general purpose registers and special purpose registers. table 3-1. general and special purpose registers registers mnemonics description reset value general purpose registers (gpr) r0 general r egister 0 unknown r1 general r egister 1 unknown r2 general r egister 2 unknown r3 general r egister 3 unknown special purpose registers (spr) group 0 (spr0) idl0 l ower byte of i n d ex register 0 unknown idl1 l ower byte of i n d ex register 1 unknown idh h igher byte of i n d ex register unknown sr0 s tatus r egister 0 00h group 1 (spr1) ilx i nstruction pointer l ink register for e x tended byte unknown ilh i nstruction pointer l ink register for h igher byte unknown ill i nstruction pointer l ink register for l ower byte unknown sr1 s tatus r egister 1 unknown gpr ? s can be used in most instructions such as alu instructions, stack instructions, load instructions, etc (see the instruction set sections). from the programming standpoint, they have almost no restriction whatsoever. calmrisc has 4 banks of gpr ? s and each bank has 4 registers, r0, r1, r2, and r3. hence, 16 gpr ? s in total are available. the gpr bank switching can be done by setting an appropriate value in sr0[4:3] (see sr0 for details). the alu operations between gpr ? s from different banks are not allowed. spr ? s are designed for their own dedicated purposes. they have some restrictions in terms of instructions that can access them. for example, direct alu operations cannot be performed on spr ? s. however, data transfers between a gpr and an spr are allowed and stack operations with spr ? s are also possible (see the instruction sections for details). registers s3f b42f 3- 2 index registers: idh, idl0 and idl1 idh in concatenation with idl0 (or idl1) forms a 16-bit data memory address. note that calmrisc ? s data memory address space is 64k bytes (addressable by 16-bit addresses). basically, idh points to a page index and idl0 (or idl1) corresponds to an offset of the page. like gpr ? s, the index registers are 2-way banked. there are 2 banks in total, each of which has its own index registers, idh, idl0 and idl1. the banks of index registers can be switched by setting an appropriate value in sr0[2] (see sr0 for details). normally, programmers can reserve an index register pair, idh and idl0 (or idl1), for software stack operations. link registers: ilx, ilh and ill the link registers are specially designed for link-and-branch instructions (see lnk and lret instructions in the instruction sections for details). when an lnk instruction is executed, the current pc[19:0] is saved into ilx, ilh and ill registers, i.e., pc[19:16] into ilx[3:0], pc[15:8] into ilh [7:0], and pc[7:0] into ill[7:0], respectively. when an lret instruction is executed, the return pc value is recovered from ilx, ilh, and ill, i.e., ilx[3:0] into pc[19:16], ilh[7:0] into pc[15:8] and ill[7:0] into pc[7:0], respectively. these registers are used to access program memory by ldc/ldc+ instructions. when an ldc or ldc+ instruction is executed, the (code) data residing at the program address specified by ilx:ilh:ill will be read into tbh:tbl. ldc+ also increments ill after accessing the program memory. there is a special core input pin signal, np64kw , which is reserved for indicating that the program memory address space is only 64 k word. by grounding the signal pin to zero, the upper 4 bits of pc, pc[19:16], is deactivated and therefore the upper 4 bits , pa[19:16], of the program memory address signals from calmrisc core are also deactivated. by doing so, power consumption due to manipulating the upper 4 bits of pc can be totally eliminated (see the core pin description section for details). from the programmer ? s standpoint, when np64kw is tied to the ground level, then pc[19:16] is not saved into ilx for lnk instructions and ilx is not read back into pc[19:16] for lret instructions. therefore, ilx is totally unused in lnk and lret instructions when np64kw = 0. S3FB42F registers 3- 3 status register 0: sr0 sr0 is mainly reserved for system control functions and each bit of sr0 has its own dedicated function. table 3-2. status register 0: sr0 flag name bit description reset value eid 0 data memory page selection in direct addressing 1 ie 1 global interrupt enable x idb 2 index register banking selection 0 grb[1:0] 4,3 gpr bank selection 00 exe 5 stack overflow/underflow exception enable x ie0 6 interrupt 0 enable x ie1 7 interrupt 1 enable x sr0[0] (or eid) selects which page index is used in direct addressing. if eid = 0, then page 0 (page index = 0) is used. otherwise ( eid = 1), idh of the current index register bank is used for page index. sr0[1] (or ie) is the global interrupt enable flag. as explained in the interrupt/exception section, calmrisc has 3 interrupt sources (non- maskable interrupt, interrupt 0, and interrupt 1) and 1 stack exception. both interrupt 0 and interrupt 1 are masked by setting sr0[1] to 0 (i.e., ie = 0). when an interrupt is serviced, the global interrupt enable flag ie is automatically cleared. the execution of an iret instruction (return from an interrupt service routine) automatically sets ie = 1. sr0[2] (or idb) and sr0[4:3] (or grb[1:0]) selects an appropriate bank for index registers and gpr?s, respectively as shown below: r3 r0 r2 r1 r3 r0 r2 r1 r3 r0 r2 r1 r3 r0 r2 r1 idh idl0 idl1 idh idl0 idl1 bank 0 bank 1 bank 2 bank 3 11 10 01 00 grb [1:0] 0 1 idb figure 3-1. bank selection by setting of grb bits and idb bit sr0[5] (or exe) enables the stack exception, that is, the stack overflow/underflow exception. if exe = 0, the stack exception is disabled. the stack exception can be used for program debugging in the software development stage. sr0[6] (or ie0) and sr0[7] (or ie1) are enabled, by setting them to 1. even though ie0 or ie1 are enabled, the interrupts are ignored (not serviced) if the global interrupt enable flag ie is set to 0. registers s3f b42f 3- 4 status register 1: sr1 sr1 is the register for status flags such as alu execution flag and stack full flag. table 3-3. status register 1: sr1 flag name bit description c 0 carry flag v 1 overflow flag z 2 zero flag n 3 negative flag sf 4 stack full flag ? 5,6,7 reserved sr1[0] (or c) is the carry flag of alu executions. sr1[1] (or v) is the overflow flag of alu executions. it is set to 1 if and only if the carry-in into the 8-th bit position of addition/subtraction differs from the carry-out from the 8-th bit position. sr1[2] (or z) is the zero flag, which is set to 1 if and only if the alu result is zero. sr1[3] (or n) is the negative flag. basically, the most significant bit (msb) of alu results becomes n flag. note a load instruction into a gpr is considered an alu instruction. however, if an alu instruction touches the overflow flag (v) like add, sub, cp, etc , n flag is updated as exclusive-or of v and the msb of the alu result. this implies that even if an alu operation results in overflow, n flag is still valid. sr1[4] (or sf) is the stack overflow flag. it is set when the hardware stack is overflowed or underflowed. programmers can check if the hardware stack has any abnormalities by the stack exception or testing if sf is set (see the hardware stack section for great details). note: when an interrupt occur sr0 and sr1 are not saved by hardware, so the sr1 register values must be saved by software. S3FB42F memory map 4- 1 4 memory map overview to support the control of peripheral hardware, the address for peripheral control registers are memory-mapped to page 0 of the ram. memory mapping lets you use a mnemonic as the operand of an instruction in place of the specific memory location. in this section, detailed descriptions of the S3FB42F control registers are presented in an easy-to-read format. you can use this section as a quick-reference source when writing application programs. this memory area can be accessed with the whole method of data memory access. ? if sr0 bit 0 is "0" then the accessed register area is always page 0. ? if sr0 bit 0 is "1" then the accessed register page is controlled by the proper idh register's value. so if you want to access the memory map area, clear the sr0.0 and use the direct addressing mode. this method is used for most cases. this control register is divided into five areas. here, the system control register area is same in every device. ffh control register system control register area port data register area peripheral control register (1 x 16 or 2 x 8) reserved area (1 x 16 or 2 x 8) specially in S3FB42F the area from 60h-7fh can be used for external device. so if you want to use some peripheral externally, then you can control that by means of this special area. peripheral control register (4 x 8) port control register area (4 x 8) 80h 7fh 70h 6fh 40h 3fh 20h 1fh 10h 0fh 00h standard exhortative area standard area ~ ~ ~ ~ figure 4-1. memory map area memory map S3FB42F 4- 2 table 4-1. registers register name mnemonic decimal hex reset r/w location 1ah-1fh are not mapped port 9 data register p9 25 19h 00h r/w port 8 data register p8 24 18h 00h r/w port 7 data register p7 23 17h 00h r/w port 6 data register p6 22 16h 00h r/w port 5 data register p5 21 15h 00h r port 4 data register p4 20 14h 00h r/w port 3 data register p3 19 13h 00h r/w port 2 data register p2 18 12h 00h r/w port 1 data register p1 17 11h 00h r/w port 0 data register p0 16 10h 00h r/w watchdog timer control register wdtcon 15 0fh 00h r/w watchdog timer enable register wdten 14 0eh 00h r/w basic timer counter btcnt 13 0dh 00h r basic timer control register btcon 12 0ch 00h r/w interrupt id register 1 iir1 11 0bh ? r/w interrupt priority register 1 ipr1 10 0ah 00h r/w interrupt mask register 1 imr1 9 09h 00h r/w interrupt request register 1 irq1 8 08h ? r/w interrupt id register 0 iir0 7 07h ? r/w interrupt priority register 0 ipr0 6 06h 00h r/w interrupt mask register 0 imr0 5 05h 00h r/w interrupt request register 0 irq0 4 04h - r/w oscillator control register osccon 3 03h 00h r/w power control register (stop or idle mode) pcon 2 02h 04h r/w locations 00h-01h are not mapped notes: 1. '?' means underlined. 2. if you want to clear the bit of irqx, then write the number which you want to clear to iirx. for example, when clear irq0.4 then ld r0, #04h and ld iir0, r0. S3FB42F memory map 4- 3 table 4-1. registers (continued) register name mnemonic decimal hex reset r/w port 0 control register p0con 32 20h 00h r/w port 1 control register p1con 33 21h 00h r/w port 2 control register low p2conl 34 22h 00h r/w port 2 control register high p2conh 35 23h 30h r/w port 3 control register low p3conl 36 24h 00h r/w port 3 control register high p3conh 37 25h 00h r/w port 3 pull-up resistor p3pur 38 26h 00h r/w location 27h is not mapped port 5 control register p5con 40 28h 00h r/w port 5 pull-up resistor p5pur 41 29h 00h r/w port 5 int. control register p5intcon 42 2ah 00h r/w port 5 int. mode register low p5intmodl 43 2bh 00h r/w port 5 int. mode register high p5intmodh 44 2ch 00h r/w external int. pending register eintpnd 45 2dh 00h r/w locations 2e-2fh are not mapped port 4 control register p4con 48 30h 00h r/w port 4 int. control register p4intcon 49 31h 00h r/w port 4 int. mode register p4intmod 50 32h 00h r/w location 33h is not mapped port 6 control register p6con 52 34h 00h r/w port 7 control register p7con 53 35h 00h r/w port 8 control register p8con 54 36h 00h r/w port 9 control register p9con 55 37h 00h r/w locations 38h-3fh are not mapped timer a control register tacon 64 40h 00h r/w timer a data register tadata 65 41h 00h r/w timer a counter tacnt 66 42h ? r location 43h is not mapped timer b control register tbcon 68 44h 00h r/w timer b data register tbdata 69 45h 00h r/w timer b counter tbcnt 70 46h ? r locations 47h-4bh are not mapped watch timer control register wtcon 76 4ch 00h r/w locations 4dh-4fh are not mapped memory map S3FB42F 4- 4 table 4-1. registers (continued) register name mnemonic decimal hex reset r/w serial i/o control register siocon 80 50h 00h r/w serial i/o pre-scale register siops 81 51h 00h r/w serial i/o data register siodata 82 52h 00h r/w location 53h is not mapped a/d c control register adcon 84 54h 00h r/w a/d conversion result data register addata 85 55h ? r locations 56h-57h are not mapped iis control register 0 iiscon0 88 58h 00h r/w iis mode register 0 iismode0 89 59h 00h r/w iis buffer pointer register 0 iisptr0 90 5ah 00h r/w location 5bh is not mapped iis control register 1 iiscon1 92 5ch 00h r/w iis mode register 1 iismode1 93 5dh 00h r/w iis buffer pointer register 1 iisptr1 94 5eh 00h r/w location 5fh is not mapped parallel port data register ppdata 96 60h 00h r/w parallel port command data register ppcdata 97 61h 00h r/w parallel port status control register ppscon 98 62h 08h r/w parallel port status register ppstat 99 63h 3fh r/w parallel port control register low ppconl 100 64h 00h r/w parallel port control register high ppconh 101 65h 00h r/w parallel port int. control register low ppintconl 102 66h 00h r/w parallel port int. control register high ppintconh 103 67h 00h r/w parallel port int. pending register low ppintpndl 104 68h 00h r/w parallel port int. pending register high ppintpndh 105 69h 00h r/w parallel port ack. width data register ppackd 106 6ah xxh r/w locations 6bh-6fh are not mapped smartmedia control register smcon 112 70h 00h r/w ecc counter eccnt 113 71h 00h r/w ecc data register low eccl 114 72h 00h r/w ecc data register high ecch 115 73h 00h r/w ecc data register extension eccx 116 74h 00h r/w ecc result register low eccrstl 117 75h 00h r/w S3FB42F memory map 4- 5 table 4-1. registers (continued) register name mnemonic decimal hex reset r/w ecc result register high eccrsth 118 76h 00h r/w ecc clear register eccclr 119 77h ? w flash memory control register fmcon 120 78h 00h r/w location 79h is not mapped flash user programming serial clock register fsclk 122 7ah 00h r/w flash user programming serial data register fsdat 123 7bh 00h r/w locations 7ch-7fh are not mapped function address register funaddr 128 80h 00h r power management register pwrman 129 81h 00h r frame number lo register framelo 130 82h 00h r frame number hi register framehi 131 83h 00h r interrupt pending register intreg 132 84h 00h r/w interrupt enable register intena 133 85h 00h r/w endpoint index register epindex 134 86h 00h r/w locations 87h-88h are not mapped endpoint direction register epdir 137 89h 00h w in control status register incsr 138 8ah 00h r/w out control status register outcsr 139 8bh 00h r/w in max packet register inmaxp 140 8ch 00h r/w out max packet register outmaxp 141 8dh 00h r/w write counter lo register wrtcntlo 142 8eh 00h r/w write counter hi register wrtcnthi 143 8fh 00h r/w endpoint 0 fifo register ep0fifo 144 90h 00h r/w endpoint 1 fifo register ep1fifo 145 91h 00h r/w endpoint 2 fifo register ep2fifo 146 92h 00h r/w endpoint 3 fifo register ep3fifo 147 93h 00h r/w memory map S3FB42F 4- 6 table 4-1. registers (continued) register name mnemonic decimal hex reset r/w control register for random number generator rancon 168 a8h ? r/w 8-bit linear feedback shift register lfsr8 169 a9h ? r/w 16-bit linear feedback shift register lower lfsr16l 170 aah ? r/w 16-bit linear feedback shift register higher lfsr16h 171 abh ? r/w pll data register lower plldatal 172 ach ? r/w pll data register higher plldatah 173 adh ? r/w pll control register pllcon 174 aeh 0 r/w location afh is not mapped uart line control register lcon 176 b0h 00h r/w uart control register ucon 177 b1h 00h r/w uart status register ussr 178 b2h c0h r uart transmit buffer register tbr 179 b3h ? w uart receive buffer register rbr 180 b4h ? r uart band rate divisor register ubrdr 181 b5h 00h r/w uart interrupt pending register upend 182 b6h 00 r/w location bfh is not mapped iic control register iiccon 184 b8h 00h r/w iic status register iicsr 185 b9h 00h r/w iic data register iicdata 186 bah ? r/w iic address register iicaddr 187 bbh ? r/w iic pre- scaler register iicps 188 bch ffh r/w iic pre- scaler count register for test iiccnt 189 bdh ? r locations beh-bfh is not mapped 64-byte iis i/o buffer buf64 c0h ffh ? r/w S3FB42F hardware st ack 5- 1 5 hardware stack overview the hardware stack in calmrisc has two usages: ? to save and restore the return pc[19:0] on lcall, calls, ret, and iret instructions. ? temporary storage space for registers on push and pop instructions. when pc[19:0] is saved into or restored from the hardware stack, the access should be 20 bits wide. on the other hand, when a register is pushed into or popped from the hardware stack, the access should be 8 bits wide. hence, to maximize the efficiency of the stack usage, the hardware stack is divided into 3 parts: the extended stack bank (xstack, 4-bits wide), the odd bank (8-bits wide), and the even bank (8-bits wide). 3 0 7 0 7 0 level 0 level 1 level 2 level 14 level 15 xstack odd bank even bank hardware stack 0 1 5 stack pointer sptr [5:0] odd or even bank selector stack level pointer figure 5-1. hardware stack hardware stack s3fb 42f 5- 2 the top of the stack (tos) is pointed to by a stack pointer, called sptr[5:0] . the upper 5 bits of the stack pointer, sptr[5:1], points to the stack level into which either pc[19:0] or a register is saved. for example, if sptr[5:1] is 5h or tos is 5, then level 5 of xstack is empty and either level 5 of the odd bank or level 5 of the even bank is empty. in fact, sptr[0], the stack bank selection bit, indicates which bank(s) is empty. if sptr[0] = 0, both level 5 of the even and the odd banks are empty. on the other hand, if sptr[0] = 1, level 5 of the odd bank is empty, but level 5 of the even bank is occupied. this situation is well illustrated in the figure below. level 0 level 1 level 2 level 15 xstack odd bank even bank 0 1 5 sptr [5:0] bank selector stack level pointer level 3 level 4 level 5 0 0 1 1 0 0 level 0 level 1 level 2 level 15 xstack odd bank even bank 0 1 5 sptr [5:0] bank selector stack level pointer level 3 level 4 level 5 0 0 1 1 1 0 figure 5-2. even and odd bank selection example as can be seen in the above example, sptr[5:1] is used as the hardware stack pointer when pc[19:0] is pushed or popped and sptr[5:0] as the hardware stack pointer when a register is pushed or popped. note that xstack is used only for storing and retrieving pc[19:16]. let us consider the cases where pc[19:0] is pushed into the hardware stack (by executing lcall/calls instructions or by interrupts/exceptions being served) or is retrieved from the hardware stack (by executing ret/iret instructions). regardless of the stack bank selection bit ( sptr[0]), tos of the even bank and the odd bank store or return pc[7:0] or pc[15:8], respectively. this is illustrated in the following figures. S3FB42F hardware st ack 5- 3 level 0 level 15 xstack odd bank even bank 1 5 sptr [5:0] bank selector level 5 0 0 1 1 0 0 level 6 0 level 0 level 15 xstack odd bank even bank 1 5 sptr [5:0] bank selector stack level pointer level 5 0 1 1 0 0 0 level 6 0 pc[7:0] stack level pointer level 0 level 15 xstack odd bank even bank 1 5 sptr [5:0] bank selector level 5 1 0 1 1 0 0 level 6 0 level 0 level 15 xstack odd bank even bank 1 5 sptr [5:0] bank selector level 5 1 1 1 0 0 0 level 6 0 by executing ret, iret by executing call, calls or interrupts/exceptions stack level pointer stack level pointer pc[19:16] pc[15:8] pc[15:8] pc[19:16] pc[7:0] by executing ret, iret by executing call, calls or interrupts/exceptions figure 5-3. stack operation with pc [19:0] as can be seen in the figures, when stack operations with pc[19:0] are performed, the stack level pointer sptr[5:1] ( not sptr[5:0]) is either incremented by 1 (when pc[19:0] is pushed into the stack) or decremented by 1 (when pc[19:0] is popped from the stack). the stack bank selection bit ( sptr[0]) is unchanged. if a calmrisc core input signal np64kw is 0, which signifies that only pc[15:0] is meaningful, then any access to xstack is totally deactivated from the stack operations with pc. therefore, xstack has no meaning when the input pin signal, np64kw , is tied to 0. in that case, xstack doesn ? t have to even exist. as a matter of fact, xstack is not included in calmrisc core itself and it is interfaced through some specially reserved core pin signals ( npush, nstack , xhsi[3:0] , xsho[3:0] ), if the program address space is more than 64k words (see the core pin signal section for details). with regards to stack operations with registers, a similar argument can be made. the only difference is that the data written into or read from the stack are a byte. hence, the even bank and the odd bank are accessed alternately as shown below. hardware stack s3fb 42f 5- 4 level 0 level 15 xstack odd bank even bank 1 5 sptr [5:0] bank selector level 5 0 0 1 1 0 0 level 6 0 level 0 level 15 xstack odd bank even bank 1 5 sptr [5:0] bank selector stack level pointer level 5 1 0 1 1 0 0 level 6 0 register stack level pointer level 0 level 15 xstack odd bank even bank 1 5 sptr [5:0] bank selector level 5 1 0 1 1 0 0 level 6 0 level 0 level 15 xstack odd bank even bank 1 5 sptr [5:0] bank selector level 5 0 1 1 0 0 0 level 6 0 register pop register push register stack level pointer stack level pointer pop register push register figure 5-4. stack operation with registers when the bank selection bit ( sptr[0]) is 0, then the register is pushed into the even bank and the bank selection bit is set to 1. in this case, the stack level pointer is unchanged. when the bank selection bit ( sptr[0]) is 1, then the register is pushed into the odd bank, the bank selection bit is set to 0, and the stack level pointer is incremented by 1. unlike the push operations of pc[19:0], any data are not written into xstack in the register push operations. this is illustrated in the example figures. when a register is pushed into the stack, sptr[5:0] is incremented by 1 ( not the stack level pointer sptr[5:1]). the register pop operations are the reverse processes of the register push operations. when a register is popped out of the stack, sptr[5:0] is decremented by 1 ( not the stack level pointer sptr[5:1]). hardware stack overflow/underflow happens when the msb of the stack level pointer, sptr[5], is 1. this is obvious from the fact that the hardware stack has only 16 levels and the following relationship holds for the stack level pointer in a normal case. suppose the stack level pointer sptr[5:1] = 15 (or 01111b in binary format) and the bank selection bit sptr[0] = 1. here if either pc[19:0] or a register is pushed, the stack level pointer is incremented by 1. therefore, sptr[5:1] = 16 (or 10000b in binary format) and sptr[5] = 1, which implies that the stack is overflowed. the situation is depicted in the following. S3FB42F hardware st ack 5- 5 level 0 level 15 xstack odd bank even bank push register 1 1 1 1 1 0 1 5 sptr [5:0] 0 level 1 level 14 level 0 level 15 xstack odd bank even bank 0 0 0 0 0 1 1 5 sptr [5:0] 0 level 1 level 14 level 0 level 15 1 0 0 0 0 1 1 5 sptr [5:0] 0 level 1 level 14 xstack odd bank even bank push pc [19:0] register pc[19:16] pc[15:8] pc[7:0] figure 5-5. stack overflow the first overflow happens due to a register push operation. as explained earlier, a register push operation increments sptr[5:0] (not sptr[5:1]) , which results in sptr[5] = 1, sptr[4:1] = 0 and sptr[0] = 0. as indicated by sptr[5] = 1, an overflow happens. note that this overflow doesn ? t overwrite any data in the stack. on the other hand, when pc[19:0] is pushed, sptr[5:1] is incremented by 1 instead of sptr[5:0], and as expected, an overflow results. unlike the first overflow, pc[7:0] is pushed into level 0 of the even bank and the data that has been there before the push operation is overwritten . a similar argument can be made about stack underflows. note that any stack operation, which causes the stack to overflow or underflow, doesn ? t necessarily mean that any data in the stack are lost, as is observed in the first example. in sr1, there is a status flag, sf (stack full flag), which is exactly the same as sptr[5]. in other words, the value of sptr[5] can be checked by reading sf (or sr1[4]). sf is not a sticky flag in the sense that if there was a stack overflow/underflow but any following stack access instructions clear sptr[5] to 0, then sf = 0 and programmers cannot tell whether there was a stack overflow/underflow by reading sf. for example, if a program pushes a register 64 times in a row, sptr[5:0] is exactly the same as sptr[5:0] before the push sequence. therefore, special attention should be paid. hardware stack s3fb 42f 5- 6 another mechanism to detect a stack overflow/underflow is through a stack exception. a stack exception happens only when the execution of any stack access instruction results in sf = 1 (or sptr[5] = 1). suppose a register push operation makes sf = 1 (the sf value before the push operation doesn ? t matter). then the stack exception due to the push operation is immediately generated and served if the stack exception enable flag (exe of sr0) is 1. if the stack exception enable flag is 0, then the generated interrupt is not served but pending. sometime later when the stack exception enable flag is set to 1, the pending exception request is served even if sf = 0. more details are available in the stack exception section. S3FB42F exceptions 6- 1 6 exceptions overview exceptions in calmrisc are listed in the table below. exception handling routines, residing at the given addresses in the table, are invoked when the corresponding exception occurs. the starting address of each exception routine is specified by concatenating 0h (leading 4 bits of 0) and the 16-bit data in the exception vector listed in the table. for example, the interrupt service routine for nmi starts from 0h:pm[00001h]. note that ?:? means concatenation and pm[*] stands for the 16-bit content at the address * of the program memory. aside from the exception due to reset release, the current pc is pushed in the stack on an exception. when an exception is executed due to nmi/irq[1:0]/iexp, the global interrupt enable flag, ie bit (sr0[1]), is set to 0, whereas ie is set to 1 when iret or an instruction that explicitly sets ie is executed. table 6-1. exceptions name address priority description reset 00000h 1 st exception due to reset release. nmi 00001h 2 nd exception due to nnmi signal. non- maskable. irq[0] 00002h 4 th exception due to nirq[0] signal. maskable by setting ie/ie0. irq[1] 00003h 5 th exception due to nirq[1] signal. maskable by setting ie/ie1. iexp 00004h 3 rd exception due to stack full. maskable by setting exe. ? 00005h ? reserved. ? 00006h ? reserved. ? 00007h ? reserved. note: break mode due to bkreq has a higher priority than all the exceptions above. that is, when bkreq is active, even the exception due to reset release is not executed. hardware reset when hardware reset is active (the reset input signal pin nres = 0), the control pins in the calmrisc core are initialized to be disabled, and sr0 and sptr (the hardware stack pointer) are initialized to be 0. additionally, the interrupt sensing block is cleared. when hardware reset is released ( nres = 1), the reset exception is executed by loading the jp instruction in ir (instruction register) and 0h:0000h in pc. therefore, when hardware reset is released, the ?jp {0h:pm[00000h]}? instruction is executed. when the reset exception is executed, a core output signal nexpack is generated to acknowledge the exception. exceptions S3FB42F 6- 2 nmi exception (edge sensitive) on the falling edge of a core input signal nnmi , the nmi exception is executed by loading the call instruction in ir and 0h:0001h in pc. therefore, when nmi exception is activated, the "call {0h:pm[00001h]}" instruction is executed. when the nmi exception is executed, the ie bit (sr0[1]) becomes 0 and a core output signal nexpack is generated to acknowledge the exception. irq[0] exception (level-sensitive) when a core input signal nirq[0] is low, sr0[6] (ie0) is high, and sr0[1] ( ie) is high, irq[0] exception is generated, and this will load the call instruction in ir (instruction register) and 0h:0002h in pc. therefore, on an irq[0] exception, the "call {0h:pm[00002h]}" instruction is executed. when the irq[0] exception is executed, sr0[1] ( ie) is set to 0 and a core output signal nexpack is generated to acknowledge the exception. irq[1] exception (level-sensitive) when a core input signal nirq[1] is low, sr0[7] (ie1) is high, and sr0[1] ( ie) is high, irq[1] exception is generated, and this will load the call instruction in ir (instruction register) and 0h:0003h in pc. therefore, on an irq[1] exception, the "call {0h:pm[00003h]}" instruction is executed. when the irq[1] exception is executed, sr0[1] ( ie) is set to 0 and a core output signal nexpack is generated to acknowledge the exception. hardware stack full exception a stack full exception occurs when a stack operation is performed and as a result of the stack operation sptr[5] (sf) is set to 1. if the stack exception enable bit, exe (sr0[5]), is 1, the stack full exception is served. one exception to this rule is when nnmi causes a stack operation that sets sptr[5] (sf), since it has higher priority. handling a stack full exception may cause another stack full exception. in this case, the new exception is ignored. on a stack full exception, the call instruction is loaded in ir (instruction register) and 0h:0004h in pc. therefore, when the stack full exception is activated, the "call {0h:pm[00004h]}" instruction is executed. when the exception is executed, sr0[1] ( ie) is set to 0, and a core output signal nexpack is generated to acknowledge the exception. break exception break exception is reserved only for an in-circuit debugger. when a core input signal, bkreq , is high, the calmrisc core is halted or in the break mode, until bkreq is deactivated. another way to drive the calmrisc core into the break mode is by executing a break instruction, break. when break is fetched, it is decoded in the fetch cycle (if stage) and the calmrisc core output signal nbkack is generated in the second cycle (id/mem stage). an in-circuit debugger generates bkreq active by monitoring nbkack to be active. break instruction is exactly the same as the nop (no operation) instruction except that it does not increase the program counter and activates nbkack in the second cycle (or id/mem stage of the pipeline). there, once break is encountered in the program execution, it falls into a deadlock. break instruction is reserved for in-circuit debuggers only, so it should not be used in user programs. S3FB42F exceptions 6- 3 exceptions ( or interrupts) non-maskable interrupt - nmi 0001h - ext int 8 iis1 int wt int tb int ta int ivec0 0002h ivec1 0003h ext int 4 ext int 5 h/w h/w (s/w) vector source level reset (clear) reset or wdt overflow reset 0000h h/w iis0 int h/w (s/w) h/w (s/w) h/w (s/w) h/w (s/w) h/w (s/w) h/w (s/w) h/w (s/w) h/w (s/w) h/w (s/w) notes: 1. nmi has the highest priority for an interrupt level, followed by sf_excep, ivec0 and ivec1. 2. in the case of ivec0 and ivec1, one interrupt vector has several interrupt sources. the priority of the sources is controlled by setting the ipr register. 3. external interrupts are triggered by a rising or falling edge, depending on the corresponding control register setting, ext int0-ext int5 have no interrupt pending bit but have an enable bit. 4. after system reset, iis0 int has the highest priority in the ivec0 level, followed by iis1 int and other interrupt sources. 5. the interrupt priority can be changed by setting of ipr register. 6. the pending bit is cleared by hardware when cpu reads the iir register value. h/w (s/w) h/w (s/w) h/w (s/w) h/w (s/w) ext int 0 ext int 1 ext int 2 ext int 3 bt sio int iic int uart rx/error/tx int h/w (s/w) h/w (s/w) h/w (s/w) h/w (s/w) h/w (s/w) h/w (s/w) h/w usb/ppic int ext int 9 stack full exception 0004h sf_excep figure 6-1. interrupt structure exceptions S3FB42F 6- 4 ipr0 logic iir0 cpu ivec0 ipr0 imr0 logic imr0 stop & idle release imr1 logic imr1 irp1 ipr1 logic ivec1 iir1 irq0.0 irq0.1 irq0.2 irq0.3 irq0.4 irq0.5 irq0.6 irq0.7 irq1.0 irq1.1 irq1.2 irq1.3 irq1.4 irq1.5 irq1.6 irq1.7 ext int9 usb int ppic int uart_rx int uart_err int uart_tx int iic int sio int bt int ext int0 ext int1 ext int2 ext int3 ext int4 ext int5 note: the irq register value is cleared by h/w when the iir register is read by the programmer in an interrupt service routine. however, if you want to clear by s/w, then write the proper value to the iir register like above examples. for clear all the bits of irqx register at one time write "#08h" to the iirx register. iis0 int iis1 int ext int8 ta int tb int nt int clear (when writing clear bit value to bit .2 .1 .0) exmp) ld r0, #05h clear (when writing clear bit value to bit .2 .1 .0) exmp) ld r0, #02h ld iir0, r0 irq.5 is cleared ld iir1, r0 irq1.2 is cleared figure 6-2. interrupt structure S3FB42F exceptions 6- 5 interrupt mask registers .7 .6 .5 .4 .3 .2 .1 .0 interrupt mask register0 (imr0) 05h, r/w irq0.0 irq0.1 irq0.2 irq0.3 irq0.4 irq0.5 irq0.6 irq0.7 interrupt request enable bits: 0 = disable interrupt request 1 = enable interrupt request note: if you want to change the value of the imr register, then you first make disable global int by di instruction, and change the value of the imr register. .7 .6 .5 .4 .3 .2 .1 .0 interrupt mask register1 (imr1) 09h, r/w irq1.0 irq1.1 irq1.2 irq1.3 irq1.4 irq1.5 irq1.6 irq1.7 figure 6-3. interrupt mask register exceptions S3FB42F 6- 6 interrupt priority register group a 0 = irq0 > irq1 1 = irq1 > irq0 interrupt priority registers (ipr0:06h,ipr1:0ah, r/w ) ipr group a note: if you want to change the value of the ipr register, then you first make disable global int by di instruction, and change the value of the ipr register. ipr group b ipr group c irq0 irq1 irq2 irq3 irq4 irq5 irq6 irq7 group b 0 = irq2 > (irq3,irq4) 1 = (irq3,irq4) > irq2 subgroup b 0 = irq3 > irq4 1 = irq4 > irq3 group c 0 = irq5 > (irq6,irq7) 1 = (irq6,irq7) > irq5 subgroup c 0 = irq6 > irq7 1 = irq7 > irq6 .7 .6 .5 .4 .3 .2 .1 .0 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 not used b>c>a a>b>c b>a>c c>a>b c>b>a a>c>b not used .7 .4 .1 group priority: figure 6-4. interrupt priority register S3FB42F exceptions 6- 7 f f programming tip ? interrupt programming tip 1 jumped from vector 2 push sr1 push r0 and sr0, #0feh ld r0, iir0 cp r0, #03h jr ule, lte03 cp r0, #05h jr ule, lte05 cp r0, #06h jp eq, irq6_srv jp irq7_srv lte05 cp r0, #04h jp eq, irq4_srv jp irq5_srv lte03 cp r0, #01h jr ule, lte01 cp r0, #02h jp eq, irq2_srv jp irq3_srv lte01 cp r0, #00h jp eq, irq0_srv jp irq1_srv irq0_srv ? service for irq0 pop r0 pop sr1 iret irq1_srv ? service for irq1 pop r0 pop sr1 iret irq7_srv ? service for irq7 pop r0 pop sr1 iret note: if the sr0 register is changed in the interrupt service routine, then the sr0 register must be pushed and poped in the interrupt service routine. exceptions S3FB42F 6- 8 f f programming tip ? interrupt programming tip 2 jumped from vector 2 push sr1 push r0 push r1 ld r0, iir0 sl r0 ld r1, # < tbl_intx add r0, # > tbl_intx push r0 push r1 ret tbl_intx ljp irq0_svr ljp irq1_svr ljp irq2_svr ljp irq3_svr ljp irq4_svr ljp irq5_svr ljp irq6_svr ljp irq7_svr irq0_srv ? service for irq0 pop r1 pop r0 pop sr1 iret irq1_srv ? service for irq1 pop r1 pop r0 pop sr1 iret irq7_srv ? service for irq7 pop r1 pop r0 pop sr1 iret notes: 1. if the sr0 register is changed in the interrupt service routine, then the sr0 register must be pushed and poped in the interrupt service routine. 2. above example is assumed that the rom size is less than 64kword and all the ljp instructions which is in the jump table (tbl- intx) is in the same page. S3FB42F coprocessor interface 7- 1 7 coprocessor interfa ce overview calmrisc supports an efficient and seamless interface with coprocessors. by integrating a mac (multiply and accumulate) dsp coprocessor engine with the calmrisc core, not only the microcontroller functions but also complex digital signal processing algorithms can be implemented in a single development platform (or mds). calmrisc has a set of dedicated signal pins, through which data/command/status are exchanged to and from a coprocessor. figure 7-1 depicts the coprocessor signal pins and the interface between two processors. data bus [7:0] syscp [11:0] ncopid ncldid cldwr ec[2:0] coprocessor calmrisc program rom [23:0] data ram [23:0] [7:0] figure 7-1. coprocessor interface diagram coprocessor interface S3FB42F 7- 2 as shown in the coprocessor interface diagram above, the coprocessor interface signals of calmrisc are: syscp[11:0] , ncopid , ncldid , ncldwr , and ec[2:0] . the data are exchanged through data buses, di[7:0] and do[7:0] . a command is issued from calmrisc to a coprocessor through syscp[11:0] in cop instructions. the status of a coprocessor can be sent back to calmrisc through ec[2:0] and these flags can be checked in the condition codes of branch instructions. the coprocessor instructions are listed in the following table table 7-1. coprocessor instructions mnemonic op 1 op 2 description cop #imm:12 ? coprocessor operation cld gpr imm:8 data transfer from coprocessor into gpr cld imm:8 gpr data transfer of gpr to coprocessor jp(or jr) call lnk ec2?ec0 label conditional branch with coprocessor status flags the coprocessor of calmrisc does not have its own program memory (i.e., it is a passive coprocessor) as shown in figure 7 -1. in fact, the coprocessor instructions are fetched and decoded by calmrisc, and calmrisc issues the command to the coprocessor through the interface signals. for example, if ?cop #imm:12? instruction is fetched, then the 12-bit immediate value (imm:12) is loaded on syscp[11:0] signal with ncopid active in id/mem stage, to request the coprocessor to perform the designated operation. the interpretation of the 12-bit immediate value is totally up to the coprocessor. by arranging the 12-bit immediate field, the instruction set of the coprocessor is determined. in other words, calmrisc only provides a set of generic coprocessor instructions, and its installation to a specific coprocessor instruction set can differ from one coprocessor to another. cld write instructions ( ? cld imm:8, gpr ? ) put the content of a gpr register of calmrisc on the data bus ( do[7:0] ) and issue the address(imm:8) of the coprocessor internal register on syscp[7:0] with ncldid active and cldwr active. cld read instructions ( ? cld gpr, imm:8 ? in table 7-1) work similarly, except that the content of the coprocessor internal register addressed by the 8-bit immediate value is read into a gpr register through di[7:0] with ncldid active and cldwr deactivated. the timing diagram given below is a coprocessor instruction pipeline and shows when the coprocessor performs the required operations. suppose i 2 is a coprocessor instruction. first, it is fetched and decoded by calmrisc (at t = t(i- 1)). once it is identified as a coprocessor instruction, calmrisc indicates to the coprocessor the appropriate command through the coprocessor interface signals (at t = t( i)). then the coprocessor performs the designated tasks at t = t( i) and t = t(i+1). hence if from calmrisc and then id/mem and ex from the coprocessor constitute the pipeline for i 2 . similarly, if i 3 is a coprocessor instruction, the coprocessor ? s id/mem and ex stages replace the corresponding stages of calmrisc. S3FB42F coprocessor interface 7- 3 calmrisc if id/mem ex if id/mem if ex id/mem ex i 2 : coprocessor instruction t (i -1) t (i) t (i +1) i 1 : normal instruction i 3 : coprocessor instruction for i 3 for i 2 id/mem ex id/mem ex coprocessor i 2: i 3 : coprocessor interface signals figure 7-2. coprocessor instruction pipeline in a multi-processor system, the data transfer between processors is an important factor to determine the efficiency of the overall system. suppose an input data stream is accepted by a processor, in order for the data to be shared by another processors. there should be some efficient mechanism to transfer the data to the processors. in calmrisc, data transfers are accomplished through a single shared data memory. the shared data memory in a multi-processor has some inherent problems such as data hazards and deadlocks. however, the coprocessor in calmrisc accesses the shared data memory only at the designated time by calmrisc at which time calmrisc is guaranteed not to access the data memory, and therefore there is no contention over the shared data memory. another advantage of the scheme is that the coprocessor can access the data memory in its own bandwidth. coprocessor interface S3FB42F 7- 4 notes S3FB42F instruction set 8- 1 8 instruction set overview glossary this chapter describes the calmrisc instruction set and the details of each instruction are listed in alphabetical order. the following notations are used for the description. table 8-1. instruction notation conventions notation interpretation instruction set s3f b42f 8- 2 instruction set map table 8-2. overall instruction set map ir [12:10]000 001 010 011 100 101 110 111 [15:13,7:2] 000 xxxxxx add gpr, #imm:8 sub gpr, #imm:8 cp gpr, #imm8 ld gpr, #imm:8 tm gpr, #imm:8 and gpr, #imm:8 or gpr, #imm:8 xor gpr, #imm:8 001 xxxxxx add gpr, @idm sub gpr, @idm cp gpr, @idm ld gpr, @idm ld @idm, gpr and gpr, @idm or gpr, @idm xor gpr, @idm 010 xxxxxx add gpr, adr:8 sub gpr, adr:8 cp gpr, adr:8 ld gpr, adr:8 bitt adr:8.bs bits adr:8.bs 011 xxxxxx adc gpr, adr:8 sbc gpr, adr:8 cpc gpr, adr:8 ld adr:8, gpr bitr adr:8.bs bitc adr:8.bs 100 000000 add gpr, gpr sub gpr, gpr cp gpr, gpr bms/bmc ld spr0, #imm:8 and gpr, adr:8 or gpr, adr:8 xor gpr, adr:8 100 000001 adc gpr, gpr sbc gpr, gpr cpc gpr, gpr invalid 100 000010 invalid invalid invalid invalid 100 000011 and gpr, gpr or gpr, gpr xor gpr, gpr invalid 100 00010x sla/sl/ rlc/rl/ sra/sr/ rrc/rr/ gpr inc/incc/ dec/ decc/ com/ com2/ comc gpr invalid invalid 100 00011x ld spr, gpr ld gpr, spr swap gpr, spr ld tbh/tbl, gpr 100 00100x push spr pop spr invalid invalid 100 001010 push gpr pop gpr ld gpr, gpr ld gpr, tbh/tbl S3FB42F instruction set 8- 3 table 8-2. overall instruction set map (continued) ir [12:10]000 001 010 011 100 101 110 111 100 001011 pop invalid ldc invalid ld spr0, #imm:8 and gpr, adr:8 or gpr, adr:8 xor gpr, adr:8 100 00110x ret/lret/i ret/nop/ break invalid invalid invalid 100 00111x invalid invalid invalid invalid 100 01xxxx ld gpr:bank, gpr:bank and sr0, #imm:8 or sr0, #imm:8 bank #imm:2 100 100000 100 110011 invalid invalid invalid invalid 100 1101xx lcall cc:4, imm:20 (2-word instruction) 100 1110xx llnk cc:4, imm:20 (2-word instruction) 100 1111xx ljp cc:4, imm:20 (2-word instruction) [15:10] 101 xxx jr cc:4, imm:9 110 0xx calls imm:12 110 1xx lnks imm:12 111 xxx cld gpr, imm:8 / cld imm:8, gpr / jnzd gpr, imm:8 / sys #imm:8 / cop #imm:12 note: ? invalid ? - invalid instruction. instruction set s3f b42f 8- 4 table 8-3. instruction encoding instruction 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 add gpr, #imm:8 000 000 gpr imm[7:0] sub gpr, #imm:8 001 cp gpr, #imm:8 010 ld gpr, #imm:8 011 tm gpr, #imm:8 100 and gpr, #imm:8 101 or gpr, #imm:8 110 xor gpr, #imm:8 111 add gpr, @idm 001 000 gpr idx mod offset[4:0] sub gpr, @idm 001 cp gpr, @idm 010 ld gpr, @idm 011 ld @idm, gpr 100 and gpr, @idm 101 or gpr, @idm 110 xor gpr, @idm 111 add gpr, adr:8 010 000 gpr adr[7:0] sub gpr, adr:8 001 cp gpr, adr:8 010 ld gpr, adr:8 011 bitt adr:8.bs 10 bs bits adr:8.bs 11 adc gpr, adr:8 011 000 gpr adr[7:0] sbc gpr, adr:8 001 cpc gpr, adr:8 010 ld adr:8, gpr 011 bitr adr:8.bs 10 bs bitc adr:8.bs 11 S3FB42F instruction set 8- 5 table 8-3. instruction encoding (continued ) instruction 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 add gprd, gprs 100 000 gprd 000000 gprs sub gprd, gprs 001 cp gprd, gprs 010 bms/bmc 011 adc gprd, gprs 000 000001 sbc gprd, gprs 001 cpc gprd, gprs 010 invalid 011 invalid ddd 000010 and gprd, gprs 000 000011 or gprd, gprs 001 xor gprd, gprs 010 invalid 011 aluop1 000 gpr 00010 aluop1 aluop2 001 gpr aluop2 invalid 010?011 xx xxx ld spr, gpr 000 gpr 00011 spr ld gpr, spr 001 gpr spr swap gpr, spr 010 gpr spr ld tbl, gpr 011 gpr x 0 x ld tbh, gpr x 1 x push spr 000 xx 00100 spr pop spr 001 xx spr invalid 010?011 xx xxx push gpr 000 gpr 001010 gpr pop gpr 001 gpr gpr ld gprd, gprs 010 gprd gprs ld gpr, tbl 011 gpr 0 x ld gpr, tbh 1 x pop 000 xx 001011 xx ldc @il 010 0 x ldc @il+ 1 x invalid 001, 011 xx note: "x" means not applicable. instruction set s3f b42f 8- 6 table 8-3. instruction encoding (concluded ) instruction 15-13 12 11 10 9 8 7 6 5 4 3 2 1 0 2 nd word modop1 100 000 xx 00110 modop1 ? invalid 001?011 xx xxx invalid 000 xx 01 xxxxxx and sr0, #imm:8 001 imm[7:6] imm[5:0] or sr0, #imm:8 010 imm[7:6] bank #imm:2 011 xx x imm [1:0] xxx invalid 0 xxxx 10000000-11001111 lcall cc, imm:20 cc 1101 imm[19:16] imm[15:0] llnk cc, imm:20 ljp cc, imm:20 ld spr0, #imm:8 1 00 spr0 imm[7:0] ? and gpr, adr:8 01 gpr adr[7:0] or gpr, adr:8 10 xor gpr, adr:8 11 jr cc, imm:9 101 imm [8] cc imm[7:0] calls imm:12 110 0 imm[11:0] lnks imm:12 1 cld gpr, imm:8 111 0 00 gpr imm[7:0] cld imm:8, gpr 01 gpr jnzd gpr, imm:8 10 gpr sys #imm:8 11 xx cop #imm:12 1 imm[11:0] notes: 1. "x" means not applicable. 2. there are several modop1 codes that can be used, as described in table 8-9. 3. the operand 1(gpr) of the instruction jnzd is bank 3?s register. S3FB42F instruction set 8- 7 table 8-4. index code information (?idx?) symbol code description id0 0 index 0 idh:idl0 id1 1 index 1 idh:idl1 table 8-5. index modification code information (?mod?) symbol code function @idx + offset:5 00 dm[idx], idx ? idx + offset @[idx - offset:5] 01 dm[idx + (2?s complement of offset:5)], idx ? idx + (2?s complement of offset:5) @[idx + offset:5]! 10 dm[idx + offset], idx ? idx @[idx - offset:5]! 11 dm[idx + (2?s complement of offset:5)], idx ? idx note: carry from idl is propagated to idh. in case of @[idx - offset:5] or @[idx - offset:5]!, the assembler should convert offset:5 to the 2?s complement format to fill the operand field (offset[4:0]). furthermore, @[idx - 0] and @[idx - 0]! are converted to @[idx + 0] and @[idx + 0]!, respectively. table 8-6. condition code information (?cc?) symbol (cc:4) code function blank 0000 always nc or ult 0001 c = 0, unsigned less than c or uge 0010 c = 1, unsigned greater than or equal to z or eq 0011 z = 1, equal to nz or ne 0100 z = 0, not equal to ov 0101 v = 1, overflow - signed value ule 0110 ~c | z, unsigned less than or equal to ugt 0111 c & ~z, unsigned greater than zp 1000 n = 0, signed zero or positive mi 1001 n = 1, signed negative pl 1010 ~n & ~z, signed positive zn 1011 z | n, signed zero or negative sf 1100 stack full ec0-ec2 1101-1111 ec[0] = 1/ec[1] = 1/ec[2] = 1 note: ec[2:0] is an external input (calmrisc core?s point of view) and used as a condition. instruction set s3f b42f 8- 8 table 8-7. ?aluop1? code information symbol code function sla 000 arithmetic shift left sl 001 shift left rlc 010 rotate left with carry rl 011 rotate left sra 100 arithmetic shift right sr 101 shift right rrc 110 rotate right with carry rr 111 rotate right table 8-8. ?aluop2? code information symbol code function inc 000 increment incc 001 increment with carry dec 010 decrement decc 011 decrement with carry com 100 1?s complement com2 101 2?s complement comc 110 1?s complement with carry ? 111 reserved table 8-9. ?modop1? code information symbol code function lret 000 return by il ret 001 return by hs iret 010 return from interrupt (by hs) nop 011 no operation break 100 reserved for debugger use only ? 101 reserved ? 110 reserved ? 111 reserved S3FB42F instruction set 8- 9 quick reference operation op1 op2 function flag # of word / cycle and or xor add sub cp gpr adr:8 #imm:8 gpr @idm op1 ? op1 & op2 op1 ? op1 | op2 op1 ? op1 ^ op2 op1 ? op1 + op2 op1 ? op1 + ~op2 + 1 op1 + ~op2 + 1 z,n z,n z,n c,z,v,n c,z,v,n c,z,v,n 1w1c adc sbc cpc gpr gpr adr:8 op1 ? op1 + op2 + c op1 ? op1 + ~op2 + c op1 + ~op2 + c c,z,v,n c,z,v,n c,z,v,n tm gpr #imm:8 op1 & op2 z,n bits bitr bitc bitt r3 adr:8.bs op1 ? (op2[bit] ? 1) op1 ? (op2[bit] ? 0) op1 ? ~(op2[bit]) z ? ~(op2[bit]) z z z z bms/bmc ? ? tf ? 1 / 0 ? push pop gpr ? hs[sptr] ? gpr, (sptr ? sptr + 1) gpr ? hs[ sptr - 1], (sptr ? sptr - 1) ? z,n push pop spr ? hs[sptr] ? spr, (sptr ? sptr + 1) spr ? hs[ sptr - 1], (sptr ? sptr - 1) ? pop ? ? sptr ? sptr ? 2 ? sla sl rlc rl sra sr rrc rr inc incc dec decc com com2 comc gpr ? c ? op1[7], op1 ? {op1[6:0], 0} c ? op1[7], op1 ? {op1[6:0], 0} c ? op1[7], op1 ? {op1[6:0], c} c ? op[7], op1 ? {op1[6:0], op1[7]} c ? op[0], op1 ? {op1[7],op1[7:1]} c ? op1[0], op1 ? {0, op1[7:1]} c ? op1[0], op1 ? {c, op1[7:1]} c ? op1[0], op1 ? {op1[0], op1[7:1]} p1 ? op1 + 1 op1 ? op1 + c op1 ? op1 + 0ffh op1 ? op1 + 0ffh + c op1 ? ~op1 op1 ? ~op1 + 1 op1 ? ~op1 + c c,z,v,n c,z,n c,z,n c,z,n c,z,n c,z,n c,z,n c,z,n c,z,v,n c,z,v,n c,z,v,n c,z,v,n z,n c,z,v,n c,z,v,n instruction set s3f b42f 8- 10 quick reference ( continued ) operation op1 op2 function flag # of word / cycle ld gpr :bank gpr :bank op1 ? op2 z,n 1w1c ld spr0 #imm:8 op1 ? op2 ? ld gpr gpr spr adr:8 @idm #imm:8 tbh/tbl op1 ? op2 z,n ld spr tbh/tbl gpr op1 ? op2 ? ld adr:8 gpr op1 ? op2 ? ld @idm gpr op1 ? op2 ? ldc @il @il+ ? (tbh:tbl) ? pm[(ilx:ilh:ill)], ill++ if @il+ ? 1w2c and or sr0 #imm:8 sr0 ? sr0 & op2 sr0 ? sr0 | op2 ? 1w1c bank #imm:2 ? sr0[4:3] ? op2 ? swap gpr spr op1 ? op2, op2 ? op1 (excluding sr0/sr1) ? lcall cc imm:20 ? if branch taken, push xstack, hs[15:0] ? {pc[15:12],pc[11:0] + 2} and pc ? op1 else pc[11:0] ? pc[11:0] + 2 ? 2w2c llnk cc imm:20 ? if branch taken, il[19:0] ? {pc[19:12], pc[11:0] + 2} and pc ? op1 else pc[11:0] ? pc[11:0] + 2 ? calls imm:12 ? push xstack, hs[15:0] ? {pc[15:12], pc[11:0] + 1} and pc[11:0] ? op1 ? 1w2c lnks imm:12 ? il[19:0] ? {pc[19:12], pc[11:0] + 1} and pc[11:0] ? op1 ? jnzd rn imm:8 if (rn == 0) pc ? pc[delay slot] - 2?s complement of imm:8, rn-- else pc ? pc[delay slot]++, rn-- ? ljp cc imm:20 ? if branch taken, pc ? op1 else pc[11:0] < pc[11:0] + 2 ? 2w2c jr cc imm:9 ? if branch taken, pc[11:0] ? pc[11:0] + op1 else pc[11:0] ? pc[11:0] + 1 ? 1w2c note: op1 - operand1, op2 - operand2, 1w1c - 1-word 1-cycle instruction, 1w2c - 1-word 2-cycl e instruction, 2w2c - 2-word 2-cycle instruction. the rn of instruction jnzd is bank 3?s gpr. S3FB42F instruction set 8- 11 quick reference ( concluded ) operation op1 op2 function flag # of word / cycle lret ret iret nop break ? ? pc ? il[19:0] pc ? hs[ sptr - 2], (sptr ? sptr - 2) pc ? hs[ sptr - 2], (sptr ? sptr - 2) no operation no operation and hold pc ? 1w2c 1w2c 1w2c 1w1c 1w1c sys #imm:8 ? no operation but generates syscp[7:0] and nsysid ? 1w1c cld imm:8 gpr op1 ? op2, generates syscp[7:0], ncldid, and cldwr ? cld gpr imm:8 op1 ? op2, generates syscp[7:0], ncldid, and cldwr z,n cop #imm:12 ? generates syscp[11:0] and ncopid ? notes: 1. op1 - operand1, op2 - operand2, sptr - stack pointer register, 1w1c - 1-word 1-cycle instruction, 1w2c - 1-word 2-cycle instruction 2. pseudo instructions ? scf/rcf carry flag set or reset instruction ? stop/idle mcu power saving instructions ? ei/di exception enable and disable instructions ? jp/lnk/call if jr/lnks/calls commands (1 word instructions) can access the target address, there is no conditional code in the case of call/lnk, and the jp/lnk/call commands are assembled to jr/lnks/calls in linking time, or else the jp/lnk/call commands are assembled to ljp/llnk/lcall (2 word instructions) instr uctions. instruction set s3f b42f 8- 12 instruction group summary alu instructions ?alu instructions? refer to the operations that use alu to generate results. alu instructions update the values in status register 1 (sr1), namely carry (c), zero (z), overflow (v), and negative (n), depending on the operation type and the result. aluop gpr, adr:8 performs an alu operation on the value in gpr and the value in dm[adr:8] and stores the result into gpr. aluop = add, sub, cp, and, or, xor for sub and cp, gpr+(not dm[adr:8])+1 is performed. adr:8 is the offset in a specific data memory page. the data memory page is 0 or the value of idh (index of data memory higher byte register), depending on the value of eid in status register 0 (sr0). operation gpr ? gpr aluop dm[00h:adr:8] if eid = 0 gpr ? gpr aluop dm[idh:adr8] if eid = 1 note that this is an 8-bit operation. example add r0, 80h // assume eid = 1 and idh = 01h // r0 ? r0 + dm[0180h] aluop gpr, #imm:8 stores the result of an alu operation on gpr and an 8-bit immediate value into gpr. aluop = add, sub, cp, and, or, xor for sub and cp, gpr+(not #imm:8)+1 is performed. #imm:8 is an 8-bit immediate value. operation gpr ? gpr aluop #imm:8 example add r0, #7ah // r0 ? r0 + 7ah S3FB42F instruction set 8- 13 aluop gprd, gprs store the result of aluop on gprs and gprd into gprd. aluop = add, sub, cp, and, or, xor for sub and cp, gprd + (not gprs) + 1 is performed. gprs and gprd need not be distinct. operation gprd ? gprd aluop gprs gprd - gprs when aluop = cp (comparison only) example add r0, r1 // r0 ? r0 + r1 aluop gpr, @idm performs aluop on the value in gpr and dm[id] and stores the result into gpr. index register id is idh:idl (idh:idl0 or idh:idl1). aluop = add, sub, cp, and, or, xor for sub and cp, gpr+(not dm[idm])+1 is performed. idm = idx+off:5, [idx-offset:5], [idx+offset:5]!, [idx-offset:5]! (idx = id0 or id1) operation gpr - dm[idm] when aluop = cp (comparison only) gpr ? gpr aluop dm[idx], idx ? idx + offset:5 when idm = idx + offset:5 gpr ? gpr aluop dm[idx - offset:5], idx ? idx - offset:5 when idm = [idx - offset:5] gpr ? gpr aluop dm[idx + offset:5] when idm = [idx + offset:5]! gpr ? gpr aluop dm[idx - offset:5] when idm = [idx - offset:5]! when carry is generated from idl (on a post-increment or pre-decrement), it is propagated to idh. example add r0, @id0+2 // assume id0 = 02ffh // r0 ? r0 + dm[02ffh], idh ? 03h and idl0 ? 01h add r0, @[id0-2] // assume id0 = 0201h // r0 ? r0 + dm[01ffh], idh ? 01h and idl0 ? ffh add r0, @[id1+2]! // assume id1 = 02ffh // r0 ? r0 + dm[0301], idh ? 02h and idl1 ? ffh add r0, @[id1-2]! // assume id1 = 0200h // r0 ? r0 + dm[01feh], idh ? 02h and idl1 ? 00h instruction set s3f b42f 8- 14 aluopc gprd, gprs performs aluop with carry on gprd and gprs and stores the result into gprd. aluopc = adc, sbc, cpc gprd and gprs need not be distinct. operation gprd ? gprd + gprs + c when aluopc = adc gprd ? gprd + (not gprs) + c when aluopc = sbc gprd + (not gprs) + c when aluopc = cpc (comparison only) example add r0, r2 // assume r1:r0 and r3:r2 are 16-bit signed or unsigned numbers. adc r1, r3 // to add two 16-bit numbers, use add and adc. sub r0, r2 // assume r1:r0 and r3:r2 are 16-bit signed or unsigned numbers. sbc r1, r3 // to su btract two 16-bit numbers, use sub and sbc. cp r0, r2 // assume both r1:r0 and r3:r2 are 16-bit unsigned numbers. cpc r1, r3 // to compare two 16-bit unsigned numbers, use cp and cpc. aluopc gpr, adr:8 performs aluop with carry on gpr and dm[adr:8]. operation gpr ? gpr + dm[adr:8] + c when aluopc = adc gpr ? gpr + (not dm[adr:8]) + c when aluopc = sbc gpr + (not dm[adr:8]) + c when aluopc = cpc (comparison only) cplop gpr (complement operations ) cplop = com, com2, comc operation com gpr not gpr (logical complement) com2 gpr not gpr + 1 (2?s complement of gpr) comc gpr not gpr + c (logical complement of gpr with carry) example com2 r0 // assume r1:r0 is a 16-bit signed number. comc r1 // com2 and comc can be used to get the 2?s complement of it. S3FB42F instruction set 8- 15 incdec gpr (increment/decrement operations) incdec = inc, incc, dec, decc operation inc gpr increase gpr, i.e., gpr ? gpr + 1 incc gpr in crease gpr if carry = 1, i.e., gpr ? gpr + c dec gpr decrease gpr, i.e., gpr ? gpr + ffh decc gpr decrease gpr if carry = 0, i.e., gpr ? gpr + ffh + c example inc r0 // assume r1:r0 is a 16-bit number incc r1 // to increase r1:r0, use inc and incc. dec r0 // assume r1:r0 is a 16-bit number decc r1 // to decrease r1:r0, use dec and decc. instruction set s3f b42f 8- 16 shift/rotate instructions shift (rotate) instructions shift (rotate) the given operand by 1 bit. depending on the operation performed, a number of status register 1 (sr1) bits, namely carry (c), zero (z), overflow (v), and negative (n), are set. sl gpr operation c 7 0 0 gpr carry (c) is the msb of gpr before shifting, negative (n) is the msb of gpr after shifting. overflow (v) is not affected. zero (z) will be 1 if the result is 0. sla gpr operation c 7 0 0 gpr carry (c) is the msb of gpr before shifting, negative (n) is the msb of gpr after shifting. overflow (v) will be 1 if the msb of the result is different from c. z will be 1 if the result is 0. rl gpr operation c 7 0 gpr carry (c) is the msb of gpr before rotating. negative (n) is the msb of gpr after rotatin/g. overflow (v) is not affected. zero (z) will be 1 if the result is 0. rlc gpr operation c 7 0 gpr carry (c) is the msb of gpr before rotating, negative (n) is the msb of gpr after rotating. overflow (v) is not affected. zero (z) will be 1 if the result is 0. S3FB42F instruction set 8- 17 sr gpr operation c 7 0 0 gpr carry (c) is the lsb of gpr before shifting, negative (n) is the msb of gpr after shifting. overflow (v) is not affected. zero (z) will be 1 if the result is 0. sra gpr operation c 7 0 gpr carry (c) is the lsb of gpr before shifting, negative (n) is the msb of gpr after shifting. overflow (v) is not affected. z will be 1 if the result is 0. rr gpr operation c 7 0 gpr carry (c) is the lsb of gpr before rotating. negative (n) is the msb of gpr after rotating. overflow (v) is not affected. zero (z) will be 1 if the result is 0. rrc gpr operation c 7 0 gpr carry (c) is the lsb of gpr before rotating, negative (n) is the msb of gpr after rotating. overflow (v) is not affected. zero (z) will be 1 if the result is 0. instruction set s3f b42f 8- 18 load instructions load instructions transfer data from data memory to a register or from a register to data memory, or assigns an immediate value into a register. as a side effect, a load instruction placing a value into a register sets the zero (z) and negative (n) bits in status register 1 (sr1), if the placed data is 00h and the msb of the data is 1, respectively. ld gpr, adr:8 loads the value of dm[adr:8] into gpr. adr:8 is offset in the page specified by the value of eid in status register 0 (sr0). operation gpr ? dm[00h:adr:8] if eid = 0 gpr ? dm[idh:adr:8] if eid = 1 note that this is an 8-bit operation. example ld r0, 80h // assume eid = 1 and idh= 01h // r0 ? dm[0180h] ld gpr, @idm loads a value from the data memory location specified by @idm into gpr. idm = idx+off:5, [idx-offset:5], [idx+offset:5]!, [idx-offset:5]! (idx = id0 or id1) operation gpr ? dm[idx], idx ? idx + offset:5 when idm = idx + offset:5 gpr ? dm[idx - offset:5], idx ? idx - offset:5 when idm = [idx - offset:5] gpr ? dm[idx + offset:5] when idm = [idx + offset:5]! gpr ? dm[idx - offset:5] when idm = [idx - offset:5]! when carry is generated from idl (on a post-increment or pre-decrement), it is propagated to idh. example ld r0, @[id0 + 03h]! // assume idh:idl0 = 0270h // r0 ? dm[0273h], idh:idl0 ? 0270h S3FB42F instruction set 8- 19 ld reg, #imm:8 loads an 8-bit immediate value into reg. reg can be either gpr or an spr0 group register - idh (index of data memory higher byte register), idl0 (index of data memory lower byte register)/ idl1, and status register 0 (sr0). #imm:8 is an 8-bit immediate value. operation reg ? #imm:8 example ld r0 #7ah // r0 ? 7ah ld idh, #03h // idh ? 03h ld gpr:bs:2, gpr:bs:2 loads a value of a register from a specified bank into another register in a specified bank. example ld r0:1, r2:3 // r0 in bank 1, r2 in bank 3 ld gpr, tbh/tbl loads the value of tbh or tbl into gpr. tbh and tbl are 8-bit long registers used exclusively for ldc instructions that access program memory. therefore, after an ldc instruction, ld gpr, tbh/tbl instruction will usually move the data into gprs, to be used for other operations. operation gpr ? tbh (or tbl) example ldc @il // gets a program memory item residing @ ilx:ilh:ill ld r0, tbh ld r1, tbl ld tbh/tbl, gpr loads the value of gpr into tbh or tbl. these instructions are used in pair in interrupt service routines to save and restore the values in tbh/tbl as needed. operation tbh (or tbl) ? gpr ld gpr, spr loads the value of spr into gpr. operation gpr ? spr example ld r0, idh // r0 ? idh instruction set s3f b42f 8- 20 ld spr, gpr loads the value of gpr into spr. operation spr ? gpr example ld idh, r0 // idh ? r0 ld adr:8, gpr stores the value of gpr into data memory (dm). adr:8 is offset in the page specified by the value of eid in status register 0 (sr0). operation dm[00h:adr:8] ? gpr if eid = 0 dm[idh:adr:8] ? gpr if eid = 1 note that this is an 8-bit operation. example ld 7ah, r0 // assume eid = 1 and idh = 02h. // dm[027ah] ? r0 ld @idm, gpr loads a value into the data memory location specified by @idm from gpr. idm = idx+off:5, [idx-offset:5], [idx+offset:5]!, [idx-offset:5]! (idx = id0 or id1) operation dm[idx] ? gpr, idx ? idx + offset:5 when idm = idx + offset:5 dm[idx - offset:5] ? gpr, idx ? idx - offset:5 when idm = [idx - offset:5] dm[idx + offset:5] ? gpr when idm = [idx + offset:5]! dm[idx - offset:5] ? gpr when idm = [idx - offset:5]! when carry is generated from idl (on a post-increment or pre-decrement), it is propagated to idh. example ld @[id0 + 03h]!, r0 // assume idh:idl0 = 0170h // dm[0173h] ? r0, idh:idl0 ? 0170h S3FB42F instruction set 8- 21 branch instructions branch instructions can be categorized into jump instruction, link instruction, and call instruction. a jump instruction does not save the current pc, whereas a call instruction saves (?pushes?) the current pc onto the stack and a link instruction saves the pc in the link register il. status registers are not affected. each instruction type has a 2-word format that supports a 20-bit long jump. jr cc:4, imm:9 imm:9 is a signed number (2?s complement), an offset to be added to the current pc to compute the target (pc[19:12]:(pc[11:0] + imm:9)). operation pc[11:0] ? pc[11:0] + imm:9 if branch taken (i.e., cc:4 resolves to be true) pc[11:0] ? pc[11:0] + 1 otherwise example l18411: // assume current pc = 18411h. jr z, 107h // next pc is 18518 (18411h + 107h) if zero (z) bit is set. ljp cc:4, imm:20 jumps to the program address specified by imm:20. if program size is less than 64k word, pc[19:16] is not affected. operation pc[15:0] ? imm[15:0] if branch taken and program size is less than 64k word pc[19:0] ? imm[19:0] if branch taken and program size is equal to 64k word or more pc [11:0] ? pc[11:0] + 1 otherwise example l18411: // assume current pc = 18411h. ljp z, 10107h // next instruction?s pc is 10107h if zero (z) bit is set jnzd rn, imm:8 jumps to the program address specified by imm:8 if the value of the bank 3 register rn is not zero. jnzd performs only backward jumps, with the value of rn automatically decreased. there is one delay slot following the jnzd instruction that is always executed, regardless of whether jnzd is taken or not. operation if (rn == 0) pc ? pc[delay slot] (-) 2?s complement of imm:8, rn ? rn - 1 else pc ? pc[delay slot] + 1, rn ? rn - 1. instruction set s3f b42f 8- 22 example loop_a: // start of loop body jnzd r0, loop_a // jump back to loop_a if r0 is not zero add r1, #2 // delay slot, always executed (you must use one cycle instruction only) calls imm:12 saves the current pc on the stack (?pushes? pc) and jumps to the program address specified by imm:12. the current page number pc[19:12] is not changed. since this is a 1-word instruction, the return address pushed onto the stack is (pc + 1). if np64kw is low when pc is saved, pc[19:16] is not saved in the stack. operation hs[sptr][15:0] ? current pc + 1 and sptr ? sptr + 2 (push stack) if np64kw = 0 hs[sptr][19:0] ? current pc + 1 and sptr ? sptr + 2 (push stack) if np64kw = 1 pc[11:0] ? imm:12 example l18411: // assume current pc = 18411h. calls 107h // call the subroutine at 18107h, with the current pc pushed // onto the stack (hs ? 18412h) if np64kw = 1. lcall cc:4, imm:20 saves the current pc onto the stack (pushes pc) and jumps to the program address specified by imm:20. since this is a 2-word instruction, the return address saved in the stack is (pc + 2). if np64kw, a core input signal is low when pc is saved, 0000111111pc[19:16] is not saved in the stack and pc[19:16] is not set to imm[19:16]. operation hs[sptr][15:0] ? current pc + 2 and sptr + 2 (push stack) if branch taken and np64kw = 0 hs[sptr][19:0] ? current pc + 2 and sptr + 2 (push stack) if branch taken and np64kw = 1 pc[15:0] ? imm[15:0] if branch taken and np64kw = 0 pc[19:0] ? imm[19:0] if branch taken and np64kw = 1 pc[11:0] ? pc[11:0] + 2 otherwise example l18411: // assume current pc = 18411h. lcall nz, 10h:107h // call the subroutine at 10107h with the current pc pushed // onto the stack (hs ? 18413h) S3FB42F instruction set 8- 23 lnks imm:12 saves the current pc in il and jumps to the program address specified by imm:12. the current page number pc[19:12] is not changed. since this is a 1-word instruction, the return address saved in il is (pc + 1). if the program size is less than 64k word when pc is saved, pc[19:16] is not saved in ilx. operation il[15:0] ? current pc + 1 if program size is less than 64k word il[19:0] ? current pc + 1 if program size is equal to 64k word or more pc[11:0] ? imm:12 example l18411: // assume current pc = 18411h. lnks 107h // call the subroutine at 18107h, with the current pc saved // in il (il[19:0] ? 18412h) if program size is 64k word or more. llnk cc:4, imm:20 saves the current pc in il and jumps to the program address specified by imm:20. since this is a 2-word instruction, the return address saved in il is (pc + 2). if the program size is less than 64k word when pc is saved, pc[19:16] is not saved in ilx. operation il[15:0] ? current pc + 2 if branch taken and program size is less than 64k word il[19:0] ? current pc + 2 if branch taken and program size is 64k word or more pc[15:0] ? imm[15:0] if branch taken and program size is less than 64k word pc[19:0] ? imm[19:0] if branch taken and program size is 64k word or more pc[11:0] ? pc[11:0] + 2 otherwise example l18411: // assume current pc = 18411h. llnk nz, 10h:107h // call the subroutine at 10107h with the current pc saved // in il (il[19:0] ? 18413h) if program size is 64k word or more ret, iret returns from the current subroutine. iret sets ie (sr0[1]) in addition. if the program size is less than 64k word, pc[19:16] is not loaded from hs[19:16]. operation pc[15:0] ? hs[sptr - 2] and sptr ? sptr - 2 (pop stack) if program size is less than 64k word pc[19:0] ? hs[sptr - 2] and sptr ? sptr - 2 (pop stack) if program size is 64k word or more example ret // assume sptr = 3h and hs[1] = 18407h. // the next pc will be 18407h and sptr is set to 1h instruction set s3f b42f 8- 24 lret returns from the current subroutine, using the link register il. if the program size is less than 64k word, pc[19:16] is not loaded from ilx. operation pc[15:0] ? il[15:0] if program size is less tha n 64k word pc[19:0] ? il[19:0] if program size is 64k word or more example lret // assume il = 18407h. // the next instruction to execute is at pc = 18407h // if program size is 64k word or more jp/lnk/call jp/lnk/call instructions are pseudo instructions. if jr/lnks/calls commands (1 word instructions) can access the target address, there is no conditional code in the case of call/lnk and the jp/lnk/call commands are assembled to jr/lnks/calls in linking time or else the jp/lnk/call commands are assembled to ljp/llnk/lcall (2 word instructions) instructions. S3FB42F instruction set 8- 25 bit manipulation instructions bitop adr:8.bs performs a bit operation specified by op on the value in the data memory pointed by adr:8 and stores the result into r3 of current gpr bank or back into memory depending on the value of tf bit. bitop = bits, bitr, bitc, bitt bits: bit set bitr: bit reset bitc: bit complement bitt: bit test (r3 is not touched in this case) bs: bit location specifier, 0 - 7. operation r3 ? dm[00h:adr:8] bitop bs if eid = 0 r3 ? dm[idh:adr:8] bitop bs if eid = 1 (no register transfer for bitt) set the zero (z) bit if the result is 0. example bits 25h.3 // assume eid = 0. set bit 3 of dm[00h:25h] and store the result in r3. bitt 25h.3 // check bit 3 of dm[00h:25h] if eid = 0. bmc/bms clears or sets the tf bit, which is used to determine the destination of bitop instructions. when tf bit is clear, the result of bitop instructions will be stored into r3 (fixed); if the tf bit is set, the result will be written back to memory. operation tf ? 0 (bmc) tf ? 1 (bms) tm gpr, #imm:8 performs and operation on gpr and imm:8 and sets the zero (z) and negative (n) bits. no change in gpr. operation z, n flag ? gpr & #imm:8 bitop gpr.bs performs a bit operation on gpr and stores the result in gpr. since the equivalent functionality can be achieved using or gpr, #imm:8, and gpr, #imm:8, and xor gpr, #imm:8, this instruction type doesn?t have separate op codes. instruction set s3f b42f 8- 26 and sr0, #imm:8/or sr0, #imm:8 sets/resets bits in sr0 and stores the result back into sr0. operation sr0 ? sr0 & #imm:8 sr0 ? sr0 | #imm:8 bank #imm:2 loads sr0[4:3] with #imm[1:0]. operation sr0[4:3] ? #imm[1:0] miscellaneous instruction swap gpr, spr swaps the values in gpr and spr. sr0 and sr1 can not be used for this instruction. no flag is updated, even though the destination is gpr. operation temp ? spr spr ? gpr gpr ? temp example swap r0, idh // assume idh = 00h and r0 = 08h. // after this, idh = 08h and r0 = 00h. push reg saves reg in the stack (pushes reg into stack). reg = gpr, spr operation hs[sptr][7:0] ? reg and sptr ? sptr + 1 example push r0 // assume r0 = 08h and sptr = 2h // then hs[2][7:0] ? 08h and sptr ? 3h S3FB42F instruction set 8- 27 pop reg pops stack into reg. reg = gpr, spr operation reg ? hs[sptr-1][7:0] and sptr ? sptr ? 1 example pop r0 // assume sptr = 3h and hs[2] = 18407h // r0 ? 07h and sptr ? 2h pop pops 2 bytes from the stack and discards the popped data. nop does no work but increase pc by 1. break does nothing and does not increment pc. this instruction is for the debugger only. when this instruction is executed, the processor is locked since pc is not incremented. therefore, this instruction should not be used under any mode other than the debug mode. sys #imm:8 does nothing but increase pc by 1 and generates syscp[7:0] and nsysid signals. cld gpr, imm:8 gpr ? (imm:8) and generates syscp[7:0], ncldid, and ncldwr signals. cld imm:8, gpr (imm:8) ? gpr and generates syscp[7:0], ncldid, and ncldwr signals. cop #imm:12 generates syscp[11:0] and ncopid signals. instruction set s3f b42f 8- 28 ldc loads program memory item into register. operation [tbh:tbl] ? pm[ilx:ilh:ill] (ldc @il) [tbh:tbl] ? pm[ilx:ilh:ill], ill++ (ldc @il+) tbh and tbl are temporary registers to hold the transferred program memory items. these can be accessed only by ld gpr and tbl/tbh instruction. example ld ilx, r1 // assume r1:r2:r3 has the program address to access ld ilh, r2 ld ill, r3 ldc @il // get the program data @(ilx:ilh:ill) into tbh:tbl S3FB42F instruction set 8- 29 pseudo instructions ei/di exceptions enable and disable instruction. operation sr0 ? or sr0,#00000010b (ei) sr0 ? and sr0,#11111101b (di) exceptions are enabled or disabled through this instruction. if there is an ei instruction, the sr0.1 is set and reset, when di instruction. example di ei scf/rcf carry flag set and reset instruction. operation cp r0,r0 (scf) and r0,r0 (rcf) carry flag is set or reset through this instruction. if there is an scf instruction, the sr1.0 is set and reset, when rcf instruction. example scf rcf stop/idle mcu power saving instruction. operation sys #0ah (stop) sys #05h (idle) the stop instruction stops the both cpu clock and system clock and causes the microcontroller to enter stop mode. the idle instruction stops the cpu clock while allowing system clock oscillation to continue. example stop(or idle) nop nop nop instruction set s3f b42f 8- 30 adc ? add with carry format: adc S3FB42F instruction set 8- 31 add ? add format: add instruction set s3f b42f 8- 32 and ? bit-wise and format: and S3FB42F instruction set 8- 33 and sr0 ? bit-wise and with sr0 format: and sr0, #imm:8 operation: sr0 ? sr0 & imm:8 and sr0 performs the bit-wise and operation on the value of sr0 and imm:8 and stores the result in sr0. flags: ? example: given: sr0 = 11000010b nie equ ~02h nie0 equ ~40h nie1 equ ~80h and sr0, #nie | nie0 | nie1 and sr0, #11111101b in the first example, the statement ?and sr0, #nie|nie0|nie1? clear all of bits of the global interrupt, interrupt 0 and interrupt 1. on the contrary, cleared bits can be set to ?1? by instruction ?or sr0, #imm:8?. refer to instruction or sr0 for more detailed explanation about enabling bit. in the second example, the statement ?and sr0, #11111101b? is equal to instruction di, which is disabling interrupt globally. instruction set s3f b42f 8- 34 bank ? gpr bank selection format: bank #imm:2 operation: sr0[4:3] ? imm:2 flags: ? note: for explanation of the calmrisc banked register file and its usage, please refer to chapter 3. example: bank #1 // select register bank 1 ld r0, #11h // bank1?s r0 ? 11h bank #2 // select register bank 2 ld r1, #22h // bank2?s r1 ? 22h S3FB42F instruction set 8- 35 bitc ? bit complement format: bitc adr:8.bs bs: 3-digit bit specifier operation: r3 ? ((adr:8) ^ (2**bs)) if (tf == 0) (adr:8) ? ((adr:8) ^ (2**bs)) if (tf == 1) bitc complements the specified bit of a value read from memory and stores the result in r3 or back into memory, depending on the value of tf. tf is set or clear by bms/bmc instruction. flags: z: set if result is zero. reset if not. note: since the destination register r3 is fixed, it is not specified explicitly. example: given: idh = 01, dm[0180h] = ffh, eid = 1 bmc // tf ? 0 bitc 80h.0 // r3 ? feh, dm[0180h] = ffh bms // tf ? 1 bitc 80h.1 // dm[0180h] ? fdh instruction set s3f b42f 8- 36 bitr ? bit reset format: bitr adr:8.bs bs: 3-digit bit specifier operation: r3 ? ((adr:8) & ((11111111) 2 - (2**bs))) if (tf == 0) (adr:8) ? ((adr:8) & ((11111111) 2 - (2**bs))) if (tf == 1) bitr resets the specified bit of a value read from memory and stores the result in r3 or back into memory, depending on the value of tf. tf is set or clear by bms/bmc instruction. flags: z: set if result is zero. reset if not. note: since the destination register r3 is fixed, it is not specified explicitly. example: given: idh = 01, dm[0180h] = ffh, eid = 1 bmc // tf ? 0 bitr 80h.1 // r3 ? fdh, dm[0180h] = ffh bms // tf ? 1 bitr 80h.2 // dm[0180h] ? fbh S3FB42F instruction set 8- 37 bits ? bit set format: bits adr:8.bs bs: 3-digit bit specifier. operation: r3 ? ((adr:8) | (2**bs)) if (tf == 0) (adr:8) ? ((adr:8) | (2**bs)) if (tf == 1) bits sets the specified bit of a value read from memory and stores the result in r3 or back into memory, depending on the value of tf. tf is set or clear by bms/bmc instruction. flags: z: set if result is zero. reset if not. note: since the destination register r3 is fixed, it is not specified explicitly. example: given: idh = 01, dm[0180h] = f0h, eid = 1 bmc // tf ? 0 bits 80h.1 // r3 ? 0f2h, dm[0180h] = f0h bms // tf ? 1 bits 80h.2 // dm[0180h] ? f4h instruction set s3f b42f 8- 38 bitt ? bit test format: bitt adr:8.bs bs: 3-digit bit specifier. operation: z ? ~((adr:8) & (2**bs)) bitt tests the specified bit of a value read from memory. flags: z: set if result is zero. reset if not. example: given: dm[0080h] = f7h, eid = 0 bitt 80h.3 // z flag is set to ?1? jr z, %1 // jump to label %1 because condition is true. %1 bits 80h.3 nop S3FB42F instruction set 8- 39 bmc/bms ? tf bit clear/set format: bms/bmc operation: bmc/bms clears (sets) the tf bit. tf ? 0 if bmc tf ? 1 if bms tf is a single bit flag which determines the destination of bit operations, such as bitc, bitr, and bits. flags: ? note: bmc/bms are the only instructions that modify the content of the tf bit. example: bms // tf ? 1 bits 81h.1 bmc // tf ? 0 bitr 81h.2 ld r0, r3 instruction set s3f b42f 8- 40 call ? conditional subroutine call (pseudo instruction) format: call cc:4, imm:20 call imm:12 operation: if calls can access the target address and there is no conditional code (cc:4), call command is assembled to calls (1-word instruction) in linking time, else the call is assembled to lcall (2-word ins truction). example: call c, wait // hs[sptr][15:0] ? current pc + 2, sptr ? sptr + 2 // 2-word instruction call 0088h // hs[sptr][15:0] ? current pc + 1, sptr ? sptr + 2 // 1-word instruction wait: nop // address at 0088h nop nop nop nop ret S3FB42F instruction set 8- 41 calls ? call subroutine format: calls imm:12 operation: hs[sptr][15:0] ? current pc + 1, sptr ? sptr + 2 if the program size is less than 64k word. hs[sptr][19:0] ? current pc + 1, sptr ? sptr + 2 if the program size is equal to or over 64k word. pc[11:0] ? imm:12 calls unconditionally calls a subroutine residing at the address specified by imm:12. flags: ? example: calls wait wait: nop nop nop ret because this is a 1-word instruction, the saved returning address on stack is (pc + 1). instruction set s3f b42f 8- 42 cld ? load into coprocessor format: cld imm:8, S3FB42F instruction set 8- 43 cld ? load from coprocessor format: cld instruction set s3f b42f 8- 44 com ? 1's or bit-wise complement format: com S3FB42F instruction set 8- 45 com2 ? 2's complement format: com2 instruction set s3f b42f 8- 46 comc ? bit-wise complement with carry format: comc S3FB42F instruction set 8- 47 cop ? coprocessor format: cop #imm:12 operation: cop passes imm:12 to the coprocessor by generating syscp[11:0] and ncopid signals. flags: ? example: cop #0d01h // generate 1 word instruction code(fd01h) cop #0234h // generate 1 word instruction code(f234h) the above two instructions are equal to statement ?eld a, #1234h? for mac816 operation. the microcode of mac instruction ?eld a, #1234h? is ?fd01f234?, 2-word instruction. in this, code ?f? indicates ?cop? instruction. instruction set s3f b42f 8- 48 cp ? compare format: cp S3FB42F instruction set 8- 49 cpc ? compare with carry format: cpc instruction set s3f b42f 8- 50 dec ? decrement format: dec S3FB42F instruction set 8- 51 decc ? decrement with carry format: decc instruction set s3f b42f 8- 52 di ? disable interrupt (pseudo instruction) format: di operation: disables interrupt globally. it is same as ?and sr0, #0fdh? . di instruction sets bit1 (ie: global interrupt enable) of sr0 register to ?0? flags: ? example: given: sr0 = 03h di // sr0 ? sr0 & 11111101b di instruc tion clears sr0[1] to ?0?, disabling interrupt processing. S3FB42F instruction set 8- 53 ei ? enable interrupt (pseudo instruction) format: ei operation: enables interrupt globally. it is same as ?or sr0, #02h? . ei instruction sets the bit1 (ie: global interrupt enable) of sr0 register to ?1? flags: ? example: given: sr0 = 01h ei // sr0 ? sr0 | 00000010b the statement ?ei? sets the sr0[1] to ?1?, enabling all interrupts. instruction set s3f b42f 8- 54 idle ? idle operation (pseudo instruction) format: idle operation: the idle instruction stops the cpu clock while allowing system clock oscillation to continue. idle mode can be released by an interrupt or reset operation. the idle instruction is a pseudo instruction. it is assembled as ?sys #05h?, and this generates the syscp[7-0] signals. then these signals are decoded and the decoded signals execute the idle operation. flags: ? note: the next instruction of idle instruction is executed, so please use the nop instruction after the idle instruction. example: idle no p nop nop the idle instruction stops the cpu clock but not the system clock. S3FB42F instruction set 8- 55 inc ? increment format: inc instruction set s3f b42f 8- 56 incc ? increment with carry format: incc S3FB42F instruction set 8- 57 iret ? return from interrupt handling format: iret operation: pc ? hs[sptr - 2], sptr ? sptr - 2 iret pops the return address (after interrupt handling) from the hardware stack and assigns it to pc. the ie (i.e., sr0[1]) bit is set to allow further interrupt generation. flags: ? note: the program size (indicated by the np64kw signal) determines which portion of pc is updated. when the program size is less than 64k word, only the lower 16 bits of pc are updated (i.e., pc[15:0] ? hs[sptr ? 2] ) . when the program size is 64k word or more, the action taken is pc[19:0] ? hs[sptr - 2]. example: sf_excep: nop // stack full exception service routine iret instruction set s3f b42f 8- 58 jnzd ? jump not zero with delay slot format: jnzd S3FB42F instruction set 8- 59 jp ? conditional jump (pseudo instruction) format: jp cc:4 imm:20 jp cc:4 imm:9 operation: if jr can access the target address, jp command is assembled to jr (1 word instruction) in linking time, else the jp is assembled to ljp (2 word instruction) instruction. there are 16 different conditions that can be used, as described in table 8-6. example: %1 ld r0, #10h // assume address of label %1 is 020dh jp z, %b1 // address at 0264h jp c, %f2 // address at 0265h %2 ld r1, #20h // assume address of label %2 is 089ch in the above example, the statement ?jp z, %b1? is assembled to jr instruction. assuming that current pc is 0264h and condition is true, next pc is made by pc[11:0] ? pc[11:0] + offset, offset value is ?64h + a9h? without carry. ?a9? means 2?s complement of offset value to jump backward. therefore next pc is 020dh. on the other hand, statement ?jp c, %f2? is assembled to ljp instruction because offset address exceeds the range of imm:9. instruction set s3f b42f 8- 60 jr ? conditional jump relative format: jr cc:4 imm:9 cc:4: 4-bit condition code operation: pc[11:0] ? pc[11:0] + imm:9 if condition is true. imm:9 is a signed number, which is sign- extended to 12 bits when added to pc. there are 16 different conditions that can be used, as described in table 8-6. flags: ? note: unlike ljp, the target address of jr is pc-relative. in the case of jr, imm:9 is added to pc to compute the actual jump address, while ljp directly jumps to imm:20, the target. example: jr z, %1 // assume current pc = 1000h %1 ld r0, r1 // address at 10a5h after the first instruction is executed, next pc has become 10a5h if z flag bit is set to ?1?. the range of the relative address is from +255 to ?256 because imm:9 is signed number. S3FB42F instruction set 8- 61 lcall ? conditional subroutine call format: lcall cc:4, imm:20 operation: hs[sptr][15:0] ? current pc + 2, sptr ? sptr + 2, pc[15:0] ? imm[15:0] if the condition holds and the program size is less than 64k word. hs[sptr][19:0] ? current pc + 2, sptr ? sptr + 2, pc[19:0] ? imm:20 if the condition holds and the program size is equal to or over 64k word. pc[11:0] ? pc[11:0] + 2 otherwise. lcall instruction is used to call a subroutine whose starting address is specified by imm:20. flags: ? example: lcall l1 lcall c, l2 label l1 and l2 can be allocated to the same or other section. because this is a 2-word instruction, the saved returning address on stack is (pc + 2). instruction set s3f b42f 8- 62 ld adr:8 ? load into memory format: ld adr:8, S3FB42F instruction set 8- 63 ld @idm ? load into memory indexed format: ld @idm, instruction set s3f b42f 8- 64 ld ? load register format: ld S3FB42F instruction set 8- 65 ld ? load gpr:bankd, gpr:banks format: ld instruction set s3f b42f 8- 66 ld ? load gpr, tbh/tbl format: ld S3FB42F instruction set 8- 67 ld ? load tbh/tbl, gpr format: ld instruction set s3f b42f 8- 68 ld spr ? load spr format: ld S3FB42F instruction set 8- 69 ld spr0 ? load spr0 immediate format: ld spr0, #imm:8 operation: spr0 ? imm:8 ld spr0 loads an 8-bit immediate value into spr0. flags: ? example: given: eid = 1, idb = 0 (index register bank 0 selection) ld idh, #80h // idh point to page 80h ld idl1, #44h ld idl0, #55h l d sr0, #02h the last instruction set ie (global interrupt enable) bit to ?1?. special register group 1 (spr1) registers are not supported in this addressing mode. instruction set s3f b42f 8- 70 ldc ? load code format: ldc S3FB42F instruction set 8- 71 ljp ? conditional jump format: ljp cc:4, imm:20 cc:4: 4-bit condition code operation: pc[15:0] ? imm[15:0] if condition is true and the program size is less than 64k word. if the program is equal to or larger than 64k word, pc[19:0] ? imm[19:0] as long as the condition is true. there are 16 different conditions that can be used, as described in table 8-6. flags: ? note: ljp cc:4 imm:20 is a 2-word instruction whose immediate field directly specifies the target address of the jump. example: ljp c, %1 // assume current pc = 0812h %1 ld r0, r1 // address at 10a5h after the first instruction is executed, ljp directly jumps to address 10a5h if condition is true. instruction set s3f b42f 8- 72 llnk ? linked subroutine call conditional format: llnk cc:4, imm:20 cc:4: 4-bit condition code operation: if condition is true, il[19:0] ? {pc[19:12], pc[11:0] + 2}. further, when the program is equal to or larger than 64k word, pc[19:0] ? imm[19:0] as long as the condition is true. if the program is smaller than 64k word, pc[15:0] ? imm[15:0]. there are 16 different conditions that can be used, as described in table 8-6. flags: ? note: llnk is used to conditionally to call a subroutine with the return address saved in the link register (il) without stack operation. this is a 2-word instruction. example: llnk z, %1 // address at 005ch, ilx:ilh:ill ? 00:00:5eh nop // address at 005eh %1 ld r0, r1 lret S3FB42F instruction set 8- 73 lnk ? linked subroutine call (pseudo instruction) format: lnk cc:4, imm:20 lnk imm:12 operation: if lnks can access the target address and there is no conditional code (cc:4), lnk command is assembled to lnks (1 word instruction) in linking time, else the lnk is assembled to llnk (2 word instruction). example: lnk z, link1 // equal to ?llnk z, link1? lnk link2 // equal to ?lnks link2? nop link2: nop lret subroutines section code, abs 0a00h subroutines link1: nop lret instruction set s3f b42f 8- 74 lnks ? linked subroutine call format: lnks imm:12 operation: il[19:0] ? {pc[19:12], pc[11:0] + 1} and pc[11:0] ? imm:12 lnks saves the current pc in the link register and jumps to the address specified by imm:12. flags: ? note: lnks is used to call a subroutine with the return address saved in the link register (il) without stack operation. example: lnks link1 // address at 005ch, ilx:ilh:ill ? 00:00:5dh nop // address at 005dh link1: nop lret S3FB42F instruction set 8- 75 lret ? return from linked subroutine call format: lret operation: pc ? il[19:0] lret returns from a subroutine by assigning the saved return address in il to pc. flags: ? example: lnk link1 link1: nop lret ; pc[19:0] ? ilx:ilh:ill instruction set s3f b42f 8- 76 nop ? no operation format: nop operation: no operation. when the instruction nop is executed in a program, no operation occurs. instead, the instruction time is delayed by approximately one machine cycle per each nop instruction encountered. flags: ? example: nop S3FB42F instruction set 8- 77 or ? bit-wise or format: or instruction set s3f b42f 8- 78 or sr0 ? bit-wise or with sr0 format: or sr0, #imm:8 operation: sr0 ? sr0 | imm:8 or sr0 performs the bit-wise or oper ation on sr0 and imm:8 and stores the result in sr0. flags: ? example: given: sr0 = 00000000b eid equ 01h ie equ 02h idb1 equ 04h ie0 equ 40h ie1 equ 80h or sr0, #ie | ie0 | ie1 or sr0, #00000010b in the first example, the statement ?or sr0, #eid|ie|ie0? set global interrupt(ie), interrupt 0(ie0) and interrupt 1(ie1) to ?1? in sr0. on the contrary, enabled bits can be cleared with instruction ?and sr0, #imm:8?. refer to instruction and sr0 for more detailed explanation about disabling bit. in the second example, the statement ?or sr0, #00000010b? is equal to instruction ei, which is enabling interrupt globally. S3FB42F instruction set 8- 79 pop ? pop format: pop operation: sptr ? sptr ? 2 pop decrease sptr by 2. the top two bytes of the hardware stack are therefore invalidated. flags: ? example: given: sptr[5:0] = 001010b pop this pop instruction decrease sptr[5:0] by 2. therefore sptr[5:0] is 001000b. instruction set s3f b42f 8- 80 pop ? pop to register format: pop S3FB42F instruction set 8- 81 push ? push register format: push instruction set s3f b42f 8- 82 ret ? return from subroutine format: ret operation: pc ? hs[sptr - 2], sptr ? sptr ? 2 ret pops an address on the hardware stack into pc so that control returns to the subroutine call site. flags: ? example: given: sptr[5:0] = 001010b calls wait // address at 00120h wait: nop // address at 01000h nop nop nop nop ret after the first instruction calls execution, ?pc+1?, 0121h is loaded to hs[5] and hardware stack pointer sptr[5:0] have 001100b and next pc became 01000h. the instruction ret pops value 0121h on the hardware stack hs[sptr-2] and load to pc then stack pointer sptr[[5:0] became 001010b. S3FB42F instruction set 8- 83 rl ? rotate left format: rl instruction set s3f b42f 8- 84 rlc ? rotate left with carry format: rlc S3FB42F instruction set 8- 85 rr ? rotate right format: rr instruction set s3f b42f 8- 86 rrc ? rotate right with carry format: rrc S3FB42F instruction set 8- 87 sbc ? subtract with carry format: sbc instruction set s3f b42f 8- 88 sl ? shift left format: sl S3FB42F instruction set 8- 89 sla ? shift left arithmetic format: sla |