Lecture 7 stack operations and introduction to procedure
This presentation is the property of its rightful owner.
Sponsored Links
1 / 13

Lecture 7 Stack Operations and Introduction to Procedure PowerPoint PPT Presentation


  • 79 Views
  • Uploaded on
  • Presentation posted in: General

Lecture 7 Stack Operations and Introduction to Procedure. Modified and Presented By Dr. Rajesh Palit Asst. Professor, EECS, NSU Originally Prepared By Dr. Shazzad Hosain , EECS, NSU. Stack vs. Queue. Stack LIFO : Last In First Out Queue FIFO : First In First Out. Queue. Stack.

Download Presentation

Lecture 7 Stack Operations and Introduction to Procedure

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Lecture 7 stack operations and introduction to procedure

Lecture 7Stack Operations and Introduction to Procedure

Modified and Presented By

Dr. Rajesh Palit

Asst. Professor, EECS, NSU

Originally Prepared By

Dr. ShazzadHosain, EECS, NSU


Stack vs queue

Stack vs. Queue

  • Stack

    • LIFO : Last In First Out

  • Queue

    • FIFO : First In First Out

Queue

Stack


Push vs pop in stack

PUSH vs. POP in Stack


Stack operations

Stack Operations


Push instructions

PUSH Instructions


Pop instructions

POP Instructions


Lecture 7 stack operations and introduction to procedure

Stack example


Introduction to procedures

Introduction to Procedures

  • Way to implement top-down programming approach

  • Procedure declaration

    name PROC type

    RET

    name ENDP

  • Some other place the procedure is called by

    call name

  • Type can be FAR or NEAR, and it is optional, in absence of type NEAR is assumed

  • NEAR indicates that the calling statement is in the same segment, FAR implies different segment


Procedure contd

Procedure contd.

  • The RET instruction causes control to transfer back to the calling procedure.

  • Every procedure, except the MAIN procedure should have a RET someplace, and usually it’s the last statement in the procedure

  • A procedure must have a way to receive values from the caller, and a way to return results

  • In assembly language, there is no parameter lists, so it’s up to the programmer to devise way to communicate

  • In case of a few parameters, registers are fine to pass values


Procedure example

Procedure Example

Product = 0

REPEAT

IF lsb of B is 1

THEN

product = product + A

END_IF

Shift left A

Shift right B

UNTIL B = 0


Passing data between procedures

Passing Data Between Procedures

  • Using Global Variables

  • Through Register (call by values)

  • Passing the address of the data

  • Using the stack

    • Suitable for recursive procedure

    • Used by high-level programming languages

  • Procedure calling starts by pushing the return address on the stack


Using bp for accessing stack

Using BP for Accessing Stack

MOV AL, a

PUSH AX

MOV AL, b

PUSH AX

CALL addnos

(original BP)

return address

data 1

data 2

data n

SP, BP

addnos PROC NEAR

PUSH BP

MOV BP, SP

MOV AX, [BP+6]

ADD AX, [BP+4]

POP BP

RET 4

addnos ENDP

SP, BP


References

References

  • Chapter 8 and Chapter 14 – Assembly Language Programming by Charles Marut


  • Login