1 Introduction to C Programming Levels Programming Language: Syntax

Total Page:16

File Type:pdf, Size:1020Kb

1 Introduction to C Programming Levels Programming Language: Syntax Programming Levels Algorithm level Application Scripting Interpreted Languages Languages Or Compiled High-Level (Java, C#) (Perl, Python, VB) Languages System Programming Languages Introduction to C (C and C++) Compilation Assembly Language (x86, PowerPC, SPARC, MIPS) Low-Level Assembly Languages Machine Langgguage (x86, PowerPC, SPARC, MIPS) Based on slides © McGraw-Hill ISA level Additional material © 2004/2005 Lewis/Martin Hardware Modified by Diana Palsetia (Application-Specific Integrated Circuits or ASICs) CIT 593 2 Programming Language: Syntax Programming Language Semantics Syntax is the grammar of the language When the computer carries out your instructions (program) Running or Executing a program Analogous to rules in English Language ¾Missin g a peri od a fte r se nt en ce Semantics is the meaning of the program ¾Rules using verbs, nouns etc.. We learn the semantics after we run or execute the program Basically we observe the output Most languages provide syntax check errors After the executing program, the semantics of the program (Interprets/Compilers) may or may be correct ¾Syntax error messages may be helpful ¾Often, they are not Semantic errors cause your answers to be wrong ¾You gain experience with error messages after a while You may or may not get error messages ¾ E.g. Error Message – Dividing a number by zero If your program is not doing what you want it to do, though it runs, the error is semantic CIT 593 3 CIT 593 4 1 C Programs are Compiled Compilation Process C Entire mechanism is usually called the compiler Source and Header Files (text file containing hello.c Preprocessor C source code) Acts upon C preprocessor directives “Source-level” transformations C Preprocessor ¾ Output is still C Compiler (text file containing Source Code hello.s assembler source code) Analysis Compiler Symbol Table Generates object file Target Code Synthesis ¾ Machine instructions (binaries) Library hello Linker (a.out) (binary executable file Linker Object Files Containing machine code ) Combine object files (including libraries) into executable image Executable We will use the GNU gcc compiler (v3.0 and higher) Image CIT 593 5 CIT 593 6 Comments in C Basic C Elements Variables Begins with /* and ends with */ A data item upon which the programmer performs an operation A named space in memory Can span multiple lines E.g. z, counter Operators Predefined actions performed on data items Begins with // and ends with “end of line” E.g. *, +, /, ||, |, && Single-line comment Expressions ¾E.g. //This is a comment Operators combined with variables/literals to form expressions E.g. x * y Introduced in C++, later back-ported to C Statements Compiling with ansi standards, gives error A defined behavior Constitutes a unit of work for high-level language Ends with a semicolon. E.g. z = x * y; Why use comments ? Functions Help readers understand programs better Named group of statements Provides modularity to program Enforces, DRY principle (Do not Repeat Yourself) CIT 593 7 CIT 593 8 2 C program structure Variable Properties int main(){ Identifier: variable name /* code goes here Type: how data is interpreted, and how much space it */ needs return 0; } Every C program must the above format to develop Later we will discuss: application program(s) Scope: is the region of the program in which the variable is One of files must contain above structure alive and accessible ¾ main is a special function in C ¾ similar to Java’s main method Storage: how C compiler allocates storage and whether or Starting point for every program not the variable loses its value when the block that All C programs start and finish execution in the main contains it has completed execution Note: int main(int argc, char **argv) – main function can also take arguments like in Java CIT 593 9 CIT 593 10 Identifier: Variable Names Identifier Examples Any combination of letters, numbers, and Legal underscore (_) i wordsPerSecond same identifier words_per_ second Case sensitive _green "sum" is different than "Sum" aReally_longName_moreThan31chars aReally_longName_moreThan31characters Cannot begin with a number Usually, variables beginning with underscore Illegal are used only in special library routines 10sdigit ten'sdigit Only first 31 characters are definitely used done? reserved keyword Implementations can consider more characters if they like double CIT 593 11 CIT 593 12 3 Types Additional to Data Type C has several basic data types Literal int integer (at least 16 bits, commonly 32 bits) Values we write in a conventional form whose value is long integer (at least 32 bits) obvious float floating point (at least 32 bits) double floating point (commonly 64 bits) char character (at least 8 bits) Constant Exact size can vary, depending on processor Variable whose values do not change during the int is supposed to be "natural" integer size execution of the program ¾ 32 bits for most modern processors This done by appending “const” before the type So how do I know the size? ¾ Use method called sizeof. E.g. sizeof(int), returns answer in bytes Signed vs. unsigned: Symbol Default is 2’s complement signed integers Like constants but is preprocessor directive Use “unsigned” keyword for unsigned numbers CIT 593 13 CIT 593 14 Literals Constants vs. Symbol Integer #define RADIUS 15.0 123 /* decimal */ -123 symbol 0x123 /* hexadecimal */ int main(){ const dou ble PI = 3. 14159; Floating point double area; constant literal 6.023 double circum; 6.023e23 /* 6.023 x 1023 */ 5E12 /* 5.0 x 1012 */ area = PI * RADIUS * RADIUS; Character circum = 2 * PI * RADIUS; 'c' return 0; '\n' /* newline */ } '\xA' /* ASCII 10 (0xA) */ CIT 593 15 CIT 593 16 4 Symbol is C Preprocessor Directive Expression Symbol start with #define Expression Must go before the “main function syntax” Any combination of variables, constants, operators, and function calls Every expression has a type, derived from the types Example: #define RADIUS 15.0 of its components (according to C typing rules) Before compiling, replace all instances of the string “RADIUS“ in the code with the string “15.0" Examples: Also known as a macro area = PI * RADIUS * RADIUS; Used for values that won't change during execution, but might change if the program is reused. (Must counter >= STOP recompile.) x + sqrt(y) x & z + 3 || 9 - w-- % 6 CIT 593 17 CIT 593 18 Statement Operators Expresses a complete unit of work Three things to know about each operator Executed in sequential order (1) Function What does it do? Simple statement ends with semicolon (note: “;” is nottiC)t a comment in C) (2) Precedence z = x * y; /* assign product to z */ In which order are operators combined? Example: y = y + 1; /* update y */ "a * b + c * d" is the same as "(a * b) + (c * d)" ; /* null statement */ because multiply (*) has a higher precedence than addition (+) Compound statement formed with braces (3) Associativity Syntactically equivalent to a simple statement In which order are operators of the same precedence combined? Example: { z = x * y; y = y + 1; } "a - b - c" is the same as "(a - b) - c" because add/sub associate left-to-right CIT 593 19 CIT 593 20 5 Assignment Operator Assignment Operator (contd..) Changes the value of a variable All expressions evaluate to a value Even ones with the assignment operator e.g. y = x = 3 x = x + 4; For assignment, the result is the value assigned Usually (but not always) the value of the right-hand 1. Evaluate right-hand side. side ¾Type conversion might make assigned value 2. Set value of left-hand side variable to result. different than computed value e.g. int x = 15.6/3 = 5 Assigggnment associates right to left. y = x = 3; y gets the value 3, because (x = 3) evaluates to the value 3 y = (x = 3); CIT 593 21 CIT 593 22 Arithmetic Operators Arithmetic Expressions If mixed types, smaller type is "promoted" to larger Symbol Operation Usage Precedence Assoc Example: x + 4.3 * multiply x * y 6l-to-r if x is int, converted to double and result is double divide 6l-to-r / x / y Integer division -- fraction is dropped % modulo x % y 6l-to-r Example: x / 3 + addition x + y 7l-to-r if x is int and x=5, result is 1 (not 1.666666...) - subtraction x - y 7l-to-r Storing mixed type expression values int x = 45/7.1; All associate left to right C compiler will do automatic down grade if storage is small. Java compiler will complain. * /%/ % have higher precedence than + - Example Modulo -- result is remainder 2 + 3 * 4 vs. (2 + 3) * 4 Example: x % 3 if x is int and x=5, result is 2 2 * 4 % 5 CIT 593 23 CIT 593 24 6 Relational Operators Logical Operators Symbol Operation Usage Precedence Assoc Symbol Operation Usage Precedence Assoc > greater than x > y 9l-to-r ! logical NOT !x 4 r-to-l logical AND 14 l-to-r >= greater than or equal x >= y 9l-to-r && x && y || logical OR x||yx || y 15 l-to-r < less than x < y 9l-to-r <= less than or equal x <= y 9l-to-r Logical Operator is different from bitwise operators == equal x == y 10 l-to-r Treats entire variable (or value) as TRUE (non-zero), or != not equal x != y 10 l-to-r FALSE (zero) EgE.g. 1&&81 && 8 = 1 (True && True = True) Result is non-zero (TRUE) or zero (FALSE) CIT 593 25 CIT 593 26 Relational and Logical Usage Bitwise Operators Typically used to construct conditions Symbol Operation Usage Precedence Assoc Ultimately conditional will result in TRUE or FALSE ~ bitwise NOT ~x 4 r-to-l Note that see has no Boolean type << left shift x << y 8l-to-r ¾ Outcome is zero or non-zero (i.e.
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]
  • Glibc and System Calls Documentation Release 1.0
    Glibc and System Calls Documentation Release 1.0 Rishi Agrawal <[email protected]> Dec 28, 2017 Contents 1 Introduction 1 1.1 Acknowledgements...........................................1 2 Basics of a Linux System 3 2.1 Introduction...............................................3 2.2 Programs and Compilation........................................3 2.3 Libraries.................................................7 2.4 System Calls...............................................7 2.5 Kernel.................................................. 10 2.6 Conclusion................................................ 10 2.7 References................................................ 11 3 Working with glibc 13 3.1 Introduction............................................... 13 3.2 Why this chapter............................................. 13 3.3 What is glibc .............................................. 13 3.4 Download and extract glibc ...................................... 14 3.5 Walkthrough glibc ........................................... 14 3.6 Reading some functions of glibc ................................... 17 3.7 Compiling and installing glibc .................................... 18 3.8 Using new glibc ............................................ 21 3.9 Conclusion................................................ 23 4 System Calls On x86_64 from User Space 25 4.1 Setting Up Arguements......................................... 25 4.2 Calling the System Call......................................... 27 4.3 Retrieving the Return Value......................................
    [Show full text]
  • Preview Objective-C Tutorial (PDF Version)
    Objective-C Objective-C About the Tutorial Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. This is the main programming language used by Apple for the OS X and iOS operating systems and their respective APIs, Cocoa and Cocoa Touch. This reference will take you through simple and practical approach while learning Objective-C Programming language. Audience This reference has been prepared for the beginners to help them understand basic to advanced concepts related to Objective-C Programming languages. Prerequisites Before you start doing practice with various types of examples given in this reference, I'm making an assumption that you are already aware about what is a computer program, and what is a computer programming language? Copyright & Disclaimer © Copyright 2015 by Tutorials Point (I) Pvt. Ltd. All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book can retain a copy for future reference but commercial use of this data is not allowed. Distribution or republishing any content or a part of the content of this e-book in any manner is also not allowed without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at [email protected] ii Objective-C Table of Contents About the Tutorial ..................................................................................................................................
    [Show full text]
  • The Glib/GTK+ Development Platform
    The GLib/GTK+ Development Platform A Getting Started Guide Version 0.8 Sébastien Wilmet March 29, 2019 Contents 1 Introduction 3 1.1 License . 3 1.2 Financial Support . 3 1.3 Todo List for this Book and a Quick 2019 Update . 4 1.4 What is GLib and GTK+? . 4 1.5 The GNOME Desktop . 5 1.6 Prerequisites . 6 1.7 Why and When Using the C Language? . 7 1.7.1 Separate the Backend from the Frontend . 7 1.7.2 Other Aspects to Keep in Mind . 8 1.8 Learning Path . 9 1.9 The Development Environment . 10 1.10 Acknowledgments . 10 I GLib, the Core Library 11 2 GLib, the Core Library 12 2.1 Basics . 13 2.1.1 Type Definitions . 13 2.1.2 Frequently Used Macros . 13 2.1.3 Debugging Macros . 14 2.1.4 Memory . 16 2.1.5 String Handling . 18 2.2 Data Structures . 20 2.2.1 Lists . 20 2.2.2 Trees . 24 2.2.3 Hash Tables . 29 2.3 The Main Event Loop . 31 2.4 Other Features . 33 II Object-Oriented Programming in C 35 3 Semi-Object-Oriented Programming in C 37 3.1 Header Example . 37 3.1.1 Project Namespace . 37 3.1.2 Class Namespace . 39 3.1.3 Lowercase, Uppercase or CamelCase? . 39 3.1.4 Include Guard . 39 3.1.5 C++ Support . 39 1 3.1.6 #include . 39 3.1.7 Type Definition . 40 3.1.8 Object Constructor . 40 3.1.9 Object Destructor .
    [Show full text]
  • Using LLVM for Optimized Lightweight Binary Re-Writing at Runtime
    Using LLVM for Optimized Lightweight Binary Re-Writing at Runtime Alexis Engelke, Josef Weidendorfer Department of Informatics Technical University of Munich Munich, Germany EMail: [email protected], [email protected] Abstract—Providing new parallel programming models/ab- helpful in reducing any overhead of provided abstractions. stractions as a set of library functions has the huge advantage But with new languages, porting of existing application that it allows for an relatively easy incremental porting path for code is required, being a high burden for adoption with legacy HPC applications, in contrast to the huge effort needed when novel concepts are only provided in new programming old code bases. Therefore, to provide abstractions such as languages or language extensions. However, performance issues PGAS for legacy codes, APIs implemented as libraries are are to be expected with fine granular usage of library functions. proposed [5], [6]. Libraries have the benefit that they easily In previous work, we argued that binary rewriting can bridge can be composed and can stay small and focused. However, the gap by tightly coupling application and library functions at libraries come with the caveat that fine granular usage of runtime. We showed that runtime specialization at the binary level, starting from a compiled, generic stencil code can help library functions in inner kernels will severely limit compiler in approaching performance of manually written, statically optimizations such as vectorization and thus, may heavily compiled version. reduce performance. In this paper, we analyze the benefits of post-processing the To this end, in previous work [7], we proposed a technique re-written binary code using standard compiler optimizations for lightweight code generation by re-combining existing as provided by LLVM.
    [Show full text]
  • Relational Representation of the LLVM Intermediate Language
    NATIONAL AND KAPODISTRIAN UNIVERSITY OF ATHENS SCHOOL OF SCIENCE DEPARTMENT OF INFORMATICS AND TELECOMMUNICATIONS UNDERGRADUATE STUDIES UNDERGRADUATE THESIS Relational Representation of the LLVM Intermediate Language Eirini I. Psallida Supervisors: Yannis Smaragdakis, Associate Professor NKUA Georgios Balatsouras, PhD Student NKUA ATHENS JANUARY 2014 ΕΘΝΙΚΟ ΚΑΙ ΚΑΠΟΔΙΣΤΡΙΑΚΟ ΠΑΝΕΠΙΣΤΗΜΙΟ ΑΘΗΝΩΝ ΣΧΟΛΗ ΘΕΤΙΚΩΝ ΕΠΙΣΤΗΜΩΝ ΤΜΗΜΑ ΠΛΗΡΟΦΟΡΙΚΗΣ ΚΑΙ ΤΗΛΕΠΙΚΟΙΝΩΝΙΩΝ ΠΡΟΠΤΥΧΙΑΚΕΣ ΣΠΟΥΔΕΣ ΠΤΥΧΙΑΚΗ ΕΡΓΑΣΙΑ Σχεσιακή Αναπαράσταση της Ενδιάμεσης Γλώσσας του LLVM Ειρήνη Ι. Ψαλλίδα Επιβλέποντες: Γιάννης Σμαραγδάκης, Αναπληρωτής Καθηγητής ΕΚΠΑ Γεώργιος Μπαλατσούρας, Διδακτορικός φοιτητής ΕΚΠΑ ΑΘΗΝΑ ΙΑΝΟΥΑΡΙΟΣ 2014 UNDERGRADUATE THESIS Relational Representation of the LLVM Intermediate Language Eirini I. Psallida R.N.: 1115200700272 Supervisor: Yannis Smaragdakis, Associate Professor NKUA Georgios Balatsouras, PhD Student NKUA ΠΤΥΧΙΑΚΗ ΕΡΓΑΣΙΑ Σχεσιακή Αναπαράσταση της ενδιάμεσης γλώσσας του LLVM Ειρήνη Ι. Ψαλλίδα Α.Μ.: 1115200700272 Επιβλέπων: Γιάννης Σμαραγδάκης, Αναπληρωτής Καθηγητής ΕΚΠΑ Γεώργιος Μπαλατσούρας, Διδακτορικός φοιτητής ΕΚΠΑ ΠΕΡΙΛΗΨΗ Περιγράφουμε τη σχεσιακή αναπαράσταση της ενδιάμεσης γλώσσας του LLVM, γνωστή ως LLVM IR. Η υλοποίηση μας παράγει σχέσεις από ένα πρόγραμμα εισόδου σε ενδιάμεση μορφή LLVM. Κάθε σχέση αποθηκεύεται σαν πίνακας βάσης δεδομένων σε ένα περιβάλλον εργασίας Datalog. Αναπαριστούμε το σύστημα τύπων καθώς και το σύνολο εντολών της γλώσσας του LLVM. Υποστηρίζουμε επίσης τους περιορισμούς της γλώσσας προσδιορίζοντάς τους με χρήση της προγραμματιστικής γλώσσας Datalog. ΘΕΜΑΤΙΚΗ ΠΕΡΙΟΧΗ: Μεταγλωτιστές, Γλώσσες Προγραμματισμού ΛΕΞΕΙΣ ΚΛΕΙΔΙΑ: σχεσιακή αναπαράσταση, ενδιάμεση αναπαράσταση, σύστημα τύπων, σύνολο εντολών, LLVM, Datalog ABSTRACT We describe the relational representation of the LLVM intermediate language, known as the LLVM IR. Our implementation produces the relation contents of an input program in the LLVM intermediate form. Each relation is stored as a database table into a Datalog workspace.
    [Show full text]
  • An Analysis of the D Programming Language Sumanth Yenduri University of Mississippi- Long Beach
    View metadata, citation and similar papers at core.ac.uk brought to you by CORE provided by CSUSB ScholarWorks Journal of International Technology and Information Management Volume 16 | Issue 3 Article 7 2007 An Analysis of the D Programming Language Sumanth Yenduri University of Mississippi- Long Beach Louise Perkins University of Southern Mississippi- Long Beach Md. Sarder University of Southern Mississippi- Long Beach Follow this and additional works at: http://scholarworks.lib.csusb.edu/jitim Part of the Business Intelligence Commons, E-Commerce Commons, Management Information Systems Commons, Management Sciences and Quantitative Methods Commons, Operational Research Commons, and the Technology and Innovation Commons Recommended Citation Yenduri, Sumanth; Perkins, Louise; and Sarder, Md. (2007) "An Analysis of the D Programming Language," Journal of International Technology and Information Management: Vol. 16: Iss. 3, Article 7. Available at: http://scholarworks.lib.csusb.edu/jitim/vol16/iss3/7 This Article is brought to you for free and open access by CSUSB ScholarWorks. It has been accepted for inclusion in Journal of International Technology and Information Management by an authorized administrator of CSUSB ScholarWorks. For more information, please contact [email protected]. Analysis of Programming Language D Journal of International Technology and Information Management An Analysis of the D Programming Language Sumanth Yenduri Louise Perkins Md. Sarder University of Southern Mississippi - Long Beach ABSTRACT The C language and its derivatives have been some of the dominant higher-level languages used, and the maturity has stemmed several newer languages that, while still relatively young, possess the strength of decades of trials and experimentation with programming concepts.
    [Show full text]
  • C Programming Tutorial
    C Programming Tutorial C PROGRAMMING TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com i COPYRIGHT & DISCLAIMER NOTICE All the content and graphics on this tutorial are the property of tutorialspoint.com. Any content from tutorialspoint.com or this tutorial may not be redistributed or reproduced in any way, shape, or form without the written permission of tutorialspoint.com. Failure to do so is a violation of copyright laws. This tutorial may contain inaccuracies or errors and tutorialspoint provides no guarantee regarding the accuracy of the site or its contents including this tutorial. If you discover that the tutorialspoint.com site or this tutorial content contains some errors, please contact us at [email protected] ii Table of Contents C Language Overview .............................................................. 1 Facts about C ............................................................................................... 1 Why to use C ? ............................................................................................. 2 C Programs .................................................................................................. 2 C Environment Setup ............................................................... 3 Text Editor ................................................................................................... 3 The C Compiler ............................................................................................ 3 Installation on Unix/Linux ............................................................................
    [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]
  • Moscow ML Library Documentation
    Moscow ML Library Documentation Version 2.00 of June 2000 Sergei Romanenko, Russian Academy of Sciences, Moscow, Russia Claudio Russo, Cambridge University, Cambridge, United Kingdom Peter Sestoft, Royal Veterinary and Agricultural University, Copenhagen, Denmark This document This manual describes the Moscow ML library, which includes parts of the SML Basis Library and several extensions. The manual has been generated automatically from the commented signature files. Alternative formats of this document Hypertext on the World-Wide Web The manual is available at http://www.dina.kvl.dk/~sestoft/mosmllib/ for online browsing. Hypertext in the Moscow ML distribution The manual is available for offline browsing at mosml/doc/mosmllib/index.html in the distribution. On-line help in the Moscow ML interactive system The manual is available also in interactive mosml sessions. Type help "lib"; for an overview of built-in function libraries. Type help "fromstring"; for help on a particular identifier, such as fromString. This will produce a menu of all library structures which contain the identifier fromstring (disregarding the lowercase/uppercase distinction): -------------------------------- | 1 | val Bool.fromString | | 2 | val Char.fromString | | 3 | val Date.fromString | | 4 | val Int.fromString | | 5 | val Path.fromString | | 6 | val Real.fromString | | 7 | val String.fromString | | 8 | val Time.fromString | | 9 | val Word.fromString | | 10 | val Word8.fromString | -------------------------------- Choosing a number from this menu will invoke the
    [Show full text]
  • Graph-Based Procedural Abstraction
    Graph-Based Procedural Abstraction A. Dreweke, M. Worlein,¨ I. Fischer, D. Schell, Th. Meinl, M. Philippsen University of Erlangen-Nuremberg, Computer Science Department 2, Martensstr. 3, 91058 Erlangen, Germany, {dreweke, woerlein, schell, philippsen}@cs.fau.de ALTANA Chair for Applied Computer Science, University of Konstanz, BOX M712, 78457 Konstanz, Germany, {Ingrid.Fischer, Thorsten.Meinl}@inf.uni-konstanz.de Abstract optimizations that can be done much earlier and more often improve the current practice. Even a night or weekend of Procedural abstraction (PA) extracts duplicate code seg- optimization is worthwhile since the resulting savings when ments into a newly created method and hence reduces code building cars or cell phones are enormous. Moreover, off- size. For embedded micro computers the amount of mem- line optimizations of machine code can even be applied to ory is still limited so code reduction is an important is- code that is only available in compiled form. sue. This paper presents a novel approach to PA, that is Of course there are compiler flags that avoid code bloat especially targeted towards embedded systems. Earlier ap- and there are smart linkers [38, 41] that reduce code size. proaches of PA are blind with respect to code reordering, But still, there are space-wasting code duplications that are i.e., two code segments with the same semantic effect but mainly caused by the compiler’s code generation templates, with different instruction orders were not detected as candi- by cut-and-paste programming, by use of standard libraries, dates for PA. Instead of instruction sequences, in our ap- and by translation technology for templates/generics (al- proach the data flow graphs of basic blocks are consid- though the latter are not yet in daily use in the embedded ered.
    [Show full text]
  • Bitwise Instructions
    Bitwise Instructions CSE 30: Computer Organization and Systems Programming Dept. of Computer Science and Engineering University of California, San Diego Overview vBitwise Instructions vShifts and Rotates vARM Arithmetic Datapath Logical Operators vBasic logical operators: vAND: outputs 1 only if both inputs are 1 vOR: outputs 1 if at least one input is 1 vXOR: outputs 1 if exactly one input is 1 vIn general, can define them to accept >2 inputs, but in the case of ARM assembly, both of these accept exactly 2 inputs and produce 1 output vAgain, rigid syntax, simpler hardware Logical Operators vTruth Table: standard table listing all possible combinations of inputs and resultant output for each vTruth Table for AND, OR and XOR A B A AND B A OR B A XOR B A BIC B 0 0 0 0 0 0 0 1 0 1 1 0 1 0 0 1 1 1 1 1 1 1 0 0 Uses for Logical Operators vNote that ANDing a bit with 0 produces a 0 at the output while ANDing a bit with 1 produces the original bit. vThis can be used to create a mask. vExample: 1011 0110 1010 0100 0011 1101 1001 1010 mask: 0000 0000 0000 0000 0000 1111 1111 1111 vThe result of ANDing these: 0000 0000 0000 0000 0000 1101 1001 1010 mask last 12 bits Uses for Logical Operators vSimilarly, note that ORing a bit with 1 produces a 1 at the output while ORing a bit with 0 produces the original bit. vThis can be used to force certain bits of a string to 1s.
    [Show full text]