0% found this document useful (0 votes)
9 views18 pages

CS401 CH 14

The document discusses subroutines in computer architecture and assembly language programming, focusing on stack operations such as call and ret instructions. It explains how the stack pointer (SP) is manipulated during procedure calls and returns, detailing the push and pop operations for managing temporary data. Additionally, it covers the differences between intrasegment and intersegment calls and returns.

Uploaded by

18-QADEER AHMAD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views18 pages

CS401 CH 14

The document discusses subroutines in computer architecture and assembly language programming, focusing on stack operations such as call and ret instructions. It explains how the stack pointer (SP) is manipulated during procedure calls and returns, detailing the push and pop operations for managing temporary data. Additionally, it covers the differences between intrasegment and intersegment calls and returns.

Uploaded by

18-QADEER AHMAD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 18

CS-401

Computer Architecture & Assembly


Language Programming
Lecture-14
Subroutines
In the Last Lecture
Stack Analysis
Call
……………
SP 2000
014A: myproc: not ax
IP 0178
……………
CS 0464
0161: ret
……………
0178: call myproc
017B: mov ax, 10
……………
0 0 0 0 -SP
Call
……………
SP 1FEE
014A: myproc: not ax
IP 014A
……………
CS 0464
0161: ret
……………
0178: call myproc
017B: mov ax, 10
…………… 7B 01 -SP
00 00
ret
……………
SP 1FEE
014A: myproc: not ax
IP 017B
……………
CS 0464
0161: ret
……………
0178: call myproc
017B: mov ax, 10
…………… 7B 01
00 00 -SP
ret
……………
SP 1FEE
014A: myproc: not ax
IP 017B
……………
CS 0464
0161: ret
……………
0178: call myproc
017B: mov ax, 10
…………… 7B 01
00 00 -SP
call and ret far

call far
ret far
Other Stack operations

SP 9FFE
AX 2000

push
Pop
int
iret 00 20 -SP
00 00
Push and Pop
Other Stack operations

SP A000
AX 2000

push
Pop
int
iret 00 20
00 00 -SP
push
push decrements SP (the stack pointer)
by two and then transfers a word from
source operand from top of stack now
pointed by SP.
push often is used to place parameters
on the stack before calling a
procedure; more generally, it is the
basic means of storing temporary data
on stack.
Flags affected: NONE
push ax
push cs
pop
pop transfers the word at the current
top of stack (pointed to by SP) to the
destination operand and then
increments SP bt two to point to the
new top of stack.
pop can be used to move temporary
variables from the stack to registers
or memory.
Flags affected: NONE
pop ax
pop cs
call

Call activates an out-of-line


procedure, saving information on
the stack to permit a ret
(return) instruction in the
procedure to transfer control
back to the instruction following
the call.
call

For an intrasegment direct call,


SP is decremented by two and IP
is pushed onto the stack. The
target procedure’s relative
displacement from the call
instruction is then added to the
instruction pointer.
call

For an intra segment direct call,


SP is decremented by two and CS
is pushed onto the stack. CS is
replaced by segment word
contained in the instruction. SP
again is decremented by two. IP
is pushed onto stack and replaced
by the offset word in the
instruction.
ret

ret (return) transfers control


from a procedure back to the
instruction following the CALL
that activated the procedure.
Ret pops the word at the top of
the stack (pointed to by register
SP) into the instruction pointer
and increments SP by two.
ret

If retf (intersegment ret) is


used the word at top of the stack
is popped into the IP register
and SP is incremented by two.
The word at new top of stack is
popped into the CS register, and
SP is incremented by two.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy