Friday 16 February 2018


CENG 222 – Computer Organization
Lab Work 7

CALL and RET instructions

CALL instruction is used for calling a subroutine/procedure/function.
Usage:

CALL <address or procedure name>

RET instruction is used for returning back to caller procedure from the called procedure. RET has no arguments. Analyze the code given in experiment.

Using stack

Stack is used for temporarily storing data to memory. It is also used by CALL and RET to store caller instruction address. Hence, it is critically important to use stack properly:
Leave stack as how you find!
It means that you need to get all the data out which you store in the stack. Do not forget any data in the stack. You can use it temporarily!

PUSH instruction stores a data in the stack.

PUSH <word data or word register>

POP instruction retrieves a data from the stack.

POP <word memory block or word register>

Examples:

PUSH AX
POP BX


EXPERIMENTS
1)
Write the following C code in assembly using no jump instructions (use loop command instead) You should not use other registers to store the value of CX temporarily. You should use the stack properly to store the value of CX properly.
Hint: Don't forget that loop command only operates on CX and to use a inner loop you must remember the value of CX for the outer loop at each iteration.

int b =0;
for(int i=0; i<5;i++)
            for(int j=0; j<10;j++)
                        b = I + 2*j;
2)
Write an assembly function that calculates factorial. Use the function to calculate 3! and 5!.

3)
Write an assembly program that calculates first 10 Fibonacci numbers. Numbers should be observed in dx consequently (since we did not learn how to print at the moment we can simulate it by observing the register in emulator).
Hint: Use the stack to reverse the order. Once you have pushed all the items, pop command will give you the last item.

No comments:

Post a Comment