2022 - Midterm 2 Solution - Spring - COAL
2022 - Midterm 2 Solution - Spring - COAL
i. [3 marks] Consider a subroutine fibo that uses the stack to pass the parameters, and to return the
output values. The pseudocode for the subroutine is as follows:
In order to call the subroutine, you have to pass a parameter (size = 1 word), and return a result (size =
1 word). Write some assembly language statements that are required before and after calling this
subroutine.
ii. [4 marks] Suppose that AX=0x1122, BX=0x0100, CX= 0x2341, and SP=0xffff. Give the contents of AX, BX, and SP
after executing the following instructions:
AX BX SP
iii. [3 Marks] Consider the code given below and information on when keyboard was pressed during the
execution of this code, write out the sequence in which the instructions are executed. Each
executable instruction in code is numbered so your answer should be as follows:
Sample answer:
Instructions executed in following order
I11
I6
….
You also have to briefly explain the working of the program.
I6 in al, 0x60
I7 cmp al, 0x2a
I8 jne nextcmp
I16 pop es
I17 pop ax
I18 iret
Solution: In the first five rows, the data displayed on the first 10 video memory cells is copied onto
the next 10 video memory cells.
Question 2 [15 Marks]: Draw a rectangle with the help of two given points i.e. A (xA, yA) and B (xB, yB).
i. [4 Marks] Before printing the rectangle, check that yA must be less than yB and xA must be less than xB.
iii. [8 Marks] Write a subroutine to print the boundary of the rectangle with blue dollar characters (ASCII= 24-
Hex,36-Decimal), and to fill red color inside of rectangle. Please note that the parameters should be
passed
through the stack.
Example 1:
Input: A (7, 8) and B (10, 11)
Output : (7,8)
$ $ $ $
$ $
$ $
$ $ $ $
(10,11)
Example 2:
Input: A (10, 11) and B (7, 8)
Output: No printing on screen