You are on page 1of 2

Assignment No.

Total Marks: 15
CS401-Computer Architecture & Assembly Language Programming Due Date: 11/04/07

Please read the following instructions carefully before submitting assignment:
o The assignment is submitted after due date.
o The submitted assignment does not open or file corrupt.
o The assignment is copied.
name of file is other than student ID.

Note: For any query about the assignment, contact at

Marks: 15
Question: Marks [5+10 = 15]

1. Replace the following invalid instructions with a single instruction that has the same effect.
a. pop ip
b. mov ip, L5
c. sub sp, 2
mov [ss:sp], ax
d. mov ax, [ss:sp]
add sp, 2
e. add sp, 6
mov ip, [ss:sp-6]

a. ret
b. jmp L5
c. push ax
d. pop ax
e. call

2. Write a recursive function to calculate the fibonaccii of a number. The number is passed as a parameter
via the stack and the calculated fibonaccii number is returned in the AX register. A local variable should
be used to store the return value from the first recursive call. Fibonaccii function is defined as follows:
fibonaccii(0) = 0
fibonaccii(1) = 1
fibonaccii(n) = fibonaccii(n-1) + fibonaccii(n-2)

Following is the function that must be called in the program to return the Fibonacci of the number passed as
fibonacci :

push bp
mov bp,sp
sub sp,2 ;creat local variable

mov bx, [bp+4] ; get passed argument

cmp bx,0 ; if num<=0

jle return0 ; fibonacci=0

cmp bx,1 ; if num==10

je return1 ; fibonacci=1
; else
dec bx
push bx ;cleared by ret 2
call fibonacci

mov [bp-2],ax ;save ax, in local var

mov bx, [bp+4] ; get passed argument

sub bx,2
push bx ;cleared by ret 2
call fibonacci

mov dx,[bp-2] ;get previous val of ax, saved above

add dx,ax
mov ax,dx ; return fibonacci in ax
jmp retfromfunc
mov ax,0
jmp retfromfunc

mov ax,1

mov sp,bp ;restore sp-2, which was done for local variable
pop bp
ret 2 ;clear the stack (discard bx, pushed b4 calling this proc)

Note: This Assignment covers Lecture# 07 to 15.

Your assignment must be uploaded/submitted at or before Wednesday 11 April, 2007.