BLISS Language Reference Manual

Total Page:16

File Type:pdf, Size:1020Kb

BLISS Language Reference Manual BLISS Language Reference Manual Order Number: AA–H275E–TK May 1987 This document is a combined tutorial and reference manual for the BLISS programming language, which consists of the dialects BLISS–16, BLISS–32, and BLISS–36. This language, designed for transportable system-level programming, is primarily intended for knowledgeable users of its target systems: PDP–11, VAX, DECsystem–10, and DECSYSTEM–20. Revision/Update Information: Revision/Update Information: This document supersedes the BLISS Language Guide (Order Number AA– H275D–TK). Revision/Update Information: Operating System and Version: VMS Version 3 or higher TOPS–10 Version 7.01 TOPS–20 Version 5 Revision/Update Information: Software Version: BLISS–16 Version 4 BLISS–32 Version 4.3 BLISS–36 Version 4 Digital Equipment Corporation Maynard, Massachusetts First Printing, October 1978 Revised, January 1980 Revised, January 1982 Revised, January 1983 Revised, May 1987 Digital Equipment Corporation makes no representations that the use of its products in the manner described in this publication will not infringe on existing or future patent rights, nor do the descriptions contained in this publication imply the granting of licenses to make, use, or sell equipment or software in accordance with the description. Possession, use, or copying of the software described in this publication is authorized only pursuant to a valid written license from Digital or an authorized sublicensor. © Digital Equipment Corporation 1978, 1980, 1982, 1983, 1987. All rights reserved. The postpaid Reader’s Comments forms at the end of this document request your critical evaluation to assist in preparing future documentation. The following are trademarks of Digital Equipment Corporation: DEC, DEC/CMS, DEC/MMS, DECnet, DECsystem–10, DECSYSTEM–20, DECUS, DECwriter, DIBOL, EduSystem, IAS, MASSBUS, PDP, PDT, RSTS, RSX, UNIBUS, VAX, VAXcluster, VMS, VT, and the DIGITAL logo. ZK4538 This document is available on CD–ROM. This document was prepared using VAX DOCUMENT Version 2.1. Contents Preface ............................................................ xix 1 Introduction 1.1 BLISS Dialects .............................................. 1–1 1.2 Language Objectives and Characteristics . ....................... 1–2 1.2.1 Design Objectives . ........................................ 1–2 1.2.2 Language Overview ....................................... 1–2 1.3 Program Development ........................................ 1–3 1.4 The Main Features of BLISS . ................................ 1–4 1.4.1 Data . ................................................ 1–4 1.4.2 Memory Addressing ....................................... 1–4 1.4.3 Fetching Values . ........................................ 1–5 1.4.4 Assigning Values . ........................................ 1–5 1.4.5 Expressions ............................................. 1–6 1.4.6 Blocks . ................................................ 1–6 1.4.7 Declarations ............................................. 1–8 1.4.8 Structures .............................................. 1–9 1.4.9 Flow of Control . ........................................ 1–9 1.4.10 Loops . ................................................ 1–10 1.4.11 Binding of Names ........................................ 1–11 1.5 Program Transportability ...................................... 1–11 1.6 Effects of Optimization ........................................ 1–12 1.7 The BLISS Programming System ............................... 1–13 1.7.1 System Components ....................................... 1–13 1.7.2 Constant Expressions ...................................... 1–14 1.8 A Complete Program . ........................................ 1–15 2 Lexical Definitions and Syntax Notation 2.1 Characters and Linemarks ..................................... 2–1 2.1.1 Characters .............................................. 2–1 2.1.2 Linemarks .............................................. 2–2 2.2 Lexemes and Spaces . ........................................ 2–2 2.2.1 Lexemes ................................................ 2–3 2.2.2 Spaces and Comments ..................................... 2–3 2.3 The Separation Rules . ........................................ 2–4 2.4 The Syntax Notation . ........................................ 2–4 2.4.1 Syntactic Rules . ........................................ 2–5 2.4.2 Syntactic Names and Syntactic Literals . ....................... 2–5 2.4.3 Concatenations . ........................................ 2–6 2.4.4 Disjunctions ............................................. 2–6 2.4.5 Replications ............................................. 2–7 2.4.6 Dialectal Differences ...................................... 2–7 iii 3 BLISS Values and Data Representations 3.1 BLISS Values . ............................................ 3–1 3.1.1 Fullword Values .......................................... 3–2 3.1.2 Field Values . ............................................ 3–3 3.1.3 Extending Values ......................................... 3–3 3.2 Data Segments . ............................................ 3–5 3.2.1 Addressable Units and Units per BLISS Value .................. 3–5 3.2.2 Scalars ................................................. 3–6 3.2.3 VECTOR Structures . .................................... 3–8 3.2.4 BITVECTOR Structures .................................... 3–9 3.2.5 BLOCK Structures ........................................ 3–10 3.2.6 BLOCKVECTOR Structures ................................ 3–10 3.2.7 Programmed Structures .................................... 3–11 3.3 Character Sequence Data . .................................... 3–11 3.3.1 General Character Representation ............................ 3–12 3.3.2 Character Sequence Operations . ............................ 3–12 3.3.3 BLISS–16 Character Representation .......................... 3–13 3.3.4 BLISS–32 Character Representation .......................... 3–13 3.3.5 BLISS–36 Character Representation .......................... 3–14 3.4 Storage Organization ......................................... 3–14 3.4.1 The Stack . ............................................ 3–15 3.4.2 The Registers ............................................ 3–15 3.4.3 Storage for a Program Module . ............................ 3–15 4 Primary Expressions 4.1 Primaries .................................................. 4–1 4.1.1 Syntax ................................................. 4–2 4.1.2 Semantics . ............................................ 4–2 4.2 Numeric-Literals ............................................ 4–2 4.2.1 Syntax ................................................. 4–3 4.2.2 Restrictions . ............................................ 4–4 4.2.3 Defaults ................................................ 4–5 4.2.4 Semantics . ............................................ 4–5 4.3 String Literals . ............................................ 4–6 4.3.1 Syntax ................................................. 4–6 4.3.2 Restrictions . ............................................ 4–7 4.3.3 Defaults ................................................ 4–8 4.3.4 Semantics . ............................................ 4–8 4.4 PLITs . .................................................... 4–10 4.4.1 Syntax ................................................. 4–11 4.4.2 Restrictions . ............................................ 4–12 4.4.3 Defaults ................................................ 4–12 4.4.4 Semantics . ............................................ 4–12 4.4.5 Pragmatics . ............................................ 4–13 4.5 Names .................................................... 4–13 4.5.1 Syntax ................................................. 4–13 4.5.2 Restrictions . ............................................ 4–14 4.5.3 Semantics . ............................................ 4–14 4.6 Blocks .................................................... 4–14 4.7 Structure-References ......................................... 4–15 4.8 Routine-Calls . ............................................ 4–15 4.9 Field-References . ............................................ 4–15 4.10 Code Comments . ............................................ 4–15 iv 4.10.1 Syntax . ................................................ 4–16 4.10.2 Semantics ............................................... 4–16 5 Computational Expressions 5.1 Operator-Expressions . ........................................ 5–1 5.1.1 Syntax . ................................................ 5–1 5.1.2 Restrictions ............................................. 5–2 5.1.3 Defaults ................................................ 5–3 5.1.4 Semantics ............................................... 5–4 5.1.4.1 Fetch Expressions ..................................... 5–4 5.1.4.2 Prefix Sign Expressions . ................................ 5–5 5.1.4.3 Shift Expression ....................................... 5–5 5.1.4.4 Arithmetic Expressions . ................................ 5–6 5.1.4.5 Relational Expressions . ................................ 5–7 5.1.4.6 Boolean Expressions . ................................ 5–9 5.1.4.7 Assignment Expressions ................................ 5–10 5.1.5 Pragmatics .............................................. 5–10 5.1.5.1 Explicit Parenthesization ................................ 5–10 5.1.5.2 The Order of Evaluation ................................ 5–11 5.1.5.3 Operations on Field Values in BLISS–16/32 . ............... 5–12 5.2 Executable-Functions
Recommended publications
  • Bit Shifts Bit Operations, Logical Shifts, Arithmetic Shifts, Rotate Shifts
    Why bit operations Assembly languages all provide ways to manipulate individual bits in multi-byte values Some of the coolest “tricks” in assembly rely on Bit Shifts bit operations With only a few instructions one can do a lot very quickly using judicious bit operations And you can do them in almost all high-level ICS312 programming languages! Let’s look at some of the common operations, Machine-Level and starting with shifts Systems Programming logical shifts arithmetic shifts Henri Casanova ([email protected]) rotate shifts Shift Operations Logical Shifts The simplest shifts: bits disappear at one end A shift moves the bits around in some data and zeros appear at the other A shift can be toward the left (i.e., toward the most significant bits), or toward the right (i.e., original byte 1 0 1 1 0 1 0 1 toward the least significant bits) left log. shift 0 1 1 0 1 0 1 0 left log. shift 1 1 0 1 0 1 0 0 left log. shift 1 0 1 0 1 0 0 0 There are two kinds of shifts: right log. shift 0 1 0 1 0 1 0 0 Logical Shifts right log. shift 0 0 1 0 1 0 1 0 Arithmetic Shifts right log. shift 0 0 0 1 0 1 0 1 Logical Shift Instructions Shifts and Numbers Two instructions: shl and shr The common use for shifts: quickly multiply and divide by powers of 2 One specifies by how many bits the data is shifted In decimal, for instance: multiplying 0013 by 10 amounts to doing one left shift to obtain 0130 Either by just passing a constant to the instruction multiplying by 100=102 amounts to doing two left shifts to obtain 1300 Or by using whatever
    [Show full text]
  • A Case Against the GOT' O William a . Wulf, Carnegie-Mellon Universit Y
    A Case Against the GOT' O William A . Wulf, Carnegie-Mellon Universit y ABSTRAC T suggestion to ban the goto appears to have been a part of the computing folklore for several years , It has been proposed, by E . W . Dijkstra and others , to this author's knowledge the suggestion wa s that the goto statement in programming language i s first made in print by Professor E . W . Dijkstra i n a principal culprit in programs which are diffi- a letter to the editor of the _Communications o f cult to understand, modify, and debug . More cor- the ACM in 1968 (1) . rectly, the argument is that it is possible t o In this paper we shall examine the rational e use the goto to synthesize program structures wit h for the elimination of the Soto in programin g these undesirable properties . Not all uses of th e languages, and some of the theoretical and practi- goto are to be considered harmful ; however, it i s cal implications of its (total) elimination . further argued that the "good" uses of the got o fall into one of a small number of specific case s RATIONAL E which may be handled by specific language con- structs . This paper summarizes the arguments i n At one level, the rationale for eliminatin g favor of eliminating the goto statement and som e the poto has already been given in the introduc- of the theoretical and practical implications o f tion . Namely, it is possible to use the goto in a the proposal . manner which obscures the logical structure of a program to a point where it becomes virtually im- KEY WORDS AND PHRASES : programming, programmin g possible to understand (1,3,4), It is not claimed languages, goto-less programming, structured pro- that every use of the goto obscures the logica l grammin g structure of a program ; it is only claimed that i t CR CATEGORIES : 4 .2, 4 .22, 5 .2 4 is possible to use the Soto to fabricate a "rat' s nest" of control flow which has the undesirabl e INTRODUCTION properties mentioned above .
    [Show full text]
  • Does the Seventh Amendment Compel Fact-‐Finding Before
    HAVE WE GONE TOO FAR: DOES THE SEVENTH AMENDMENT COMPEL FACT-FINDING BEFORE REACHING A DECISION ON PATENT- ELIGIBLE SUBJECT MATTER? JESSE D.H. SNYDER* I. INTRODUCTION Something seems amiss. Settled notions of what can be Patenta- ble are changing.1 To complicate matters further, so far, neither the SuPreme Court nor the Federal Circuit has addressed whether the in- quiry into Patent-eliGible subject matter is factual, legal, or both. And while the scoPe of Patentable subject matter is understandably con- strictinG, the end result may not be coterminous with the SuPreme Court’s Guidance in Alice Corporation Party Limited v. CLS Bank.2 Under Alice, which built uPon the Patent-eliGible subject matter frameworks of Prior cases, for those Patent claims that are directed to a Patent- ineligible concePt (e.G., abstract ideas), Patentability turns on whether an “inventive concePt” exists to “‘transform the nature of the claim’ into a Patent-eliGible aPPlication.”3 The lower courts have seized on the Alice holding, inhuming Pa- tents whose subject-matter failures render them invalid as a matter of law. But what if the means adoPted by the lower courts to reach that leGal conclusion also sidestePs certain constitutional guarantees? What if they are simPlifyinG the analysis at a facial level when a more granular investigation is required? What if, at the motion to dismiss staGe, fact-findinG is still required to determine whether a Patent is * 2015-2016 term law clerk to the Honorable Jimmie V. Reyna of the U.S. Court of APPeals for the Federal Circuit. I earned my J.D., summa cum laude, from Texas Wesleyan School of Law and my B.S.
    [Show full text]
  • Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore
    SHRI VAISHNAV VIDYAPEETH VISHWAVIDYALAYA, INDORE Memories are special moments that tell our story SMRITI मृत ALUMNI DIRECTORY 2020 The rising flame epitomises leadership through enlightenment The bright orange colour represents brilliance and colour blue reflects serenity and infinity तमसो मा योतगमय Lead me from darkness to light ABOUT UNIVERSITY Shri Vaishnav Vidyapeeth Vishwavidyalaya is a state private university established under Madhya Pradesh Niji Vishwavidyalaya (Sthapana Avam Sanchalan) Adhiniyam in 2015 at Indore, MP(India). The University has been established with a vision to be a leader in shaping better future for mankind through quality education, training and research. It shall pursue the mission to make a difference in sustaining the growth of global societies by developing socially responsible citizens. Value based education being at the helm, the University offers degree and diploma programs through 13 constituent institutes and schools, besides Faculty of Doctoral Studies and Research. Some of the objectives of the University are as under: • To provide teaching and training in higher education and make provision for research as well as advancement and dissemination of knowledge. • To ensure world class quality in its offerings and create higher levels of intellectual abilities. • To create centres of excellence for research and development for sharing knowledge and its applications. Shri Vaishnav Vidyapeeth Vishwavidyalaya at Indore is a multi-disciplinary university focusing on the needs of various segments of the society. FROM THE DESK OF CHANCELLOR “To emerge as a winner, learn to balance relaxation and action” Shri Vaishnav Vidyapeeth Vishwavidyalaya was conceived as an institution of higher learning for imparting quality education to the young and experienced learners alike.
    [Show full text]
  • A Cross-Platform Programmer's Calculator
    – Independent Work Report Fall, 2015 – A Cross-Platform Programmer’s Calculator Brian Rosenfeld Advisor: Robert Dondero Abstract This paper details the development of the first cross-platform programmer’s calculator. As users of programmer’s calculators, we wanted to address limitations of existing, platform-specific options in order to make a new, better calculator for us and others. And rather than develop for only one- platform, we wanted to make an application that could run on multiple ones, maximizing its reach and utility. From the start, we emphasized software-engineering and human-computer-interaction best practices, prioritizing portability, robustness, and usability. In this paper, we explain the decision to build a Google Chrome Application and illustrate how using the developer-preview Chrome Apps for Mobile Toolchain enabled us to build an application that could also run as native iOS and Android applications [18]. We discuss how we achieved support of signed and unsigned 8, 16, 32, and 64-bit integral types in JavaScript, a language with only one numerical type [15], and we demonstrate how we adapted the user interface for different devices. Lastly, we describe our usability testing and explain how we addressed learnability concerns in a second version. The end result is a user-friendly and versatile calculator that offers value to programmers, students, and educators alike. 1. Introduction This project originated from a conversation with Dr. Dondero in which I expressed an interest in software engineering, and he mentioned a need for a good programmer’s calculator. Dr. Dondero uses a programmer’s calculator while teaching Introduction to Programming Systems at Princeton (COS 217), and he had found that the pre-installed Mac OS X calculator did not handle all of his use cases.
    [Show full text]
  • A Look at Some Compilers MATERIALS from the DRAGON BOOK and WIKIPEDIA MICHAEL WOLLOWSKI
    2/11/20 A Look at some Compilers MATERIALS FROM THE DRAGON BOOK AND WIKIPEDIA MICHAEL WOLLOWSKI EQN oTakes inputs like “E sub 1” and produces commands for text formatter TROFF to produce “E1” 1 2/11/20 EQN EQN oTreating EQN as a language and applying compiler technologies has several benefits: oEase of implementation. oLanguage evolution. In response to user needs 2 2/11/20 Pascal Developed by Nicolas Wirth. Generated machine code for the CDC 6000 series machines To increase portability, the Pascal-P compiler generates P-code for an abstract stack machine. One pass recursive-descent compiler Storage is organized into 4 areas: ◦ Code for procedures ◦ Constants ◦ Stack for activation records ◦ Heap for data allocated by the new operator. Procedures may be nested, hence, activation record for a procedure contains both access and control links. CDC 6000 series The first member of the CDC 6000 series Was the supercomputer CDC 6600, Designed by Seymour Cray and James E. Thornton Introduced in September 1964 Performed up to three million instructions per second, three times faster than the IBM Stretch, the speed champion for the previous couple of years. It remained the fastest machine for five years until the CDC 7600 Was launched. The machine Was Freon refrigerant cooled. Control Data manufactured about 100 machines of this type, selling for $6 to $10 million each. 3 2/11/20 CDC 6000 series By Steve Jurvetson from Menlo Park, USA - Flickr, CC BY 2.0, https://commons.Wikimedia.org/w/index.php?curid=1114605 CDC 205 CDC 205 DKRZ 4 2/11/20 CDC 205 CDC 205 Wiring, davdata.nl Pascal 5 2/11/20 Pascal One of the compiler Writers states about the use of a one-pass compiler: ◦ Easy to implement ◦ Imposes severe restrictions on the quality of the generated code and suffers from relatively high storage requirements.
    [Show full text]
  • Mach-O Programming Topics
    Mach-O Programming Topics Tools > Compiling & Debugging 2006-11-28 subsidiaries in the United States and other Apple Inc. countries. © 2003, 2006 Apple Computer, Inc. Java and all Java-based trademarks are All rights reserved. trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other No part of this publication may be countries. reproduced, stored in a retrieval system, or transmitted, in any form or by any means, PowerPC and and the PowerPC logo are mechanical, electronic, photocopying, trademarks of International Business recording, or otherwise, without prior Machines Corporation, used under license written permission of Apple Inc., with the therefrom. following exceptions: Any person is hereby UNIX is a registered trademark of The Open authorized to store documentation on a Group single computer for personal use only and Simultaneously published in the United to print copies of documentation for States and Canada. personal use provided that the documentation contains Apple’s copyright Even though Apple has reviewed this document, APPLE MAKES NO WARRANTY OR notice. REPRESENTATION, EITHER EXPRESS OR IMPLIED, WITH RESPECT TO THIS The Apple logo is a trademark of Apple Inc. DOCUMENT, ITS QUALITY, ACCURACY, MERCHANTABILITY, OR FITNESS FOR A Use of the “keyboard” Apple logo PARTICULAR PURPOSE. AS A RESULT, THIS (Option-Shift-K) for commercial purposes DOCUMENT IS PROVIDED “AS IS,” AND YOU, THE READER, ARE ASSUMING THE without the prior written consent of Apple ENTIRE RISK AS TO ITS QUALITY AND may constitute trademark infringement and ACCURACY. unfair competition in violation of federal IN NO EVENT WILL APPLE BE LIABLE FOR and state laws.
    [Show full text]
  • Bitwise Operators
    Logical operations ANDORNOTXORAND,OR,NOT,XOR •Loggpical operations are the o perations that have its result as a true or false. • The logical operations can be: • Unary operations that has only one operand (NOT) • ex. NOT operand • Binary operations that has two operands (AND,OR,XOR) • ex. operand 1 AND operand 2 operand 1 OR operand 2 operand 1 XOR operand 2 1 Dr.AbuArqoub Logical operations ANDORNOTXORAND,OR,NOT,XOR • Operands of logical operations can be: - operands that have values true or false - operands that have binary digits 0 or 1. (in this case the operations called bitwise operations). • In computer programming ,a bitwise operation operates on one or two bit patterns or binary numerals at the level of their individual bits. 2 Dr.AbuArqoub Truth tables • The following tables (truth tables ) that shows the result of logical operations that operates on values true, false. x y Z=x AND y x y Z=x OR y F F F F F F F T F F T T T F F T F T T T T T T T x y Z=x XOR y x NOT X F F F F T F T T T F T F T T T F 3 Dr.AbuArqoub Bitwise Operations • In computer programming ,a bitwise operation operates on one or two bit patterns or binary numerals at the level of their individual bits. • Bitwise operators • NOT • The bitwise NOT, or complement, is an unary operation that performs logical negation on each bit, forming the ones' complement of the given binary value.
    [Show full text]
  • Steps Toward a Compiler for BLISS-360
    STEPS TOWARD A COMPILER FOR BLISS-360 Richard Charles Bahler HffiE 1 ihshL postgraduate school Monterey, California THESIS - STEPS TOWARD A COMPILER FOR BLISS- 360 by Richard Charles Bahler Thesis Advisor: Gary A . Kildall June 1972 Appiov&d ^oh. pubtic k.qA.qju> e; diA&iibntion untimittd. Steps Toward a Compiler for BLISS-360 by Richard Charles Bahler Major, United States Marine Corps Reserve B.A., University of Rochester, 1955 Submitted in partial fulfillment of the requirements for the degree of MASTER OF SCIENCE IN COMPUTER SCIENCE from the NAVAL POSTGRADUATE SCHOOL June 1972 ABSTRACT The design of a compiler for the IBM S/360 systems implementation language BLISS-360, a modification of the PDP-10 language BLISS- 10, is described. The compiler has a two-pass structure that is based upon the XPL Compiler Generator System. The first of these passes, which uses the XPL prototype compiler Skeleton,, is examined in some detail. Funda- mental data structures are described for this pass, including a constant table, a dictionary for variable definitions, and an intermediate language table to retain the source program structure and semantics. Modifications which allow the Skeleton compiler to perform a syntax analysis of BLISS- 360 programs are discussed and demonstrated. General requirements are defined for the functions to be performed by the second pass, including machine language code generation from the intermediate language, storage allocation and building program interface linkage. TABLE OF CONTENTS I. INTRODUCTION 9 A. PROJECT GOAL 9 B. THESIS OBJECTIVES 9 II. A BLISS-360 COMPILER — POSSIBLE APPROACHES 11 A. REQUIREMENTS OF THE COMPILER 11 B.
    [Show full text]
  • Bits, Bytes, and Integers Today: Bits, Bytes, and Integers
    Bits, Bytes, and Integers Today: Bits, Bytes, and Integers Representing information as bits Bit-level manipulations Integers . Representation: unsigned and signed . Conversion, casting . Expanding, truncating . Addition, negation, multiplication, shifting . Summary Representations in memory, pointers, strings Everything is bits Each bit is 0 or 1 By encoding/interpreting sets of bits in various ways . Computers determine what to do (instructions) . … and represent and manipulate numbers, sets, strings, etc… Why bits? Electronic Implementation . Easy to store with bistable elements . Reliably transmitted on noisy and inaccurate wires 0 1 0 1.1V 0.9V 0.2V 0.0V For example, can count in binary Base 2 Number Representation . Represent 1521310 as 111011011011012 . Represent 1.2010 as 1.0011001100110011[0011]…2 4 13 . Represent 1.5213 X 10 as 1.11011011011012 X 2 Encoding Byte Values Byte = 8 bits . Binary 000000002 to 111111112 0 0 0000 . Decimal: 010 to 25510 1 1 0001 2 2 0010 . Hexadecimal 0016 to FF16 3 3 0011 . 4 4 0100 Base 16 number representation 5 5 0101 . Use characters ‘0’ to ‘9’ and ‘A’ to ‘F’ 6 6 0110 7 7 0111 . Write FA1D37B16 in C as 8 8 1000 – 0xFA1D37B 9 9 1001 A 10 1010 – 0xfa1d37b B 11 1011 C 12 1100 D 13 1101 E 14 1110 F 15 1111 Example Data Representations C Data Type Typical 32-bit Typical 64-bit x86-64 char 1 1 1 short 2 2 2 int 4 4 4 long 4 8 8 float 4 4 4 double 8 8 8 long double − − 10/16 pointer 4 8 8 Today: Bits, Bytes, and Integers Representing information as bits Bit-level manipulations Integers .
    [Show full text]
  • Integer Arithmetic and Undefined Behavior in C Brad Karp UCL Computer Science
    Carnegie Mellon Integer Arithmetic and Undefined Behavior in C Brad Karp UCL Computer Science CS 3007 23rd January 2018 (lecture notes derived from material from Eddie Kohler, John Regehr, Phil Gibbons, Randy Bryant, and Dave O’Hallaron) 1 Carnegie Mellon Outline: Integer Arithmetic and Undefined Behavior in C ¢ C primitive data types ¢ C integer arithmetic § Unsigned and signed (two’s complement) representations § Maximum and minimum values; conversions and casts § Perils of C integer arithmetic, unsigned and especially signed ¢ Undefined behavior (UB) in C § As defined in the C99 language standard § Consequences for program behavior § Consequences for compiler and optimizer behavior § Examples § Prevalence of UB in real-world Linux application-level code ¢ Recommendations for defensive programming in C 2 Carnegie Mellon Example Data Representations C Data Type Typical 32-bit Typical 64-bit x86-64 char 1 1 1 signed short (default) 2 2 2 and int 4 4 4 unsigned variants long 4 8 8 float 4 4 4 double 8 8 8 pointer 4 8 8 3 Carnegie Mellon Portable C types with Fixed Sizes C Data Type all archs {u}int8_t 1 {u}int16_t 2 {u}int32_t 4 {u}int64_t 8 uintptr_t 4 or 8 Type definitions available in #include <stdint.h> 4 Carnegie Mellon Shift Operations ¢ Left Shift: x << y Argument x 01100010 § Shift bit-vector x left y positions << 3 00010000 – Throw away extra bits on left Log. >> 2 00011000 § Fill with 0’s on right Arith. >> 2 00011000 ¢ Right Shift: x >> y § Shift bit-vector x right y positions Argument 10100010 § Throw away extra bits on right x § Logical shift << 3 00010000 § Fill with 0’s on left Log.
    [Show full text]
  • Episode 7.03 – Coding Bitwise Operations
    Episode 7.03 – Coding Bitwise Operations Welcome to the Geek Author series on Computer Organization and Design Fundamentals. I’m David Tarnoff, and in this series, we are working our way through the topics of Computer Organization, Computer Architecture, Digital Design, and Embedded System Design. If you’re interested in the inner workings of a computer, then you’re in the right place. The only background you’ll need for this series is an understanding of integer math, and if possible, a little experience with a programming language such as Java. And one more thing. This episode has direct consequences for our code. You can find coding examples on the episode worksheet, a link to which can be found on the transcript page at intermation.com. Way back in Episode 2.2 – Unsigned Binary Conversion, we introduced three operators that allow us to manipulate integers at the bit level: the logical shift left (represented with two adjacent less-than operators, <<), the arithmetic shift right (represented with two adjacent greater-than operators, >>), and the logical shift right (represented with three adjacent greater-than operators, >>>). These special operators allow us to take all of the bits in a binary integer and move them left or right by a specified number of bit positions. The syntax of all three of these operators is to place the integer we wish to shift on the left side of the operator and the number of bits we wish to shift it by on the right side of the operator. In that episode, we introduced these operators to show how bit shifts could take the place of multiplication or division by powers of two.
    [Show full text]