• No results found

PROGRAMMING CONCEPTS AND EMBEDDED PROGRAMMING IN C, C++ and JAVA: Lesson-4: Data Structures: Stacks

N/A
N/A
Protected

Academic year: 2021

Share "PROGRAMMING CONCEPTS AND EMBEDDED PROGRAMMING IN C, C++ and JAVA: Lesson-4: Data Structures: Stacks"

Copied!
21
0
0

Loading.... (view fulltext now)

Full text

(1)

PROGRAMMING CONCEPTS AND

EMBEDDED PROGRAMMING IN

C, C++ and JAVA

:

(2)

A structure with a series of data

elements with last sent element

waiting for a delete operation.

-

Used when an element is not to be

accessible by the index with pointer

directly, as in an array, but only

through LIFO (Last in first out)

mode through a stack-top pointer.

STACK

(3)

-

A data-element can be pushed

(inserted) only at the from front

(stack-head) in the series of

elements waiting for an operation

and popped (deleted) also from front

(stack-head).

Push and Pop onto a

(4)

-

There is only one pointer, for

deleting after the read operation

from stack-top and other for

inserting at stack-top. Pointer if

increments after a push operation

then it decrements after a POP

(5)

Standard Functions used in a Stack

1.

SELInsert – Pushes a data-element

into the stack as pointed by item and

increment the item pointer address

2.

SELReturn – Pop an element from

the stack as pointed by *item and

the element deletes from stack on

decrement in the item pointer

address

(6)

3.

isSNotEmpty– Return true or false

after the check for the stack not

empty.

(7)

Stack Pointer

Stack Pointer

SP (stack pointer): SP is pointer to a

memory block dedicated to saving the

context on context switch to another ISR or

routine.

(8)

Stack Pointer

Stack Pointer

Each processor has at least one stack pointer

so that the instruction stack can be pointed

and calling of the routines can be facilitated

In some processors, RIP (return instruction

pointer)─ a register for saving the return

address of the program counter when a

routine calls another routine or ISR.

RIP is also called link register (LR) in ARM

processor

(9)

A stack due to nested function calls and

A stack due to nested function calls and

pushing of program counters

(10)

A program

A program

-

-

thread stack having pointers and

thread stack having pointers and

parameters pushed on to stack before the

parameters pushed on to stack before the

context switch

(11)

FP (data frame pointer)

FP (data frame pointer)

A pointer to a memory block dedicated to

saving the data and local variable values

FIP in certain processors

(12)

PFP (previous program frame pointer)

PFP (previous program frame pointer)

A pointer to a memory block dedicated to

saved the program data frame, in certain

processors

(13)

Multiple stack frames for Multiple Threads

Multiple stack frames for Multiple Threads

OS defines processes or threads such that

each process or thread is allocated one one

task stack pointer or thread stack pointer

(14)

Multiple stacks of multiple tasks or threads

Multiple stacks of multiple tasks or threads

pushed on the stacks with each having

pushed on the stacks with each having

separate pointer

(15)

Multiple stacks of CPU registers for the

Multiple stacks of CPU registers for the

multiple tasks which are pushed on to stack

multiple tasks which are pushed on to stack

before context switches

(16)

Motorola MC68010 processor

Motorola MC68010 processor

USP (user Stack Pointer) and SSP

(Supervisory Stack Pointer).

Program runs in two modes: user mode and

supervisory mode.

In supervisory mode the operating system

functions execute.

Switch from user mode to supervisory mode

after every tick of the system clock

(17)

MC68040

MC68040

USP (User Stack Pointer), SSP (Supervisory

Stack Pointer), (MSP) Memory Stack

frames pointers, and Instruction Stack

Pointer (ISP).

(18)

Application Examples

1.

Ease in saving of the data-elements

in case of interrupts or function calls

2.

Nested set of operations like

function calls

3.

A program thread, which blocks

pushes on the stack and then the last

pushed thread pops first.

(19)

Summary

Summary

(20)

We learnt

Using of stack is very helpful for

saving the data in case of interrupts

or function calls.

Stack related functions are

'constructing' a stack, 'pushing' an

element into it, popping an element

from it and 'destruction' of stack.

(21)

End of Lesson 4 of Chapter 5

References

Related documents

Executing the instruction PUSH {R0} first decrements the stack pointer by four, so register SP is now 0x2000.03FC and stores the value 0x6B onto the stack at memory

• The directive performs a direct text substitution of all future examples of name with the replacement-text for the remainder of the source file. • The name has the same constraints

In conclusion, the RCSA believes a Framework for Collaboration will provide the basis for effective and outcomes focused collaboration between private recruitment agencies

A Mixed Integer Linear Programming (MILP) model is developed to determine the best location to place the abovementioned biorefinery and to determine the tactical and

SP points to location last item placed in block SP points to location last item placed in block SP SP decreases decreases when you put an item on the stack when you put an item on

StackOfStrings() create an empty stack void push(String s) insert a new item onto stack String pop() remove and return the item!. most recently added boolean isEmpty() is the

argument: str return address stack frame pointer.

Top of Stack pointer to the last item place on the stack for the task Task State list item used to place the TCB in ready and blocked queues.. Event List list item used to place the