Top Banner
Allocating Space for Variables Global data section All global variables stored here (actually all static variables) R4 points to beginning Run-time stack Used for local variables R6 points to top of stack R5 points to top frame on stack New frame for each block (goes away when block exited) Offset = distance from beginning of storage area Global: LDR R1, R4, #x Local: LDR R2, R5, #-y instructions global data run-time stack Device Registers x0200 xFFFF PC R4 R6 R5 x0000 xFE00 Vectors Op Sys x3000
46

Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Dec 19, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Allocating Space for Variables

• Global data section– All global variables stored here

(actually all static variables)– R4 points to beginning

• Run-time stack– Used for local variables– R6 points to top of stack– R5 points to top frame on stack– New frame for each block

(goes away when block exited)

• Offset = distance from beginning of storage area– Global: LDR R1, R4, #x– Local: LDR R2, R5, #-y

instructions

global data

run-timestack

Device Registers

x0200

xFFFF

PC

R4

R6R5

x0000

xFE00

Vectors

Op Sys x3000

Page 2: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Activation Record or Context Frame Format

Function stacked stuff

……..

……..

Local Variables

Caller’s Frame Pointer (R5)

Caller’s Return PC (R7)

Function Return Value

Function Pass Value n

……..

Function Pass Value 1

R6

R5

Page 3: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Interrupts:

1) Programmer Action: Enable Interrupts by setting “intr enable” bit in Device Status Reg

2) Enabling Mechanism for device: When device wants service, and its enable bit is set (The I/O device has the right to request service), and its priority is higher than the priority of the presently running program, and execution of an instruction is complete, then The processor initiates the interrupt

4) Process to service the interrupt: The Processor saves the “state” of the program (has to be able to return)

The Processor goes into Privileged Mode (PSR bit 15 cleared) Priority level is set (established by the interrupting device)The (USP), (R6) USP.saved register (UserStackPointer.saved)The (SSP.saved) R6 (SupervisorStackPointer)The (PC) and the (PSR) are PUSHED onto the Supervisor StackThe contents of the other registers are not saved. Why? The CC’s are cleared

5) The Processor Loads the PC from the Interrupt vector (vectors in 0100:01FF)

6) Interrupt Service Routine is executed Ends with an RTI

7) Program returns from Service routine The stored user PSR (POP into PSR), PC (POP into PC), (R6)SSP.saved, (USP.savedR6), and the next instruction fetched

Page 4: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Hardware Foundation

• Logic Gates

• Logic Chips

• Combinational Logic

• Timing

• Sequential Logic

• Flip Flops

• Registers

• State Machines

• Memory

Page 5: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Basic Logic Gates

Page 6: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Logic Threshold Voltage Levels

Page 7: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

CMOS Device - Inverter

p channel device

n channel device

CMOS Inverter

3-5 volts

Page 8: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

CMOS NOR Gate

NOR Gate

Page 9: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

CMOS OR Gate

OR Gate

Page 10: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

CMOS AND Gate

AND Gate

Page 11: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

2 BIT Decoder

Page 12: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Complete 74x139 Decoder

Page 13: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

74x138 3-to-8-decoder symbol

Page 14: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

2-to-1 MUX

MUX Circuit Case: S=0 MUX Symbol

Page 15: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

4-to-1 MUX

Logic

Symbol

Page 16: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

l

tt

F

D0

D1

D2

D3

D4

D5

D6

D7

A B C

A A B CB C

l

tt

ToggleButton1

l

tt

ToggleButton1

ToggleButton1

ToggleButton1

ToggleButton1

ToggleButton1

ToggleButton1

ToggleButton1

ToggleButton1

l

tt

ToggleButton1

l

tt

ToggleButton1

ToggleButton1

ToggleButton1

ToggleButton1

l

tt

ToggleButton3

ToggleButton3

ToggleButton3

ToggleButton3

l

tt

ToggleButton1

l

tt

ToggleButton1

ToggleButton1

ToggleButton1

ToggleButton1

l

tt

ToggleButton1

ToggleButton1

ToggleButton1

ToggleButton1

ToggleButton1

ToggleButton1

ToggleButton1

ToggleButton1

ToggleButton1

ToggleButton1

ToggleButton1

ToggleButton1

ToggleButton1

l

ttToggleButton1

ToggleButton1

l

ttToggleButton1ToggleButton1ToggleButton1

ToggleButton1ToggleButton1

ToggleButton1

ToggleButton7

l

tt

ToggleButton9

l

tt

l

tt

l

tt

l

tt

ToggleButton9ToggleButton7

ToggleButton1

ToggleButton

7

l

tt

ToggleButton1

ToggleButton1

8 to 1 MUX

Page 17: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Standard Symbols for Multiplexers

8 to 1 Vector(2) of 4 to 1 Vector(4) of 2 to 1

Page 18: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

1 Bit Full Adder

Page 19: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

4 Bit Full Adder

1 bit adder 4 bit adder

How many gate delays will it take before all of the outputs are correct?

Page 20: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Logical Completeness

• Can implement ANY truth table with AND, OR, NOT.

1. AND combinations that yield a "1" in the truth table.

2. OR the resultsof the AND gates.

ALSO:• Can implement ANY truth table with ONLY NANDS.

• Can implement ANY truth table with ONLY NORS.

Page 21: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Programmmable Logic Arrays (PLAs)

Page 22: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Programmable Logic Arrays (PLAs)

• Any combinational logic function can be realized as a sum of products.

• Idea: Build a large AND-OR array with lots of inputs and product terms, and programmable connections.– n inputs

•AND gates have 2n inputs -- true and complement of each variable.

– m outputs, driven by large OR gates•Each AND gate is programmably connected to each

output’s OR gate.– p AND gates (p<<2n)– designation is n x m, p ANDs

Page 23: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Example: 4x3 PLA, 6 product terms

--- X locates a fuse that can disconnect a line

Page 24: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Programmable Array Logic (PALs)

• How beneficial is product sharing?– Not enough to justify the extra fuse array

• PALs ==> fixed OR array– Each AND gate is permanently connected to a certain

OR gate.

• Example: PAL16L8

Page 25: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

• 10 primary inputs

• 8 outputs, with 7 ANDs per output

• 1 AND for 3-state enable

• 6 outputs available as inputs– more inputs, at expense of

outputs– two-pass logic, helper terms

• Note inversion on outputs– output is complement of

sum-of-products– newer PALs have selectable

inversion

Page 26: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

GAL16V8C provides optional inversion via XOR gate

close-up on next slide -->

Page 27: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.
Page 28: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Designing with PLAs

• Compare number of inputs and outputs of the problem with available resources in the PAL

• Write equations for each output using programming language like ABEL (Xilinx)

Page 29: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Alternative Logic “Family” Choices

• Totempole: High or Low output level (Most Common)

Line always at a 1 level or 0 level

• Tristate: High, Low, or Open (Good for BUS application)

Like Totempole, but has third state – open state

• Open Collector, Open Drain, Wired-OR: (Older alternative to Tristate – still used, but more susceptible to noise)

Line is nominally at a 1 level or 0 level – line is “pulled” to non-nominal level.

Outputs of and gates can be connected directed together to create an “OR condition.

• Differential: (Used for driving signals a distance. Good noise immunity)

Uses a pair of lines – the “level” is the difference of signals on the two lines.

Page 30: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Timing Diagram ConventionsTiming Diagram Conventions

Page 31: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Synchronous Timing Diagram

Page 32: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Asynchronous Timing – Read Diagram

Page 33: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Asynchronous Timing – Write Diagram

Page 34: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Combinational vs. Sequential Circuits

• Combinational Circuit– always gives the same output for a given set of inputs

• example: adder always generates sum and carry,regardless of previous inputs

• Sequential Circuit– has memory - “stores” information,– output depends on stored information (state) plus input

• so a given input might produce different outputs,depending on the stored information

– example: ticket counter• advances when you push the button• output depends on previous state

– useful for building “memory” elements and “state machines”

Page 35: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Basic SR Flip Flop

Nor Gates:

Nand Gates:

a 1 on S or R sets/resets the FF

a 0 on S or R sets/resets the FF

S R | Qn+1

0 0 | Qn

0 1 | 0

1 0 | 1

1 1 | Indeterminate

S R | Qn+10 0 | Indeterminate0 1 | 11 0 | 01 1 | Qn

Page 36: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Clocked SR Flip Flop

S, R are nominally 0, a 1 on S or R will set/reset the FF AFTER the Clock Pulse

S R | Qn+10 0 | Qn0 1 | 01 0 | 11 1 | Indeterminate

Page 37: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

D Flip Flop (D Latch)

D | Qn+10 | 01 | 1

Page 38: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Positive Edge Triggered Flip Flop(7474)

Page 39: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Master Slave Flip Flop

Master sets on rising edge of CP,

Slave sets on falling edge of CP.

(or visa versa depending on the particular Master Slave)

Page 40: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Toggle Flip Flop

Toggles on CP when T =1

T | Qn+10 | Qn

1 | not Qn

Page 41: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

JK Flip Flop

J K | Qn+10 0 | Qn

0 1 | 01 0 | 11 1 | not Qn

Page 42: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

JK as a Universal Flip Flop

JK as an SR – use set and pre inputs

JK as a Toggle – connect J and K

JK as a D – connect NOT J to K

Page 43: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

Register

• A register stores a multi-bit (vector) value.– We use a collection of D-latches, all controlled by a common write

enable pulse, call it WE.– When the write enable WE=1, the n-bit value D is written to register.

Page 44: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

More Memory Details

Two basic kinds of RAM (Random Access Memory)

• Static RAM (SRAM)– fast, maintains data as long as power applied

• Dynamic RAM (DRAM)– slower but denser, bit storage decays – must be

periodically refreshed. Refreshing interferes with regularity of execution of instruction stream.

Also, non-volatile memories: ROM, PROM, flash, …

Page 45: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

TCSS372A - HW1 (due October 7)

int main (){ int a = 23; int b = 14; ... /* point 1 */ b = Watt(a); /* point 5 */ b = Volta(a,b); ... /* point 7 */} int Watt(int c);{ int w = 5; ... /* point 2 */ w = Volta(w,10); /* point 4 */ ... return w; }

int Volta(int q, int r) { int k = 3; int m = 6; ... /* point 3 & point 6 */ return k+m;}

1) Memory Map & Activation Records: Show the memory map during execution of the following program at point 1 , and the stack at points 1 through point 7.

Page 46: Allocating Space for Variables Global data section –All global variables stored here (actually all static variables) –R4 points to beginning Run-time stack.

HW 1

2) State System Design: Design a “blinking” traffic sign which exhibits the following behavior:

– Repeat the following sequence as long as operate switch is turned on:

State 1: No lights on State 2: 1 & 2 on State 3: 1, 2, 3, & 4 on State 4: 1, 2, 3, 4, & 5 on

- The system is in state 1 when the operate switch is off

DANGERMOVERIGHT

1

2

3

4

5