Code - PowerPoint PPT Presentation

1 / 45
About This Presentation
Title:

Code

Description:

WiMAX offers multi-Mb/s in areas beyond reach of WiFi ... WiFi (Cordless) primarily used to provide a connection within a limited area ... WiFi / WiMAX Synergy ... – PowerPoint PPT presentation

Number of Views:69
Avg rating:3.0/5.0
Slides: 46
Provided by: DPD5
Category:
Tags: code | wifi

less

Transcript and Presenter's Notes

Title: Code


1
Code
2
Overview
  • Architecture
  • Levels of software
  • The software development process

3
Takeaways
  • The hardware architecture defines how the
    software architecture is built.
  • The software architecture defines how code is
    written.
  • Open systems can be more easily modified

4
Overview
  • Architecture
  • Connect processor to peripherals
  • CD/DVD, Hard disk, floppy disk off motherboard
  • Network, keyboard, mouse, monitor on
    motherboard
  • Connect processor to RAM
  • Design instruction set (and circuitry) for CPU
  • Levels of software
  • The software development process

5
CPU is the key component
  • Key ideas
  • Von Neumann machine
  • Fetch execute cycle
  • Can only operate on data held locally
  • May have many or few machine instructions
  • CISC (Complex Instruction Set Computers)
  • RISC (Reduced Instruction Set Computers)

6
The CPU
Memory Registers
Control Unit(State Machine)
7
Machine Snapshot
  • Everything is in binary (hex)
  • Organized into words of some size (16/32/64 bits)

Registers
R0 0000 R1 0CA8 R2 A9DB R3 0705 R4 1011 R5
90A0 R6 0807 R7 00A0
8
Fetch/Execute Cycle
  • At each tick of the clock
  • Read the Instruction pointer
  • Go to that address in RAM
  • Fetch the contents of that location to the
    instruction register
  • Execute the instruction stored in the instruction
    register
  • This instruction may require using the A/LU to
    operate on information in registers
  • This instruction may involve information from
    registers, RAM, disk, CD,
  • This instruction may change the address in the
    instruction pointer. It it doesnt, the
    instruction pointer is increased by 1 when the
    execution is done.

9
Sidebar Question
  • My computer is 1.2GHz, that means 1.2 billion
    clock ticks per second.
  • When I run IE and ask it to open a page, it takes
  • 3 seconds if the page is already open elsewhere
  • 7 seconds otherwise
  • Questions
  • Why the difference in timings?
  • What happens to the 3.6-8.4 billion clock ticks?

10
(No Transcript)
11
(No Transcript)
12
Sample Instructions
  • Add RegisterA to RegisterB and put the result in
    RegisterC
  • Load the value X into RegisterA
  • Store the contents of RegisterB into location X
    in RAM
  • Load the contents of memory location X into
    RegisterA
  • Move the instruction pointer to location X
  • If the value in RegisterA is positive then move
    the instruction pointer to location X

13
Adding Numbers
  • Simple Program to calculate1 2 3 4 5 6
    21

10 Load R0 ? 0001 (always 1) 11 Load R2 ?
0000 (running total) 12 Load R1 ? 0001
(current number) 13 Add R2 ? R2 R1
(R21) 14 Add R1 ? R1 R0 (R12) 15 Add
R2 ? R2 R1 (R23) 16 Add R1 ? R1 R0
(R13) 17 Add R2 ? R2 R1 (R26) 18 Add
R1 ? R1 R0 (R14) 19 Add R2 ? R2 R1
(R210) 1A Add R1 ? R1 R0 (R15) 1B Add
R2 ? R2 R1 (R215) 1C Add R1 ? R1 R0
(R16) 1D Add R2 ? R2 R1 (R221) 1E halt
14
Adding Numbers
  • Use a Loop to calculate1 2 3 4 5 N

10 Load R1 ? 0006 (N) 11 Load R2 ?
0000 (running total) 12 Load R0 ? 0001
(always 1) 13 Add R2 ? R2 R1
(add in N) 14 Sub R1 ? R1 - R0 (N N-1)
15 Jump to 13 if (R10) (If N isnt 0
yet, go back) 16 halt (N is
now 0, and R2 12N)
15
Von Neumann machine
  • Program and data indistinguishable
  • The same machine can do different things at
    different times
  • So, we write programs

16
Overview
  • Architecture
  • Levels of software
  • Operating systems
  • Compilers
  • Libraries
  • Interfaces
  • Applications
  • The software development process

17
When user turns on computer
  • System boots
  • First the hardware, then the Windows operating
    system
  • Windows O/S makes desktop appears
  • Windows O/S creates device interaction
  • CPU is listening to mouse, keyboard, etc.
  • CPU can communicate with RAM, disk,
  • O/S enters event-driven fetch/execute cycle
  • Fetch event from user (mouse click, keyboard
    stroke, ..)
  • Executes command

18
Under the hood when machine boots
  • Power goes on, each device is turned on
  • BIOS lets you talk to hardware
  • Change order devices are turned on
  • Set system clock
  • Identify new interaction devices
  • Then, the boot program for Windows starts.
  • You tell it an order to look at disks
  • It looks at disks in this order to find operating
    system
  • Operating system boots
  • Simple program called the operating system kernel
    is loaded (at location 10). This is the program
    that runs the computer.

19
Fetch/execute cycle
  • Fetch is Event driven
  • Button clicks in windows
  • Command line entries in UNIX
  • Execution is done by the operating system
  • .exe files in Windows
  • How do we create a .exe file?

20
How do we create a .exe file?
  • Unix
  • Write a program in a higher level language
  • C, C, Java,
  • Compile the program into machine level commands
  • Translate the compiled version into binary
    commands
  • Link to system libraries (eg for input/output)
  • Build the .exe
  • Execute the .exe

21
Overview
  • Architecture
  • Levels of software
  • Operating systems
  • Compilers
  • Libraries
  • Interfaces
  • Applications
  • The software development process

22
A very simple program
main( ) int a,b,c a 1
b 2 c a b
23
Translation
.file "a.c" .version
"01.01" gcc2_compiled. .text .align
4 .globl main .type main,_at_function main
pushl ebp movl esp,
ebp subl 12, esp movl
1, -4(ebp) movl 2, -8(ebp)
movl -8(ebp), eax addl -4(ebp),
eax movl eax, -12(ebp)
leave ret .Lfe1 .size
main,.Lfe1-main .ident "GCC (GNU) 2.96
20000731 (Red Hat Linux 7.3 2.96-112)"
24
.file "a.c" gcc2_compiled. .section
".text" .align 4 .global main
.type main,function .proc
04 main !PROLOGUE 0 save
sp, -128, sp !PROLOGUE 1 st
i0, fp68 st i1, fp72
mov 1, o0 st o0,
fp-20 mov 2, o0 st
o0, fp-24 ld fp-20, o0
ld fp-24, o1 add o0, o1,
o0 st o0, fp-28 .LL2
ret restore .LLfe1 .size
main,.LLfe1-main .ident "GCC (GNU)
2.95.2 19991024 (release)"
.file "a.c" .version
"01.01" gcc2_compiled. .text .align
4 .globl main .type main,_at_function main
pushl ebp movl esp,
ebp subl 12, esp movl
1, -4(ebp) movl 2, -8(ebp)
movl -8(ebp), eax addl -4(ebp),
eax movl eax, -12(ebp)
leave ret .Lfe1 .size
main,.Lfe1-main .ident "GCC (GNU) 2.96
20000731 (Red Hat Linux 7.3 2.96-112)"
25
After translation
  • A binary file is created

0000000 7f45 4c46 0101 0100 0000 0000 0000
0000 0000020 0200 0300 0100 0000 e082 0408 3400
0000 0000040 1029 0000 0000 0000 3400 2000 0600
2800 0000060 1d00 1a00 0600 0000 3400 0000 3480
0408 0000100 3480 0408 c000 0000 c000 0000 0500
0000 0000120 0400 0000 0300 0000 f400 0000 f480
0408 0000140 f480 0408 1300 0000 1300 0000 0400
0000 0000160 0100 0000 0100 0000 0000 0000 0080
0408 0000200 0080 0408 7804 0000 7804 0000 0500
0000 0000220 0010 0000 0100 0000 7804 0000 7894
0408 0000240 7894 0408 1001 0000 2801 0000 0600
0000 0000260 0010 0000 0200 0000 8c04 0000 8c94
0408 0000300 8c94 0408 d000 0000 d000 0000 0600
0000 for 15,000 bytes
26
At execution
  • The binary file is moved from disk to RAM
  • The instruction pointer is set to the first line
    of the file in RAM
  • Execution happens
  • Fetch/execute cycle until program exits

27
Issues
  • Different machines have different basic
    instructions
  • The hardware guys get to specify the instruction
    set
  • CISC vs. RISC vs.
  • Different machines interpret slightly different
    versions of the language
  • Programs can have different code for different
    architectures
  • ifdef SPARC
  • SPARC code goes here
  • else
  • LINUX code goes here
  • endif

28
Other tidbit
  • The compiler might be optimizing
  • Generates more efficient code at greater cost
  • pushl ebp
  • movl esp, ebp
  • popl ebp
  • ret
  • Code may look very different

29
Translation issues
  • Different compilers do different things
  • Source code is easiest to read
  • Assembler code is fairly unreadable
  • Binary code is totally unreadable

30
Overview
  • Architecture
  • Levels of software
  • Operating systems
  • Compilers
  • Libraries
  • Interfaces
  • Applications
  • The software development process

31
Libraries
  • Shared code for common functions
  • Math function library
  • Input/Output library
  • String processing library
  • Drawing library
  • Often linked at execution time.
  • .dll dynamically linked library
  • A library needs to be loaded into RAM but 1 copy
    is enough
  • When you install a program, it brings its dlls
    and see if they are needed

32
Overview
  • Architecture
  • Levels of software
  • Operating systems
  • Compilers
  • Libraries
  • Interfaces
  • Applications
  • The software development process

33
Interfaces
  • Tools are designed with APIs (applications
    programmers interface)
  • The API is published, but the code isnt
  • Who controls the API, controls a lot

34
Visual Basic Exercise
  • Create 2 buttons
  • Add
  • Quit
  • Give each functionality
  • Update buttons to take input

35
(No Transcript)
36
Public Class Form1 Inherits
System.Windows.Forms.Form Region " Windows Form
Designer generated code " Public Sub New()
MyBase.New() 'This call is
required by the Windows Form Designer.
InitializeComponent() 'Add any
initialization after the InitializeComponent()
call End Sub 'Form overrides dispose to
clean up the component list. Protected
Overloads Overrides Sub Dispose(ByVal disposing
As Boolean) If disposing Then
If Not (components Is Nothing) Then
components.Dispose() End If
End If MyBase.Dispose(disposing) End
Sub 'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon
tainer
37
'NOTE The following procedure is required by the
Windows Form Designer 'It can be modified
using the Windows Form Designer. 'Do not
modify it using the code editor. Friend
WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms
.Label Friend WithEvents Label3 As
System.Windows.Forms.Label Friend WithEvents
Button1 As System.Windows.Forms.Button Friend
WithEvents TextBox1 As System.Windows.Forms.TextBo
x Friend WithEvents TextBox2 As
System.Windows.Forms.TextBox Friend
WithEvents TextBox3 As System.Windows.Forms.TextBo
x
Private Sub InitializeComponent()
Me.Label1 New System.Windows.Forms.Label()
Me.Label2 New System.Windows.Forms.Label()
Me.Label3 New System.Windows.Forms.Label()
Me.Button1 New System.Windows.Forms.But
ton() Me.TextBox1 New
System.Windows.Forms.TextBox()
Me.TextBox2 New System.Windows.Forms.TextBox()
Me.TextBox3 New System.Windows.Forms.Text
Box() Me.SuspendLayout() '
'Label1 ' Me.Label1.Location
New System.Drawing.Point(184, 32)
Me.Label1.Name "Label1" Me.Label1.Size
New System.Drawing.Size(176, 88)
Me.Label1.TabIndex 0 Me.Label1.Text
"vALUE OF a" ' 'Label2 '
Me.Label2.Location New
System.Drawing.Point(176, 168)
Me.Label2.Name "Label2" Me.Label2.Size
New System.Drawing.Size(184, 104)
Me.Label2.TabIndex 1 Me.Label2.Text
"vLAUE OF b" '
38
'Label3 ' Me.Label3.Location
New System.Drawing.Point(184, 416)
Me.Label3.Name "Label3" Me.Label3.Size
New System.Drawing.Size(184, 112)
Me.Label3.TabIndex 2 Me.Label3.Text
"vALUE OF c" ' 'Button1
' Me.Button1.Location New
System.Drawing.Point(176, 304)
Me.Button1.Name "Button1"
Me.Button1.Size New System.Drawing.Size(168,
64) Me.Button1.TabIndex 3
Me.Button1.Text "aDD THEM" '
'TextBox1 ' Me.TextBox1.Location
New System.Drawing.Point(416, 416)
Me.TextBox1.Name "TextBox1"
Me.TextBox1.Size New System.Drawing.Size(184,
20) Me.TextBox1.TabIndex 4
Me.TextBox1.Text "" '
'TextBox2 ' Me.TextBox2.Location
New System.Drawing.Point(424, 192)
Me.TextBox2.Name "TextBox2"
Me.TextBox2.Size New System.Drawing.Size(176,
20) Me.TextBox2.TabIndex 5
Me.TextBox2.Text "" '
39
'TextBox3 ' Me.TextBox3.Location
New System.Drawing.Point(424, 40)
Me.TextBox3.Name "TextBox3"
Me.TextBox3.Size New System.Drawing.Size(184,
20) Me.TextBox3.TabIndex 6
Me.TextBox3.Text "" ' 'Form1
' Me.AutoScaleBaseSize New
System.Drawing.Size(5, 13) Me.ClientSize
New System.Drawing.Size(672, 622)
Me.Controls.AddRange(New System.Windows.Forms.Cont
rol() Me.TextBox3, Me.TextBox2, Me.TextBox1,
Me.Button1, Me.Label3, Me.Label2, Me.Label1)
Me.Name "Form1" Me.Text "Form1"
Me.ResumeLayout(False) End Sub End
Region
40
Dim A, B, C As Integer Private Sub
Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles
Button1.Click C A B
TextBox1.Text Str(c) End Sub Private
Sub TextBox3_TextChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles TextBox3.TextChanged A
Val(TextBox3.Text) End Sub Private Sub
TextBox2_TextChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles TextBox2.TextChanged b
Val(TextBox2.Text) End Sub End Class
41
Overview
  • Architecture
  • Levels of software
  • Operating systems
  • Compilers
  • Libraries
  • Interfaces
  • Applications
  • The software development process

42
Applications
  • Few applications start from scratch
  • Use classes methods
  • Heres how to store the data
  • Heres how to manipulate the data
  • Use tools built by others
  • Use APIs to share information as objects among
    applications

43
Overview
  • Architecture
  • Levels of software
  • The software development process

44
Software development
  • In the small
  • Write specifications
  • Write code to realize the specifications
  • In the large
  • Write overall specifications
  • Break the task into pieces (modules)
  • Carefully design interfaces between modules
  • Have programmers work on individual modules

45
Software development tales
  • The mythical man month
  • There is no silver bullet
  • It isnt a bug, its a feature.
  • Dont break the build
  • If specifications are wrong
  • Machines behave differently. Same implementation
    on different machines can be different
  • IE vs Netscape
  • Side effects can be serious
  • If it aint broke, dont fix it
  • Remember backwards compatibility
  • Think ahead to forward compatibility
Write a Comment
User Comments (0)
About PowerShow.com