0% found this document useful (0 votes)
10 views

Assembly Language Assesment

Uploaded by

221370151
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Assembly Language Assesment

Uploaded by

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

ASSIGNMENT 3

M. Muneeb Ur Rehman
221370154 CS-248
Q#1:

Stack:
It is a data structure that works on First in Last out (FILO) principle. The data pushed on stack
first is retrieved at last.

When a subroutine is called, the CPU pushes the current execution context onto the stack. This
includes the return address, parameters, and local variables. When the subroutine completes its
execution, the CPU pops the context off the stack, restoring the previous state. This mechanism
ensures that each function call has its own space in memory, preventing interference between
different function calls.

Push: Adding an item on the top.


Pop: Removing an item from the top.

Two Ways to Move Data on Stack:


1. Using sp.
2. Using bp.

• To move into the stack using SP, you increment or decrement the stack pointer directly.

• BP is often used to access parameters and local variables within a function.


• Adjusting BP allows for referencing variables based on a fixed offset within the current
stack frame.
• While SP is directly manipulated for stack operations, BP provides a stable reference for
accessing variables within the current function's stack frame.
bp
FFF6 In the attached screenshots you can see that on these addresses same values are stored.
Return
address FFF8 .
Size =
6 FFFA
Data
label FFFC
address
FFFE

Q#2

[org 0x0100]
jmp start
series:dw 0,0,0,0,0,0,0,0
size:dw 8
CreateSeries: push bp
mov bp, sp
push ax
push bx
push cx
push dx
push si
mov cx, [bp + 4]
mov bx, [bp + 6]
mov si,0
mov ax,1

mov word[bx+si],ax
sub cx,1

seriesLoop: add si,2


shl ax,1
mov[bx+si],ax

addOne: mov dx,4


cmp si,dx
je addOneMethod
add dx,6
cmp si,dx
je addOneMethod
jmp seeNext
addOneMethod: add ax,1
mov word[bx+si], ax

seeNext: dec cx
jnz seriesLoop

pop si
pop dx
pop cx
pop bx
pop ax

pop bp

ret 4
start: mov ax, word[size]
mov bx, series
push bx
push ax

call CreateSeries

mov ax, 0x4c00


int 0x21

Stack:

Si
FFEC Dx
FFEE Cx
FFF0
Bx
FFF2
Ax
FFF4
Bp
FFF6
Return
FFF8
address
FFFA Ax
FFFC Bx

FFFE

You might also like