Learning Forth. Developer Technical Support DTS. for Macintosh Open Firmware (Part II) 2/1/01 version 0.9 1
|
|
- Myles Morris
- 5 years ago
- Views:
Transcription
1 Learning Forth for Macintosh Open Firmware (Part II) Developer Technical Support DTS 2/1/01 version 0.9 1
2 Introduction This document is the second in a series of documents intended for hardware designers and device driver programmers that would like to learn and use Forth to examine, access and control hardware from low level in Open Firmware. This document expands upon the basics covered in the first document in the series of Forth for Open Firmware. It provides definition of Forth comment and notation styles, memory management and manipulation, simple printing and text editing and basic flow control and looping functions. This document was originally created as a "PowerPoint" presentation and intended to be a tutorial for Forth in Open Firmware. Slides are in a sequential order, where later (higher numbered) slides build on and assume familiarity with earlier (lower numbered) slides. This documents is intended to cover enough of basic concepts and information about the Forth language and Open Firmware for developers to use some of the features in the Open Firmware environment. Detailed and complete information about Forth and Open Firmware is left to the documents listed under Reference Material in the this document. 2/1/01 version 0.9 2
3 Stack Notation Stack Diagram The Stack Diagram (or Stack Effect Comment) is a programmer s notational convention used to show the effect of a Forth word on the Data Stack. The Syntax is as follows: ( stack item(s) before operation -- stack item(s) after operation ) * note that the parentheses are treated as "comment" characters in Forth, allowing stack effects to be part of the source code. 2/1/01 version 0.9 3
4 Stack Notation (example) Note that the Stack Comment only identifies the Stack effects before and after the function and not the function itself. White Space White Space Separator Before + ( nexecution n -- n ) After Execution Forth Word Comment Start 2nd Item from the Top of the Stack 1st Item from the Top of the Stack Result (on the top of the stack) Comment End 2/1/01 version 0.9 4
5 Stack Notation (Data Types) C: = Compile-time behavior R: = Return stack effect Symbol Data Type Stack Size a-addr A byte address that is cell-aligned 1 cell addr Address. 1 cell b A byte 1 cell c or char An ASCII character 1 cell c-addr A byte address that is character-aligned 1 cell d A double-precision, signed, t wo's complement int eger 2 cells dest Control-flow dest ination. Implement a tion dependent echar Extended character 1 cell flag A single-precision, Boolean t rut h flag 1 cell i*x, j*x, et c. Zero or more cells of unspecified data type Varies ior Result of an I/ 0 operation 1 cell len Leng th of a, string 1 cell loop-sys Loop-cont rol. parameters Implementation dependent nest -sys Implement a tion-dependent info. for procedure calls. Implement a tion dependent n A signed, single-precision, t wo's complement number 1 cell +n A single-precision number that may not be negative 1 cell orig Cont rol-flow origin. Implement a tion dependent u An unsigned, single-precision int ege 1 cell ud An unsigned, double-precision integer 2 cells x A cell (single stack item), ot herwise unspecified. 1 cell xt Execut ion token 1 cell 2/1/01 version 0.9 5
6 Memory Memory Manipulation Words Allocating and Freeing Memory Storing and Fetching Memory 2/1/01 version 0.9 6
7 Memory Manipulation Words alloc-mem (len -- a-addr) allocates len bytes of memory free-mem (a-addr len -- ) frees a portion of memory at addr of len bytes allocated by alloc-mem! (x a-addr -- ) store item x to the cell at a-addr (a-addr -- x ) fetch item x from the cell at a-addr READ dump (addr +n -- ) display len bytes of memory starting at addr off (a-addr -- ) store FALSE to the cell at a-addr on (a-addr --) store TRUE to the cell at dump off on ( Address = ff9cf0d0 Data = ) ff9cf0d0! ok ok 1 > ok ff9cf0d0 4 dump ff9cf0d0: :.4Vx: ok ff9cf0d0 off ok ok 1 >. 0 ok ff9cf0d0 on ok ok 1 >. ffffffff ok 2/1/01 version 0.9 7
8 ( Address = ff9cf0d0 Data = ) Memory Manipulation Words move (src-addr dest-addr len -- ) copy len bytes from src-addr to dest-addr fill (addr len byte -- ) set len bytes beginning at addr to the value byte blank (addr len -- ) set len bytes beginning at addr to the value 0x20 erase (addr len -- ) set len bytes, beginning at addr to zero pad ( -- addr ) return addr of temp storage area (84 char min.) tib ( -- addr ) return addr of the text input buffer move fill blank erase pad tib ff9cf0d0 ff9dd7e0 4 move ok ok 1 >. ffffffff ok ff9cf0d0 4 aa fill ok ok 1 >. aaaaaaaa ok ff9cf0d0 4 blank ok ok 1 > ok ff9cf0d0 4 erase ok ok 1 >. 0 ok pad ok 1 >. ff801e00 ok tib ok 1 >.s ff801c00 ok 1 > 6 dump ff801c00: d 70 :6 dump: ok 2/1/01 version 0.9 8
9 Allocating and Freeing Memory alloc-mem (len -- a-addr) alloc-mem takes the len value entered, off the stack and attempts to allocate that many bytes. If successful, alloc-mem places the starting address of these bytes on the stack. You must save this address in a variable! Allocated memory is contiguous. Multiple (back to back) allocations are not generally contiguous. 8 ok 1 > alloc-mem ok 1 >.s ff9cf0d0 ok 2/1/01 version 0.9 9
10 Alocating and Freeing Memory free-mem (a-addr len -- ) free-mem takes the length and address values entered, off the stack and frees that portion of memory. Always use alloc-mem and free-mem in pairs so as not to have memory leaks or worse! alloc-mem without free-mem will results in memory leaks! free-mem without alloc-mem will result in arbitrary behavior! ( i.e. crash and burn!!) ff9cf0d0 ok 1 > 8 ok 2 > free-mem ok 2/1/01 version
11 Storing and Fetching Memory! Forms of Store 2! (x1 x2 a-addr -- ) store item x1 & x2 to aaddr c! (byte addr -- ) store byte to addr w! (w waddr -- ) store (2 byte) word w to waddr l! (quad qaddr -- ) store (4 byte) long word quad to Forms of Fetch 2@ (a-addr -- x1 x2) fetch item x1 & x2 from a-addr c@ (addr -- byte) fetch byte from addr w@ (waddr -- w) fetch (2 byte) word w from waddr l@ (qaddr -- quad) fetch (4 byte) long word quad from qaddr 2/1/01 version
12 Storing and Fetching Memory ( Address = ff9cf0d0 Data = ) 2! c! w! l! abcdef ff9cf0d0 2! ok ff9cf0d0 2@ ok 2 >.s abcdef ok 2 > 12 ff9cf0d0 c! ok ff9cf0d0 c@ ok 1 >.s 12 ok 1 > 1234 ff9cf0d0 w! ok ff9cf0d0 w@ ok 1 >.s 1234 ok 1 > ff9cf0d0 l! ok ff9cf0d0 l@ ok 1 >.s ok 1 > 2@ c@ w@ l@ 2/1/01 version
13 Text (I/O) Text Input Comments ( ( [text< ) >] -- ) Ignore immediately following text until ) \ ( [rest-of-line< cr >] -- ) Ignore immediately following text for the rest of the line 2/1/01 version
14 Console (I/O) Input key? ( -- pressed?) return true if key is pressed key ( -- char) read char from input device expect (addr len -- ) get an edited input line of length len and store it at addr accept (addr len1 -- len2 ) get an edited input line of length len and store it at addr Output." ([text< >] -- ) display the following text until.( ([text< ) >] -- ) display the following text until ) emit ( char -- ) display the ASII char on the stack type (text-str text-len -- ) display the text-len starting at address text-str Formatting cr ( -- ) start a new line on the display space ( -- ) display a space spaces ( cnt -- ) display cnt number of spaces 2/1/01 version
15 Console (I/O) Input key? ( Address = ff9cf0d0 Data = ) key? \ Meant for programming. Will execute on <cr> ok 1 >. 0 ok \ Note the stack counter after <cr>. key expect accept key \ Pressing the "2" key. ok 1 >. 32 ok \ 32 is ASCII for "2". ff9cf0d0 8 expect ok ff9cf0d0 8 dump ff9cf0d0: : : ok ff9cf0d0 8 accept ok 1 >. 8 ok ff9cf0d0 8 dump ff9cf0d0: : : ok 2/1/01 version
16 Console (I/O) Output." ( Address = ff9cf0d0 )." This is a Test" This is a Test ok \ same as.(.( emit type.( This is also a Test) This is also a Test ok \ same as." 32 emit 2 ok \ Since 32 is "2" in ASCII ff9cf0d fill ok ff9cf0d0 l! ok ff9cf0d4 l! ok ff9cf0d8 l! ok 7354 ff9cf0dc w! ok ff9cf0d0 e dump ff9cf0d0: :This is a TesT: ok ff9cf0d0 e type This is a TesT ok 2/1/01 version
17 Console (I/O) Formatting cr cr." This is a test" cr This is a test ok space." This" space." is" space." a"." test" This is atest ok spaces." This is" 3 spaces." a test" This is a test ok 2/1/01 version
18 Flow Control if ( do-next? -- ) ( C: -- orig-sys ) When flag is TRUE, execute the following code. else ( -- ) ( C: orig-sys1 -- orig-sys2 ) When if flag is FALSE, execute the following code. then ( -- ) ( C: orig-sys-- ) Terminate an if construct case ( sel -- sel ) ( C: -- case-sys ) Begin a case (multiple selection) statement of ( sel of-val -- sel <nothing> ) ( C: case-sys1 -- case-sys2 of-sys ) Begin of clause; execute through endof if params match. endof ( -- ) ( C: case-sys1 of-sys -- case-sys2 ) Mark end of clause; jump to end of case if match. endcase ( sel <nothing> -- ) ( C: case-sys -- ) Mark end of case statement. 2/1/01 version
19 Flow Control (if, then, else example) if : xxx a = if." decimal 10" else." Not Ten!" then ; else True Clause (executed if True) Begin IF statement False Clause (executed if False) End IF statement then : xxx a = if." decimal 10" else." Not Ten!" then ; ok 10 xxx Not Ten! ok a xxx decimal 10 ok 2/1/01 version
20 Flow Control ( CASE example) case a of cr. you typed a endof b of cr. you typed b endof c of cr. you typed c endof cr. what you typed wasn t a, b, or c endcase 2/1/01 version
21 Flow Control ( CASE example dissected) case case Begin CASE statement of endof a of cr." you typed 'a' " endof ok Test Clause Case True Clause (executed if this case is True) b of cr." you typed 'b' " endof ok Begin CASE Clause End CASE Clause endcase c of cr." you typed 'c' " Test Clause Default Case Clause (executed if NO case is True) endof ok End CASE statement cr." what you typed wasn't 'a, b, or c' " endcase 2/1/01 version
22 Flow Control ( CASE example) case of endof endcase : yyy case ok 1 ] a of cr." you typed 'a' " endof ok 2 ] b of cr." you typed 'b' " endof ok 3 ] c of cr." you typed 'c' " endof ok 4 ] cr." what you typed wasn't 'a, b, or c' " endcase ; ok a yyy you typed 'a' ok b yyy you typed 'b' ok c yyy you typed 'c' ok 12 yyy what you typed wasn't 'a, b, or c' ok 2/1/01 version
23 Loops Conditional Infinite These continue to loop forever. Indefinite These loop until a specified condition is met. Counted These loop for a specified number of iterations. An induction variable is maintained and may be read from within the loop. 2/1/01 version
24 Conditional Loops (loop words) begin ( -- ) ( C: -- dest-sys ) begin a conditional loop until ( done? -- ) ( C: dest-sys -- ) end a begin until loop again ( -- ) ( C: dest-sys -- ) end a begin again loop while ( continue? -- ) ( C: dest-sys -- orig-sys dest-sys ) conditional test within a begin while repeat loop repeat ( -- ) ( C: orig-sys dest-sys -- ) end a begin while repeat loop 2/1/01 version
25 Conditional Loops (loop form) Infinite Loops example begin e. again \ display the e character infinitely use control - z to get out of this kind of loop begin words again repeated, loop, actions beginning loop word loop delimiter 2/1/01 version
26 Infinite Loop Example Objective: Create an infinite loop to emit * at the display The loop below won t work! begin * emit again This is because * is not a word or number To solve this problem, the ASCII value of * is needed. 2/1/01 version
27 Infinite Loop Example (Continued) How to determine ASCII value of a keystroke * \ ASCII * (asterisk) character The first line puts the "*" character on the stack as a string 2 >.s address_xyz length 2 > dump The.s word displays the address and length returned on the stack where the "*" string is stored The dump word dumps the length memory contents at address address_xyz: 2a :*: ok \ ASCII for *, is 2a Having obtained the ASCII value of "*", the solution for the example is below begin 2a emit again \ control z to exit 2/1/01 version
28 Infinite Loop Example (Result) How to determine ASCII value of a keystroke * \ ASCII * (asterisk) character 2 >.s ff \ ff = address, 1 = length 2 > dump ff810110: 2a :*: ok \ ASCII for *, is 2a begin 2a emit again \ control z to exit Now this loop will continually fill the display with * characters until the control - z keys are pressed. 2/1/01 version
29 Conditional Loops (loop form) Indefinite Loops Example (loop until encountering 4 on the stack) Begin Loop Loop Action Loop Test End Loop begin 4 = until Beginning loop word Put this value on the stack Compare the top 2 items on the stack Ending loop word a b c d e f ok f > begin 4 = until ok 3 >.s ok 2/1/01 version
30 Conditional Loops (loop form) Indefinite Loops Example (loop while encountering 4 on the stack) Begin Loop Loop Action Loop Test Conditional True Test True Action End Loop begin 4 = while cr." it's 4 repeat Beginning loop word Put this value on the stack Compare the top 2 items on the stack Pass through if True Display message while True Ending loop word (loop back if True ) ok 6 > begin 4 = while cr." it's 4 " repeat it's 4 it's 4 it's 4 ok 2 >.s 1 2 ok 2/1/01 version
31 Counted Loops (loop words) do ( limit start -- ) ( R: -- sys ) ( C: -- dotest ) begin a counted loop?do ( limit start -- ) ( R: -- sys ) ( C: -- dotest ) begin a counted loop if start = limit loop ( -- ) ( R: sys1 -- <nothing> sys2 ) ( C: dotest -- ) add 1 to index, loopback to do or exit +loop ( -- ) ( R: sys1 -- <nothing> sys2 ) ( C: dotest -- ) add delta to index, loop back to do or exit i or j ( -- index ) ( R: sys -- sys ) return i current loop counter or return j next loop counter leave ( -- ) ( R: sys -- ) exit the do or do? loop?leave ( exit? -- ) ( R: sys -- ) exit the do or do? loop if exit? is true unloop ( -- ) ( R: sys -- ) discard loop control parameters 2/1/01 version
32 Loops (Counted loop form) Finite Loops limit start do ( do something) loop limit start do ( do something) n +loop 2/1/01 version
33 Finite Loop Example Example: Begin colon definition Index Index Begin Limit Start Loop Index Loop Action End Loop End colon definition : x 3 0 do i cr." inner = ". loop ; Define a word x Put 3 and then 0 on the stack Start a do loop i is the index Print inner = and then the index value of i Repeat the loop and increment i. : x 3 0 do i cr." inner = ". loop ; ok x inner = 0 inner = 1 inner = 2 ok 2/1/01 version
34 Nested Loop Example Examples: Inner Loop : x 3 0 do i." inner =. loop ; Outer Loop Inner Loop : z 5 0 do i." outer =. cr x loop ; z calls x, the loop previously defined : x 3 0 do i." inner = ". loop ; ok : z 5 0 do i." outer = ". cr x loop ; ok z outer = 0 inner = 0 inner = 1 inner = 2 outer = 1 inner = 0 inner = 1 inner = 2 outer = 2 inner = 0 inner = 1 inner = 2 outer = 3 inner = 0 inner = 1 inner = 2 outer = 4 inner = 0 inner = 1 inner = 2 ok 2/1/01 version
35 Forth in Apple Open Firmware Further reading concerning Forth as it applies to Apple's Open Firmware: Apple Developer Technote: 1061 Apple Developer of Open Firmware, Part I: The User Interface Apple Developer Technote: 1062 Apple Developer of Open Firmware, Part II: The Device Tree Apple Technical Info Library Article ID: Apple Network Server 500,700: Open Firmware Read Me 2/1/01 version
36 Reference Material ANSI Forth IEEE IEEE Standard for Boot (Initialization Configuration) Firmware: Core requirements and Practices Starting Forth by Brodie (out of print) Forth Programmer s Handbook by Conklin & Rather 2/1/01 version
BV Forth (ARM) Core Glossary ByVac ByVac Revision 1.0
BV Forth (ARM) Core Glossary ByVac ByVac 2007 www.byvac.co.uk Revision 1.0 ByVac Page 1 of 44 Contents 1. GLOSSARY... 3 2. FUNCTIONAL CROSS REFERENCE... 4 3. REVISIONS... 43 4. APPENDIX B RESOURCES...
More informationFachhochschule Wedel Technical Report Nr Implementing the Forth Inner Interpreter in High Level Forth
Implementing the Forth Inner Interpreter in High Level Forth Ulrich Hoffmann Abstract This document defines a Forth threaded code (inner) interpreter written entirely in high level standard
More informationLearning Forth. Developer Technical Support DTS. for Macintosh Open Firmware (Part I) 2/1/01 version 0.9 (part I) 1
Learning Forth for Macintosh Open Firmware (Part I) Developer Technical Support DTS 2/1/01 version 0.9 (part I) 1 Introduction This document is the first in a series of documents intended for hardware
More informationFlow Control. CSC215 Lecture
Flow Control CSC215 Lecture Outline Blocks and compound statements Conditional statements if - statement if-else - statement switch - statement? : opertator Nested conditional statements Repetitive statements
More informationx. The optional Cross-compiler word set x.1 Introduction x.2 Additional terms and notation x.2.1 Definitions of terms
x. The optional Cross-compiler word set x.1 Introduction The purpose of this optional wordset is to facilitate writing programs that may be compiled to run on s other than the system performing the compilation.
More informationRepetition Structures
Repetition Structures Chapter 5 Fall 2016, CSUS Introduction to Repetition Structures Chapter 5.1 1 Introduction to Repetition Structures A repetition structure causes a statement or set of statements
More informationCondition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.
Repetition Structures Introduction to Repetition Structures Chapter 5 Spring 2016, CSUS Chapter 5.1 Introduction to Repetition Structures The Problems with Duplicate Code A repetition structure causes
More informationControl Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003
Control Flow COMS W1007 Introduction to Computer Science Christopher Conway 3 June 2003 Overflow from Last Time: Why Types? Assembly code is typeless. You can take any 32 bits in memory, say this is an
More informationIntroduction to Programming in C Department of Computer Science and Engineering. Lecture No. #17. Loops: Break Statement
Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #17 Loops: Break Statement (Refer Slide Time: 00:07) In this session we will see one more feature that is present
More informationMPCNC Forth Controller Userguide Version 0.6
MPCNC Forth Controller Userguide Version 0.6 1. Introduction MPCNC Forth Controller allows users to write programs to interactively control the MPCNC (or any Marlin style software) 1.1. A Forth Like Language
More informationProgramming refresher and intro to C programming
Applied mechatronics Programming refresher and intro to C programming Sven Gestegård Robertz sven.robertz@cs.lth.se Department of Computer Science, Lund University 2018 Outline 1 C programming intro 2
More informationConditionals and Loops
Conditionals and Loops Conditionals and Loops Now we will examine programming statements that allow us to: make decisions repeat processing steps in a loop Chapter 5 focuses on: boolean expressions conditional
More informationAccelerating Information Technology Innovation
Accelerating Information Technology Innovation http://aiti.mit.edu Cali, Colombia Summer 2012 Lección 03 Control Structures Agenda 1. Block Statements 2. Decision Statements 3. Loops 2 What are Control
More informationLecture A2: X-TOY Programming
Lecture A2: X-TOY Programming What We ve Learned About X-TOY X-TOY: what s in it, how to use it. Bo with switches and lights. 436 bits = 256 6 + 6 6 + 8. von Neumann architecture. Data representation.
More informationInformation Science 1
Information Science 1 Fundamental Programming Constructs (1) Week 11 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 10 l Flow of control
More informationMaciej Sobieraj. Lecture 1
Maciej Sobieraj Lecture 1 Outline 1. Introduction to computer programming 2. Advanced flow control and data aggregates Your first program First we need to define our expectations for the program. They
More information4e4th Glossary. Release Build Functional Groups, as defined in source code files.
4e4th Glossary. Release0.34 - Build 2012-04-11 http://www.forth-ev.de/repos/4e4th/ Functional Groups, as defined in source code files. 4e-core430G2553.s43 ;C EXECUTE i*x xt -- j*x execute Forth word at
More information4e-core430G2553.s43 ;C EXECUTE i*x xt -- j*x execute Forth word at 'xt' ;Z lit -- x fetch inline literal to stack ;C EXIT -- exit a colon definition
4e-core430G2553.s43 ;C EXECUTE i*x xt -- j*x execute Forth word at 'xt' ;Z lit -- x fetch inline literal to stack ;C EXIT -- exit a colon definition ;C VARIABLE -- define a Forth VARIABLE ;C CONSTANT --
More informationCPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)
Name Definition Matching (8 Points) 1. (8 pts) Match the words with their definitions. Choose the best definition for each word. Relational Expression Iteration Counter Count-controlled loop Loop Flow
More informationLanguage Reference Manual
ALACS Language Reference Manual Manager: Gabriel Lopez (gal2129) Language Guru: Gabriel Kramer-Garcia (glk2110) System Architect: Candace Johnson (crj2121) Tester: Terence Jacobs (tj2316) Table of Contents
More informationcore430g2553.s43 ;C EXECUTE i*x xt -- j*x execute Forth word ;C at 'xt' ;Z lit -- x fetch inline literal to stack ;C EXIT -- exit a colon definition
core430g2553.s43 ;C EXECUTE i*x xt -- j*x execute Forth word ;C at 'xt' ;Z lit -- x fetch inline literal to stack ;C EXIT -- exit a colon definition ;C VARIABLE -- define a Forth VARIABLE ;C CONSTANT --
More informationIntroduction to Programming in C Department of Computer Science and Engineering. Lecture No. #29 Arrays in C
Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #29 Arrays in C (Refer Slide Time: 00:08) This session will learn about arrays in C. Now, what is the word array
More informationThe CPU and Memory. How does a computer work? How does a computer interact with data? How are instructions performed? Recall schematic diagram:
The CPU and Memory How does a computer work? How does a computer interact with data? How are instructions performed? Recall schematic diagram: 1 Registers A register is a permanent storage location within
More information\n is used in a string to indicate the newline character. An expression produces data. The simplest expression
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More informationHForth Glossary. Introduction. Stack Diagrams. HForth Glossary GL - 1! " # $ % & ` ( ) * + ' -. / 0-9 : ; < = A Z [ / ] ^ _ a z { } ~
HForth Glossary Introduction This glossary defines the low level Forth words that are part of HForth. Music related words will be defined in the HMSL Manual. Some words, specific file I/O related words
More informationInformation Science 1
Topics covered Information Science 1 Fundamental Programming Constructs (1) Week 11 Terms and concepts from Week 10 Flow of control and conditional statements Selection structures if statement switch statement
More informationCYSE 411/AIT681 Secure Software Engineering Topic #12. Secure Coding: Formatted Output
CYSE 411/AIT681 Secure Software Engineering Topic #12. Secure Coding: Formatted Output Instructor: Dr. Kun Sun 1 This lecture: [Seacord]: Chapter 6 Readings 2 Secure Coding String management Pointer Subterfuge
More information2/9/18. CYSE 411/AIT681 Secure Software Engineering. Readings. Secure Coding. This lecture: String management Pointer Subterfuge
CYSE 411/AIT681 Secure Software Engineering Topic #12. Secure Coding: Formatted Output Instructor: Dr. Kun Sun 1 This lecture: [Seacord]: Chapter 6 Readings 2 String management Pointer Subterfuge Secure
More informationMore Programming Constructs -- Introduction
More Programming Constructs -- Introduction We can now examine some additional programming concepts and constructs Chapter 5 focuses on: internal data representation conversions between one data type and
More informationCSCI 1061U Programming Workshop 2. C++ Basics
CSCI 1061U Programming Workshop 2 C++ Basics 1 Learning Objectives Introduction to C++ Origins, Object-Oriented Programming, Terms Variables, Expressions, and Assignment Statements Console Input/Output
More informationHandy Cricket Programming
Handy Cricket Programming Reference Overview The Handy Cricket is programmed in a language called Cricket Logo, which is a simplified version of the powerful yet easy-to-learn Logo language. Cricket Logo
More informationMATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards
MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards Language Reference Manual Introduction The purpose of
More informationHForth Glossary GL - 1! " # $ % & ` ( ) * + ' -. / 0-9 : ; < = A Z [ / ] ^ _ a z { } ~
D+ ( d1 d2 -- d1+d2, add double numbers ) Double precision numbers are 64 bits wide. HEX 12345678.55443322 19283746.98765432 D+ D. ( prints 1B4C8DAEEDBA8754 ) D- ( d1 d2 -- d1+d2, subtract double numbers
More informationChapter 4: Control structures. Repetition
Chapter 4: Control structures Repetition Loop Statements After reading and studying this Section, student should be able to Implement repetition control in a program using while statements. Implement repetition
More informationJava Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition
Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition Learn about repetition (looping) control structures Explore how to construct and use: o Counter-controlled
More informationChapter 4 Loops. int x = 0; while ( x <= 3 ) { x++; } System.out.println( x );
Chapter 4 Loops Sections Pages Review Questions Programming Exercises 4.1 4.7, 4.9 4.10 104 117, 122 128 2 9, 11 13,15 16,18 19,21 2,4,6,8,10,12,14,18,20,24,26,28,30,38 Loops Loops are used to make a program
More informationYou can enter commands at the console any time after the prompt character is displayed.
NJ7P MON80 Monitor The Monitor is a control program that provides supervisory functions for the Intel microcomputer Single Board Computers. It processes the commands you enter at the console device. The
More informationLanguage Reference Manual simplicity
Language Reference Manual simplicity Course: COMS S4115 Professor: Dr. Stephen Edwards TA: Graham Gobieski Date: July 20, 2016 Group members Rui Gu rg2970 Adam Hadar anh2130 Zachary Moffitt znm2104 Suzanna
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering
More information5. Control Statements
5. Control Statements This section of the course will introduce you to the major control statements in C++. These control statements are used to specify the branching in an algorithm/recipe. Control statements
More information1 Lexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler
More informationChapter 4: Control structures
Chapter 4: Control structures Repetition Loop Statements After reading and studying this Section, student should be able to Implement repetition control in a program using while statements. Implement repetition
More information#include <iostream> #include <algorithm> #include <cmath> using namespace std; int f1(int x, int y) { return (double)(x/y); }
1. (9 pts) Show what will be output by the cout s in this program. As in normal program execution, any update to a variable should affect the next statement. (Note: boolalpha simply causes Booleans to
More informationChapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Slide 3-3 Flow Of Control Flow of control refers to the
More informationn Group of statements that are executed repeatedly while some condition remains true
Looping 1 Loops n Group of statements that are executed repeatedly while some condition remains true n Each execution of the group of statements is called an iteration of the loop 2 Example counter 1,
More informationREPETITION CONTROL STRUCTURE LOGO
CSC 128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING REPETITION CONTROL STRUCTURE 1 Contents 1 Introduction 2 for loop 3 while loop 4 do while loop 2 Introduction It is used when a statement or a block of
More information3 The L oop Control Structure
3 The L oop Control Structure Loops The while Loop Tips and Traps More Operators The for Loop Nesting of Loops Multiple Initialisations in the for Loop The Odd Loop The break Statement The continue Statement
More informationLoops and Files. Chapter 04 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz
Loops and Files Chapter 04 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Chapter Topics o The Increment and Decrement Operators o The while Loop o Shorthand Assignment Operators o The do-while
More informationChapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More informationJava Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition
Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition Learn about repetition (looping) control structures Explore how to construct and use: o Counter-controlled
More informationLecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan
Lecture 08-1 Programming in C++ PART 1 By Assistant Professor Dr. Ali Kattan 1 The Conditional Operator The conditional operator is similar to the if..else statement but has a shorter format. This is useful
More informationThe SPL Programming Language Reference Manual
The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming
More informationINTRODUCTION 1 AND REVIEW
INTRODUTION 1 AND REVIEW hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Programming: Advanced Objectives You will learn: Program structure. Program statements. Datatypes. Pointers. Arrays. Structures.
More informationConnecting with Computer Science, 2e. Chapter 15 Programming II
Connecting with Computer Science, 2e Chapter 15 Programming II Objectives In this chapter you will: Gain an understanding of the basics of high-level programming languages, using Java and C++ as examples
More informationText Input and Conditionals
Text Input and Conditionals Text Input Many programs allow the user to enter information, like a username and password. Python makes taking input from the user seamless with a single line of code: input()
More informationSyntax and Variables
Syntax and Variables What the Compiler needs to understand your program, and managing data 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line
More informationObjectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators
Objectives Chapter 4: Control Structures I (Selection) In this chapter, you will: Learn about control structures Examine relational and logical operators Explore how to form and evaluate logical (Boolean)
More informationLe L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators
Course Name: Advanced Java Lecture 2 Topics to be covered Variables Operators Variables -Introduction A variables can be considered as a name given to the location in memory where values are stored. One
More informationLexical Structure (Chapter 3, JLS)
Lecture Notes CS 140 Winter 2006 Craig A. Rich Lexical Structure (Chapter 3, JLS) - A Java source code file is viewed as a string of unicode characters, including line separators. - A Java source code
More informationBinghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program
Syntax What the Compiler needs to understand your program 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line Possibly replacing it with other
More informationCOMP 202 Java in one week
CONTENTS: Basics of Programming Variables and Assignment Data Types: int, float, (string) Example: Implementing a calculator COMP 202 Java in one week The Java Programming Language A programming language
More informationIn this lab, you will learn more about selection statements. You will get familiar to
Objective: In this lab, you will learn more about selection statements. You will get familiar to nested if and switch statements. Nested if Statements: When you use if or if...else statement, you can write
More informationRun-time Environments
Run-time Environments Status We have so far covered the front-end phases Lexical analysis Parsing Semantic analysis Next come the back-end phases Code generation Optimization Register allocation Instruction
More informationWYSE Academic Challenge 2002 Computer Science Test (Sectional) SOLUTION
Computer Science - 1 WYSE Academic Challenge 2002 Computer Science Test (Sectional) SOLUTION 1. Access to moving head disks requires three periods of delay before information is brought into memory. The
More informationCHAD Language Reference Manual
CHAD Language Reference Manual INTRODUCTION The CHAD programming language is a limited purpose programming language designed to allow teachers and students to quickly code algorithms involving arrays,
More informationRepetition, Looping CS101
Repetition, Looping CS101 Last time we looked at how to use if-then statements to control the flow of a program. In this section we will look at different ways to repeat blocks of statements. Such repetitions
More informationCreating a C++ Program
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer. 1 Creating a C++ Program created using an
More informationRun-time Environments
Run-time Environments Status We have so far covered the front-end phases Lexical analysis Parsing Semantic analysis Next come the back-end phases Code generation Optimization Register allocation Instruction
More informationDefinite Loops. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Using a Variable for Counting
Unit 2, Part 2 Definite Loops Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Using a Variable for Counting Let's say that we're using a variable i to count the number of times that
More informationARG! Language Reference Manual
ARG! Language Reference Manual Ryan Eagan, Mike Goldin, River Keefer, Shivangi Saxena 1. Introduction ARG is a language to be used to make programming a less frustrating experience. It is similar to C
More informationChapter Goals. Contents LOOPS
CHAPTER 4 LOOPS Slides by Donald W. Smith TechNeTrain.com Final Draft Oct 30, 2011 Chapter Goals To implement while, for, and do loops To hand-trace the execution of a program To become familiar with common
More informationBits, Bytes, and Integers Part 2
Bits, Bytes, and Integers Part 2 15-213: Introduction to Computer Systems 3 rd Lecture, Jan. 23, 2018 Instructors: Franz Franchetti, Seth Copen Goldstein, Brian Railing 1 First Assignment: Data Lab Due:
More information8. Control statements
8. Control statements A simple C++ statement is each of the individual instructions of a program, like the variable declarations and expressions seen in previous sections. They always end with a semicolon
More informationx = 3 * y + 1; // x becomes 3 * y + 1 a = b = 0; // multiple assignment: a and b both get the value 0
6 Statements 43 6 Statements The statements of C# do not differ very much from those of other programming languages. In addition to assignments and method calls there are various sorts of selections and
More informationCS313D: ADVANCED PROGRAMMING LANGUAGE
CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting
More informationChapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.
Chapter 4: Control Structures I (Selection) In this chapter, you will: Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate logical (Boolean)
More informationYOLOP Language Reference Manual
YOLOP Language Reference Manual Sasha McIntosh, Jonathan Liu & Lisa Li sam2270, jl3516 and ll2768 1. Introduction YOLOP (Your Octothorpean Language for Optical Processing) is an image manipulation language
More informationC Review. MaxMSP Developers Workshop Summer 2009 CNMAT
C Review MaxMSP Developers Workshop Summer 2009 CNMAT C Syntax Program control (loops, branches): Function calls Math: +, -, *, /, ++, -- Variables, types, structures, assignment Pointers and memory (***
More informationQuick Reference Guide
SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD mikroelektronika Development tools - Books - Compilers Quick Reference Quick Reference Guide with EXAMPLES for Basic language This reference guide
More informationPace University. Fundamental Concepts of CS121 1
Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction
More informationTHE INTEGER DATA TYPES. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)
THE INTEGER DATA TYPES STORAGE OF INTEGER TYPES IN MEMORY All data types are stored in binary in memory. The type that you give a value indicates to the machine what encoding to use to store the data in
More informationFlow of Control. Branching Loops exit(n) method Boolean data type and expressions
Flow of Control Branching Loops exit(n) method Boolean data type and expressions Chapter 3 Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Flow of Control is the execution order
More informationA complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation
Complement Number Systems A complement number system is used to represent positive and negative integers A complement number system is based on a fixed length representation of numbers Pretend that integers
More informationA Recognizer Influenced Handler Based Outer Interpreter Structure
A Recognizer Influenced Handler Based Outer Interpreter Structure Ulrich Hoffmann uho@.de many pictures taken from leo brodies famous book "starting forth" (c) forth, inc over view recognizers outer interpreter:
More informationProgram Security and Vulnerabilities Class 2
Program Security and Vulnerabilities Class 2 CEN-5079: 28.August.2017 1 Secure Programs Programs Operating System Device Drivers Network Software (TCP stack, web servers ) Database Management Systems Integrity
More informationintroduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion
introduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion Today s video will talk about an important concept in computer science which is
More informationThe PCAT Programming Language Reference Manual
The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language
More informationBasic Assembly SYSC-3006
Basic Assembly Program Development Problem: convert ideas into executing program (binary image in memory) Program Development Process: tools to provide people-friendly way to do it. Tool chain: 1. Programming
More informationLOON. Language Reference Manual THE LANGUAGE OF OBJECT NOTATION. Kyle Hughes, Jack Ricci, Chelci Houston-Borroughs, Niles Christensen, Habin Lee
LOON THE LANGUAGE OF OBJECT NOTATION Language Reference Manual Kyle Hughes, Jack Ricci, Chelci Houston-Borroughs, Niles Christensen, Habin Lee October 2017 1 Contents 1 Introduction 3 2 Types 4 2.1 JSON............................................
More informationModule 4: Decision-making and forming loops
1 Module 4: Decision-making and forming loops 1. Introduction 2. Decision making 2.1. Simple if statement 2.2. The if else Statement 2.3. Nested if Statement 3. The switch case 4. Forming loops 4.1. The
More informationGetting started with Java
Getting started with Java Magic Lines public class MagicLines { public static void main(string[] args) { } } Comments Comments are lines in your code that get ignored during execution. Good for leaving
More informationAssembly Language Manual for the STACK Computer
Computer Science 301 1 Assembly Language Manual for the STACK Computer Assembly language programmers should read the hardware description of the STACK computer together with information about the effect
More informationCourse Topics - Outline
Course Topics - Outline Lecture 1 - Introduction Lecture 2 - Lexical conventions Lecture 3 - Data types Lecture 4 - Operators Lecture 5 - Behavioral modeling A Lecture 6 Behavioral modeling B Lecture 7
More informationLanguages and Compiler Design II IR Code Generation I
Languages and Compiler Design II IR Code Generation I Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU Spring 2010 rev.: 4/16/2010 PSU CS322 HM 1 Agenda Grammar G1
More informationSlide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Advance mode: Auto
CS 170 Java Programming 1 The Switch Slide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Menu-Style Code With ladder-style if-else else-if, you might sometimes find yourself writing menu-style
More informationCSc 520 Principles of Programming Languages. 26 : Control Structures Introduction
CSc 520 Principles of Programming Languages 26 : Control Structures Introduction Christian Collberg Department of Computer Science University of Arizona collberg+520@gmail.com Copyright c 2008 Christian
More informationHigh Performance Computing in C and C++
High Performance Computing in C and C++ Rita Borgo Computer Science Department, Swansea University Summary Introduction to C Writing a simple C program Compiling a simple C program Running a simple C program
More informationX Language Definition
X Language Definition David May: November 1, 2016 The X Language X is a simple sequential programming language. It is easy to compile and an X compiler written in X is available to simplify porting between
More informationObjectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program
Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationECET 264 C Programming Language with Applications
ECET 264 C Programming Language with Applications Lecture 6 Control Structures and More Operators Paul I. Lin Professor of Electrical & Computer Engineering Technology http://www.etcs.ipfw.edu/~lin Lecture
More information