Your browser doesn't support the features required by impress.js, so you are presented with a simplified version of this presentation.

For the best experience please use the latest Chrome, Safari or Firefox browser.

CIS 115

Lecture 5: Programming



Buenos Días

bon Matin

goeie môre

goedemorgen

guten Morgen

おはようございます

Ada Lovelace

aka Augusta Ada (Byron) King, Countess of Lovelace

Image Source: Wikipedia

“that Enchantress who has thrown her magical spell around the most abstract of Sciences and has grasped it with a force few masculine intellects … could have exerted over it”

- Letter from Charles Babbage to Michael Faraday, September 9, 1843

Analytical Engine

Image Source: Wikipedia

"[The Analytical Engine] might act upon other things besides number, were objects found whose mutual fundamental relations could be expressed by those of the abstract science of operations, and which should be also susceptible of adaptations to the action of the operating notation and mechanism of the engine

Supposing, for instance, that the fundamental relations of pitched sounds in the science of harmony and of musical composition were susceptible of such expression and adaptations, the engine might compose elaborate and scientific pieces of music of any degree of complexity or extent."

- Ada Lovelace

Ada Lovelace

aka The First Computer Programmer and Debugger

Image Source: Wikipedia

Source Code

We want to write a program that takes input from the user and prints the result of that input divided by 61.

What would that program look like?

Scratch

C / C++

#include <stdio.h>

int main(){
  printf(“Enter a number: ”);
  float x = 0.0;
  scanf("%f", &x);
  float y = x / 61;
  printf("%f\n", y);
  return 0;
}

Java

import java.io.*;
import java.util.*;

public class div{
  public static void main(String[] args){
    System.out.print(“Enter a number: “);
    Scanner scanner = new Scanner(System.in);
    float x = scanner.nextFloat();
    float y = x / 61;
    System.out.println(y);
  }
}

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace div
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a number: ");
            double x = Double.Parse(Console.ReadLine());
            double y = x / 61.0;
            Console.WriteLine(y);
        }
    }
}

Python

#!/usr/bin/python

x = input("Enter a number: ")
print x / 61

Other Languages

  • Perl
  • OCaml
  • Lisp
  • R
  • PHP
  • Fortran
  • COBOL
  • Ada
  • Pascal
  • Visual Basic

Compiler

A program that takes source code written in a high level language and converts it into another language, usually one easier for a computer to understand.

Assembly Language

Image Source: Hexblog

Assembly Language

0000000000400564 <main>:
  400564: 55                    push   %rbp
  400565: 48 89 e5              mov    %rsp,%rbp
  400568: 48 83 ec 10           sub    $0x10,%rsp
  40056c: b8 00 00 00 00        mov    $0x0,%eax
  400571: 89 45 f8              mov    %eax,-0x8(%rbp)
  400574: b8 bc 06 40 00        mov    $0x4006bc,%eax
  400579: 48 8d 55 f8           lea    -0x8(%rbp),%rdx
  40057d: 48 89 d6              mov    %rdx,%rsi
  400580: 48 89 c7              mov    %rax,%rdi
  400583: b8 00 00 00 00        mov    $0x0,%eax
  400588: e8 e3 fe ff ff        callq  400470 <__isoc99_scanf@plt>
  40058d: f3 0f 10 45 f8        movss  -0x8(%rbp),%xmm0
  400592: f3 0f 10 0d 2a 01 00 movss  0x12a(%rip),%xmm1
          # 4006c4 <_IO_stdin_used+0xc>
  400599: 00
  40059a: f3 0f 5e c1           divss  %xmm1,%xmm0
  40059e: f3 0f 11 45 fc        movss  %xmm0,-0x4(%rbp)
  4005a3: f3 0f 10 45 fc        movss  -0x4(%rbp),%xmm0
  4005a8: 0f 5a c0              cvtps2pd %xmm0,%xmm0
  4005ab: b8 bf 06 40 00        mov    $0x4006bf,%eax
  4005b0: 48 89 c7              mov    %rax,%rdi
  4005b3: b8 01 00 00 00        mov    $0x1,%eax
  4005b8: e8 93 fe ff ff        callq  400450 <printf@plt>
  4005bd: b8 00 00 00 00        mov    $0x0,%eax
  4005c2: c9                    leaveq
  4005c3: c3                    retq

Assembler

A program that takes assembly language code and converts it into executable machine language code that can be directly read by a computer.

Machine Language

0000330 5f00 675f 6f6d 5f6e 7473 7261 5f74 005f
0000340 696c 6362 732e 2e6f 0036 5f5f 7369 636f
0000350 3939 735f 6163 666e 7000 6972 746e 0066
0000360 5f5f 696c 6362 735f 6174 7472 6d5f 6961
0000370 006e 4c47 4249 5f43 2e32 0037 4c47 4249
0000380 5f43 2e32 2e32 0035 0000 0002 0002 0000
0000390 0003 0000 0000 0000 0001 0002 0010 0000
00003a0 0010 0000 0000 0000 6917 0d69 0000 0003
00003b0 0042 0000 0010 0000 1a75 0969 0000 0002
00003c0 004c 0000 0000 0000 0fe0 0060 0000 0000
00003d0 0006 0000 0003 0000 0000 0000 0000 0000
00003e0 1000 0060 0000 0000 0007 0000 0001 0000
00003f0 0000 0000 0000 0000 1008 0060 0000 0000
0000400 0007 0000 0002 0000 0000 0000 0000 0000
0000410 1010 0060 0000 0000 0007 0000 0004 0000
0000420 0000 0000 0000 0000 8348 08ec 7be8 0000
0000430 e800 010a 0000 35e8 0002 4800 c483 c308

Machine Language

0000330: 00000000 01011111 01011111 01100111 01101101 01101111  .__gmo
0000336: 01101110 01011111 01110011 01110100 01100001 01110010  n_star
000033c: 01110100 01011111 01011111 00000000 01101100 01101001  t__.li
0000342: 01100010 01100011 00101110 01110011 01101111 00101110  bc.so.
0000348: 00110110 00000000 01011111 01011111 01101001 01110011  6.__is
000034e: 01101111 01100011 00111001 00111001 01011111 01110011  oc99_s
0000354: 01100011 01100001 01101110 01100110 00000000 01110000  canf.p
000035a: 01110010 01101001 01101110 01110100 01100110 00000000  rintf.
0000360: 01011111 01011111 01101100 01101001 01100010 01100011  __libc
0000366: 01011111 01110011 01110100 01100001 01110010 01110100  _start
000036c: 01011111 01101101 01100001 01101001 01101110 00000000  _main.
0000372: 01000111 01001100 01001001 01000010 01000011 01011111  GLIBC_
0000378: 00110010 00101110 00110111 00000000 01000111 01001100  2.7.GL
000037e: 01001001 01000010 01000011 01011111 00110010 00101110  IBC_2.
0000384: 00110010 00101110 00110101 00000000 00000000 00000000  2.5...
000038a: 00000010 00000000 00000010 00000000 00000000 00000000  ......

Example

Compiling and running a program written in C on Linux

Hardware

Image Source: Wikipedia

Programming

High Level Language

Compiler

Assembly Language

Assembler

Machine Language

Hardware

Assignments

Blog 2: Historical Figure in Computing

Write about who you believe is the most interesting person in the history of computing. You can use someone we’ve discussed in lecture, read about in the textbook, or choose another figure that relates to what we are discussing if you’d like. You may want to do a bit of digging into this person’s history for some more ideas and information. Don’t just share what we covered in lecture, since everyone already knows most of that information. Some questions you can ask yourself:

Loops in Scratch

Forever block
Forever If block

Loops in Scratch

Repeat block
Repeat Until block