200 likes | 276 Vues
16 bit vs. 32 bit programming. Course: BSCS-471 Instructor: Dr. Rabia Riaz. 16 bit. In computer architecture, 16-bit integers, memory addresses, or other data units are those that are at most 16 bits (2 octets) wide.
E N D
16 bit vs. 32 bit programming Course: BSCS-471 Instructor: Dr. Rabia Riaz
16 bit • In computer architecture, 16-bit integers, memory addresses, or other data units are those that are at most 16 bits (2 octets) wide. • Also, 16-bit CPU and ALU architectures are those that are based on registers, address buses, or data buses of that size. 16-bit is also a term given to a generation of computers in which 16-bit processors were the norm..
16-bit architecture • Prominent 16-bit processors include the PDP-11, Intel 8086, Intel 80286 and the WDC 65C816. The Intel 8088 was program-compatible with the Intel 8086, and was 16-bit in that its registers were 16 bits long and arithmetic instructions, even though its external bus was 8 bits wide. Other notable 16-bit processors include the Texas Instruments TMS9900 and the Zilog Z8000. • A 16-bit integer can store 216 (or 65536) unique values. In an unsigned representation, these values are the integers between 0 and 65535; using two's complement, possible values range from −32768 to 32767. Hence, a processor with 16-bit memory addresses can directly access 64 KB of byte-addressable memory. • 16-bit processors have been almost entirely supplanted in the personal computer industry, but remain in use in a wide variety of embedded applications. For example the 16-bit XAP processor is used in many ASICs.
16-bit file format • A 16-bit file format is a binary file format for which each data element is defined on 16 bits (or 2 Bytes). • An example of such a format is UTF-16 and the Windows Metafile Format
16-bit memory models • Similar to 64-bit's data models, the 16-bit Intel architecture allows for different memory models—ways to access a particular memory location. The reason for using a specific memory model is the size of the assembler instructions or required storage for pointers.
TypeWidth Characteristics • Compilers of the 16-bit era generally had the following typewidth characteristic: • “Tiny” • Code and data will be in the same segment (especially, the registers CS,DS,ES,SS will point to the same segment); “near” pointers are always used. Code, data and stack together cannot exceed 64K. • “Small” • Code and data will be in different segments, and “near” pointers are always used. There will be 64K of space for code and 64K for data/stack. • “Medium” • Code pointers will use “far” pointers, enabling access to 1MB. Data pointers remain to be of the “near” type. • “Compact” • Data pointers will use “far” and code will use “near” pointers. • “Large”/“Huge” • Code and data pointers will be “far”
32-bit • In computer architecture, 32-bit integers, memory addresses, or other data units are those that are at most 32 bits (4 octets) wide. Also, 32-bit CPU and ALU architectures are those that are based on registers, address buses, or data buses of that size. 32-bit is also a term given to a generation of computers in which 32-bit processors were the norm. • The range of integer values that can be stored in 32 bits is 0 through 4,294,967,295 or −2,147,483,648 through 2,147,483,647 using two's complement encoding. Hence, a processor with 32-bit memory addresses can directly access 4 GB of byte-addressable memory. • The external address and data buses are often wider than 32 bits but both of these are stored and manipulated internally in the processor as 32-bit quantities. For example, the Pentium Pro processor is a 32-bit machine, but the external address bus is 36 bits wide, and the external data bus is 64 bits wide.
32 bit Architecture • Prominent 32-bit instruction set architectures include the IBM System/360, the DEC VAX, the ARM, the MIPS, and the Intel IA-32.
32-bit Programming • To begin the explanation it helps to have a clear understanding of what a BIT actually is. A BIT is the smallest unit of computer information. A BIT contains either a 0 or a 1. The common PC user will never see the contents of a BIT. Eight BITs make one BYTE. One BYTE is equivalent to one character, either alphabetic, numeric, or symbol. • The difference between 16-bit and 32-bit programming lies in how much data the program can process in one operation.
Memory Model • Most modern memory models fall into one of three categories: • Flat memory model • Paged memory model • Segmented memory model
Flat Memory Model • Flat memorymodel or linear memory model refers to a memory addressing paradigm in low-level software design such that the CPU can directly (and sequentially/linearly) address all of the available memory locations without having to resort to any sort of memory segmentation or paging schemes. • Memory management and logical-to-physical address translation can still be implemented on top of a flat memory model in order to facilitate the operating system's functionality, resource protection, multitasking or to increase the memory capacity beyond the limits imposed by the processor's physical address space, but the key feature of a flat memory model is that the entire memory space is linear, sequential and contiguous from address zero to MaxBytes-1.
Flat Memory Model • Memory management is therefore optional; it is neither necessary, nor dictated by the CPU architecture: • In a simple controller, or in a single tasking embedded application, where memory management is not needed nor desirable, the flat memory model is the most appropriate, because it provides the simplest interface from the programmer's point of view, with direct access to all memory locations and minimum design complexity • In a general purpose computer system, which requires multitasking, resource allocation and protection, the flat memory system must be augmented by some memory management scheme, which is typically implemented through a combination of dedicated hardware (inside or outside the CPU) and software built into the operating system. The flat memory model (at the physical addressing level) still provides the greatest flexibility for implementing this type of memory management
Comparison of Memory Models • Flat Memory Model • Simple interface for programmers, clean design • Greatest flexibility • Minimum hardware and CPU real estate for simple controller applications • Maximum execution speed • Not suitable for general computing or multitasking operating systems, unless enhanced with additional memory management hardware/software; but this is almost always the case in modern CISC processors, which implement advanced memory management and protection technology over a flat memory model
Comparison of Memory Models • Paged Memory Model • Suitable for multitasking, general operating system design, resource protection and allocation • Suitable for virtual memory implementation • More CPU real estate, somewhat lower speed • More complex to program • Rigid page boundaries, not always the most memory efficient
Comparison of Memory Models • Segmented Memory Model • Similar to paged memory, but paging is achieved by the implicit addition of two relatively shifted registers: segment:offset • Variable page boundaries, more efficient and flexible than the paged memory model • Quite complex and awkward from a programmer's point of view • More difficult for compilers • Pages can overlap / poor resource protection and isolation • Many to one address translation correspondence: Many segment:offset combinations resolve to the same physical address • Greater chance of programming errors • Implemented in original Intel 8086, 8088, 80186, 80286 and supported by 80386 and all subsequent x86 machines through to present day Pentium and Core 2 proc
32 bit Flat Memory model • program written in native 32 bit Windows format is created in what is called FLAT memory model that has a single segment, which contains both code and data. Such programs must be run on a 80386 or higher processor. • Differing from earlier 16-bit code that used combined segment and offset addressing with a 64 Kb segment limit, FLAT memory model works only in offsets and has a range of 4 Gigabytes. This makes assembly code easier to write and the compiled (assembled) code is generally a lot faster than the equivalent 16-bit code. • All segment registers are automatically set to the same value with the flat memory model. This means that segment / offset addressing must NOT be used in 32-bit programs that run in 32-bit Windows operating systems. • For programmers who have written code in DOS, a 32-bit Windows PE (executable) file is similar in some respects to a DOS COM file - they have a single segment that can contain both code and data and they both work directly in offsets. That is, neither uses segment / offset addressing. • Flat-model assembler code defaults to NEAR code addressing and NEAR data addressing within the range of 4 gigabytes. • The FS and GS segment registers are rarely (if ever) used in application programs but may be used in some instances by the operating system itself.