CSCI130 - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

CSCI130

Description:

Must be translated to machine language. It is not trivial as with assembly ... Translation Programs. Source code (high-level language) object code (machine language) ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 15
Provided by: imadr
Category:
Tags: csci130

less

Transcript and Presenter's Notes

Title: CSCI130


1
Lecture-10 (6.1-6.6)
  • CSCI130
  • Instructor Dr. Imad Rahal

2
Higher-level Programming Languages (PLs)
  • Exam policy!
  • (1G) Machine language programming
  • limited set of instructions
  • binary numbers
  • opcodes, absolute memory addresses and data
  • (2G) Assembly language
  • English mnemonics for binary opcodes
  • Decimal data
  • Labels for memory addresses
  • limited instruction set
  • Use human languages to program
  • Large vocabulary (space and time to search)
    opcode lookup
  • Synonyms
  • Context

3
Higher-level Programming Languages
  • (3G) High-level languages are in the middle
  • Use English-like phrases and mathematical
    notation
  • x x1
  • Do it in assembly?
  • A limited vocabulary with precise meaning
  • Make us think at a higher-level of abstraction
  • No attention to technical and hardware details
  • Like O.S.
  • Does not matter if we have a CISC or RISC
    architecture
  • Much larger instruction set for programmers
  • Multiplication

4
Translation Programs
  • Price for abstraction!
  • Unaware of hardware/low-level details
  • Higher-level programs require translation
    programs
  • An example?
  • Assembler for assembly
  • Fast (why?)
  • Must be translated to machine language
  • It is not trivial as with assembly
  • No 1-to-1 correspondence

5
Show All Numbers Between 1 and N
  • READ
  • ADD VALUE_ONE
  • STOR LIMIT
  • LOOP LOAD COUNTER
  • WRITE
  • ADD
    VALUE_ONE
  • STOR COUNT
  • LOAD LIMIT
  • SUB COUNT
  • JPOS LOOP
  • HALT
  • LIMIT 0
  • COUNTER 1
  • VALUE_ONE 1
  • Read N (4 V.S. 14)
  • For i1 to N
  • Write i
  • Loop

6
Translation Programs
  • Source code (high-level language) ? object code
    (machine language)
  • An interpreter does so on a line by line basis
  • Redone every time
  • Dont have to wait for whole program to be
    translated to see output
  • A compiler produces all object code for the given
    source code
  • Done once to produce object code
  • Must wait
  • Read about them in book

7
Algorithm Design
  • For the same problem we can have
  • Many algorithms to solve it
  • Count from 1 to N
  • If counter lt N ? keep printing
  • If counter gt N ? stop
  • Each implemented through many programs
  • Plan to solve a problem vs actual solution in a
    language understood by the computer
  • We need to design a clear algorithm
  • Pseudo-code (or Flow chart)
  • Compromise between English and programming
    language
  • Omits details
  • Gradual
  • Not likely to get it the first time

8
Algorithms Design
  • Finding the minimum in a list of numbers
  • 1-Find the minimum in 1st portion of the list, S1
  • 2-Find the minimum in the next portion of the
    list, S2
  • 3-Let S be the minimum of S1 and S2
  • 4-Repeat steps 2 and 3 until all portions have
    been covered
  • 5-S is the minimum
  • What is a portion? How do we get it?
  • We need more details
  • We can assume every position in the list to be a
    portion

9
Algorithms Design
  • Psuedocode
  • S first number in list
  • Do until end of list
  • S next number in list
  • If S gt S, then S S
  • When done, Output S
  • Omitted details (depend on the programming
    language)
  • What is a list?
  • How to know the end of list?
  • Ho to go to the next number?
  • Now we have an algorithm, but is it right?
  • We need to test it

10
Algorithms Design
  • We usually test by tracing
  • Use some values to work thru the algorithm
  • 3 23 44 2 12 42 1
  • S S Output3 23 3 44 3 22 122 422 1 1

11
Computer Programming
  • Different types of high-level languages
  • The imperative programming paradigm
  • A program is a sequence of instructions
  • Machine language/assembly language
  • Object-oriented paradigm (just like we do)
  • Visual Basic or VB uses the OOP
  • Objects each having properties and actions
  • e.g. car or rabbit
  • Properties status, color, model, make, year,
    manual/auto
  • Actions turn on, speeds up, slows down, make
    accident, hit rabbit
  • An action taken by an object might affect (change
    some property) itself or other objects
  • Affect itself turn on CAR
  • ? status went from OFF to ON
  • Affect other objects hit rabbit
  • ? Rabbit is dead but the car is still OK

12
Object-Oriented Programming
  • Imagine a computer screen with several icons
  • Each is a task (object?) also desktop is an
    object
  • Each task has its own attributes and functions
  • Properties Icon picture/shape and color
  • functions
  • Single-clicked ? Darken Color (itself)
  • Double-clicked ?
  • Run corresponding program
  • Change desktop look (Desktop is another object)
  • The program is collection of interacting objects
  • In VB, actions are triggered by events
  • Done by users (interactive) e.g. CLICK or
    DOUBLE_CLICK
  • Objects sharing properties/methods are grouped
    into classes
  • Object My Documents, My Computer
  • Class Desktop Icon

13
Steps in Writing a Program
  • Read In Book
  • Steps in Writing a Program
  • OO Application Development

14
Introduction
  • Basic is an imperative language developed in
    1960s
  • Visual Basic (VB) --- developed by Microsoft
  • OO version of Basic
  • Underlying ALL MS office programs
  • You could do a lot
  • Write your own programs
  • Tailor office applications
  • Can be used to link many applications together
  • Visually oriented
  • Programs have a GUI for input/output
  • Not a command prompt
  • First thing to do to build a VB program is to
    design the interface
  • Intro to VB
Write a Comment
User Comments (0)
About PowerShow.com