Tut3 assemblyLangProgramming

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

1 Tutorial 3 Assembly Language Programming 1. (a) Write a MIPS assembly language program which is to i. ii. iii. iv.

. read an integer in a local variable inp through the prompt: Feed an integer:, nd the number of ones in its internal representation by a function store the count (returned by the function) in a local variable count1 and print the following text : The number of ones in the internal representation of ... is ....

(b) Write the corresponding C main function and the function subprogram for ease of understanding or adequate comments in the assembly language program; in the latter case, identify the mapping of the local variables with their address expressions. Note that local variables must be allocated on the stack. Allocation is by providing for the required number of bytes on the stack (by decreasing the stack pointer value, if the stack grows towards the lower memory). Access is with respect to the frame base pointer. Space allocated on the stack must be released (by increasing the stack pointer) before returning from the function. 2. Write a MIPS program which (a) reads a set of ten integers into a local array and (b) computes their sum, the minimum element and the maximum element by means of a function, (c) prints the array elements and these values (returned by the function) with proper prompt message(s). Ensure readability of the program by either writing a coresponding C program or putting meaningful comments as indicated in the previous problem. 3. Write a MIPS assembly langauage program which (a) reads two integers n and r in two local variables, (b) computes n Cr using a recursive function which uses the following formula n Cr =n Cr1 +n1 C r1 , (c) prints the original values of n and r and the returned value n Cr using proper prompt. Ensure readability as before.

You might also like