Advantages and Pitfalls of Moving from an 8 Bit System to 32 Bit Architectures
Total Page:16
File Type:pdf, Size:1020Kb
CORE Metadata, citation and similar papers at core.ac.uk Provided by Archive Ouverte en Sciences de l'Information et de la Communication Advantages and Pitfalls of Moving from an 8 bit System to 32 bit Architectures. David Kerr-Munslow To cite this version: David Kerr-Munslow. Advantages and Pitfalls of Moving from an 8 bit System to 32 bit Architectures.. Embedded Real Time Software and Systems (ERTS2010), May 2010, Toulouse, France. hal-02263470 HAL Id: hal-02263470 https://hal.archives-ouvertes.fr/hal-02263470 Submitted on 4 Aug 2019 HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. Advantages and Pitfalls of Moving from an 8 bit System to 32 bit Architectures. David Kerr-Munslow[1]. 1: Cortus S.A., Le Génésis, 97 rue de Freyr, 34000 Montpellier, France Abstract: We explore the implications of bus width notably: • Ease of Programming This paper explores the considerations of designers of embedded systems when they come to choosing • Code Density the bit width of the embedded CPU architecture, • Performance especially in the domain of System on Chip designs. • Real Time Considerations Two typical architectures are compared and contrasted, one 8 bit and the other 32 bits, the 8051 • Core Size and the Cortus APS3. • Power Consumption Embedded systems are a designed with a number of • Porting constraints not found in other computer systems. In These analyses and measurements lead to the addition they are also expected to give real-time conclusion that questions the assumption that there responses, often with limited resources. is still a niche for the 8-bit microprocessor core. This Received ideas are explored and evaluated in the is especially evident in the SoC arena, but also for light of benchmarks and concrete examples. the microcontroller and FPGA sectors. Attention is paid to modern implementation and 2. Ease of Programming programming methodologies. The most significant development cost of most Issues such as power consumption, code density, systems nowadays is that of software development suitability for real time systems, ease of software [3]. Therefore it is necessary to pay attention to the development are discussed. implications of the architecture choice on software development costs. Keywords: CPU Architecture, bus width, SoC, microcontroller, processor, CPU Most program development nowadays is done in high level languages, and currently in the embedded 1. Introduction world that generally means C and sometimes C++. In this paper we explore the challenges and Most young engineers have graduated with misconceptions involved in processor architecture experience of C and C++ from their University selection for embedded systems. We concentrate on courses, with perhaps only a minimal exposure to the design choices currently in front of system some assembly language programming. Increasingly designers. The key choice is frequently the bus width the knowledge and practice of low level interaction of the architecture. There are a number of with hardware and assembly language programming advantages and a few pitfalls associated with is becoming a specialised skill. choosing a 32 bit architecture over an 8 bit CPU. Features of C Two representative processors were chosen, the 8051 which remains a very popular microcontroller The C programming language was initially conceived architecture, and is popular in SoC designs and the for developing system software, for mini computers Cortus APS3 which is a member of a new generation [4]. There are certain assumptions made about the of 32 bit processor architectures. The APS3 is underlying hardware by the C language. These are: particularly appropriate as it was specifically • Byte addressable memory designed to correspond to the needs of embedded • Integers and pointers of the same size systems being designed at the moment. • Single address space • Stack and heap C/C++ compilers are available for the vast majority of processors, though sometimes not without concession to certain architectural features. Page 1/8 Impact of Architecture The architecture assumptions implicit in the C language have an impact upon the ease of implementation for a specific architecture. Most implementations of the C language rely on the presence of a stack, and use this stack not only for parameter passing and return address storage, but also for automatic variables. This use of the stack gives lexical scope to automatic variables, at least Figure 1: 8051 Address Spaces implicitly. Processors that have a limited stack space must implement another mechanism for the short term Figure 1 shows the various address spaces of the storage of local variables. For instance the internal 8051, certain spaces are only accessible either by stack of the 8051 is 128 bytes, and is used for direct addressing modes, or by indirect addressing subroutine and interrupt returns. Stack overflow is modes [2, 1-6]. This aspect of many 8 bit CPUs with unsignalled and can result in hard to reproduce multiple address spaces, for program, for data, for crashes when nested interrupts exceed the stack I/O requiring different access techniques, frequently depth, this is something to which the author can requires an extension of the C language is to attest! manipulate data in these spaces. The popular C compiler for the 8051, SDCC, stores Here there is a clear advantage of 32 bit local variables in general RAM, and lexical scope architectures which naturally address 4 Gbytes. collisions become an issue. This makes re-entrant 3. Code Density functions difficult to implement, and the use of library functions within an interrupt handler potentially Code density is the measure of how much memory treacherous. Recursion is clearly not possible. is required to store the program to perform a task. Pointer arithmetic Importance of Code Density The assumption that memory is a linear array of Code density influences the following factors: storage cells, permits, and even encourages, the • Consumption of the memories manipulation of data structures using explicit pointer • Execution speed arithmetic. In embedded systems where speed is • more prized over elegance this is even more the On-chip vs off-chip memory placement case. This is exacerbated by the treatment of arrays Clearly power consumption of memories is and pointers as aspects of the same language proportional to their size. Equally the number of feature by C. address bits used influences the routing and bus In 8 bit CPUs the addresses are often 16 bit values, capacitance and therefore the drive strength however the natural integer size is 8 bits. This issue required. is often palliated by special index registers and The number of fetches that are required directly addressing modes in the CPU. However it is difficult influences the execution speed, the fewer memory for a compiler to take full advantage of these accesses required to read the program into the CPU resources. the quicker and more efficiently the program can be executed. Address Space One key aspect in SoC design is whether the The size of the address space is a critical issue. memories are placed on-chip or off chip. On-chip Most 8 bit CPUs can directly access 64Kbytes of memory tends to be more limited in size, off-chip address space. Modern embedded systems often memory is bigger, however I/O pins must be have easily over 64 Kbytes of program code, and dedicated to accessing this memory. This can require complex bank switching schemes. This significantly increase the cost of packaging. makes interrupts and subroutine access complex, There is also an impact on power consumption, I/O and potentially error prone. Convoluted schemes buffers required to drive external pins consume must be created to ensure that library routines are considerably more power than the internal buffers always available in the address space. required to access on-chip memories. Page 2/8 A Practical Example: FreeRTOS give broadly useful indications. The performance measures for the 8051, and enhanced 8051 and the FreeRTOS is an open source real time operating APS3 show significant performance advantages for system. It has the advantage of being small, the 32 bit architecture. lightweight and available freely as source code. Ports are available for a number of processor architectures Architecture “Performance” The Core FreeRTOS kernel was compiled for the 8051 0.026 DMIPS/MHz 8051 and for the Cortus APS3. Enhanced 8051 0.296 DMIPS/MHz APS3 0.85 DMIPS/MHz Architecture .text Table 3: Performance 8051 (SDCC) 26007 bytes APS3 (GCC) 11084 bytes The significance of the measurements shown in Table 1: Code size for FreeRTOS Table 3 is that the 32 bit architecture manages to do significantly more useful work per clock cycle than The same options and demo code were chosen. the 8051 [5]. This means that more work can be A further analysis was made of the resulting done in a given unit of time (at the same clock assembly code to determine the instruction length frequency), or the same amount of work can be mix. spread over a longer period (at a lower clock frequency). Architecture 8 bits 16 bits 24 bits 32 bits Register Set 8051 37% 48% 15% — The register set has a significant impact upon the APS3 — 56% — 44% ability of a compiler to generate efficient code, and also the suitability of the processor for handling time Table 2: Instruction Mix for FreeRTOS critical interrupts without large quantities of Table 1 shows that the 32 bit APS3 architecture is overhead.