{Mid Semester} {End Semester} {Quizzes} {Assignment} {Project} [Teaching @ PUCSD] [Home]

Mid Semester Examination
(25 February 2003, 150 Minutes)

Please Note :

  1. NASM syntax is used in this paper and same should be used in your answers.
  2. Bit numbering starts from right; rightmost bit being "bit number 0" .
  3. The numeric values mentioned in paper are by default hexadecimal values if not mentioned otherwise.
  4. Exam is open "hand-written notes and books".


  1. Define a macro FZFR, that takes two doubleword arguments and places the "bit number of first zero bit from right in first argument" OR "-1" if all bits in first argument are non-zero, into second argument. It does not matter if original argument values are destroyed, but this macro should be safe enough to be called from anywhere in the code. It is also fine if your solution works only on 80486 onwards processors.

    Now we want to define another macro FZFL to find the bit number of first zero bit from left. Being lazy, I define it as -

    %macro FZFL 2
    BSWAP %1
    FZFR %1, %2
    %endmacro

    Will this work correctly? Justify your answer.

  2. Justify true/false - "On Pentium machines having 64-bit data bus, a 16-bit word can always be accessed in one memory cycle.".

  3. Consider an 80x86 processor operating in Real mode. Given the address "1010:F034", give the corresponding Physical and Normalised addresses.

  4. Given that 80486 processor is operating in protected mode.

    EBX = 3456, ESI = 00010, DS = 0008, SS = 0014

    first 24 bytes of LDT are --
    00,00,00,00,00,00,00,00,FF,00,00,00,10,92,00,10,00,06,00,10,10,96,11,00

    and first 24 bytes of GDT are --
    00,00,00,00,00,00,00,00,FF,FF,00,00,10,92,00,00,FF,20,00,10,10,82,00,11

    Compute the Effective and Physical Address for memory operands in each the instructions below. Which of these instructions will execute successfully? Justify your answer.

    1. mov edx, [ebx*2+esi+40H]
    2. mov [SS:ebx+esi+400H], eax

    Are given LDT and GDT entries sensible for 80286? Justify your answer.

  5. While browsing internet, at times we come across URLs, once we access them, no matter how many times we click button we can't get rid of them from our browser (i.e. same URL gets loaded again and again even when we click on button to go back to previous URL we accessed), till we kill the brower completely.

    We are interested in modifying an existing assembly function (near function) such that once this function is called we end up in similar situation, even though we return from this function. Can this be done? If no, why not?

    If yes, how? Justify, whether your solution will work independent of processor's operation mode (Real/Protected).

  6. Which flags does 80x86 use to test the following conditions? How must the flags be set for the conditions to be true?

    "Less than" , "Not Above Equal"

  7. Give the result and value of condition flags for "5439 - 456A" .

  8. If RET instruction was not available, how will you return from a near function? Give the exact sequence of instructions that you will use in place of RET instruction.

  9. We need to in-place convert, characters in an array of 60000 EBCDIC characters to corresponding ASCII characters. Give logic, and sequence of assembly instructions to implement it, for a fast solution to accomplish the task.

  10. Differentiate b/w Modular and Saturation arithmetic with suitable example(s). Does Intel x86 architecture provide support for both? If yes, in what way,?

  11. Give Packed and Unpacked BCD equivalents of following decimal numbers, in decimal, separating different bytes with a comma in your answer.

    3512, 12097

  12. Explain "Critical Expression" in NASM, with suitable examples.

  13. What are "Program Invisible Registers"? What are they used for?

  14. Given a 32 bit unsigned integer value (A354BFC3), represent it as single precision float value. Are there any discrepancies introduced in represented value in this conversion from int to float? if yes, what/why are they?

  15. Indicate, which segment registers will be used in each of the following instructions --

    1. add eax, [esi+ebp]
    2. add eax, [esp+ebx]
    3. mov eax, [ebp*4+eax+20H]
    4. mov eax, [ds:esp+ebx]

  16. Compute the encoding for following instructions, considering default as "32 bit instruction mode".

    1. mov [ebp], eax
    2. mov eax, [5000H]
    3. mov ax, [es:bx+si]
    4. mov bx, [ax]

  17. Compare and contrast "%assign" and "%xdefine" directives of NASM preprocessor.

  18. What is meant by "Denormalised number" in floating point representation. Explain with suitable example(s).


End Semester Examination
(26 April 2003, 180 Minutes)

Please Note :

  1. Questions in this paper are specific to INTEL x86 chips/ MS-DOS 6.22/ NASM.
  2. Junk answers/ wild guesses might fetch you negative credit. Read the question properly before you attempt answering, it might save a lot of effort/time.
  3. If needed, you can refer to your own handwritten notes. Xeroxes/ printouts/ books/ sharing-of-notes is strictly not allowed.
  4. Answers to all the parts of a question should be written contiguously.


  1. State true/false with brief justifications ---

    1. 8 bit microprocessors can only deal with 8 bit data types.
    2. Limitation of 'segments have to begin at paragraph boundary' is lifted in protected mode.
    3. One can not execute interrupt 21h if interrupt flag (IF) is set to 0.
    4. When an 8086 machine is switched on, it executes first instruction from physical address 0000FH.
    5. Environment block associated with program contains the fully qualified file name of the corresponding executable.
    6. Consider the following segment definition --

      segment data
      var1 db 5
      m2 equ 'a'
      m3 equ 10
      var2 db m2,m3

      Offsets of variables var1 and var2 wrt beginning of data segment are 0 and 3 respectively.

  2. Suppose that 64 bit Pentium machines were made 'word addressable' instead of current 'byte addressable'. How will the 64 bit integer 1234567890123456H be represented in memory?

  3. Suppose 'ROL' instruction wasn't supported by NASM. Define a transparent macro that will allow it to assemble source code with 'ROL' instructions, w/o changing the meaning of the intended code.

  4. Give exact registers that you will need to save/restore in setjmp/longjmp calls respectively, to provide support for continuations in assembly/C. Justify your answer.

  5. MS-DOS is not the only non-reentrant code that a TSR might want to call. The PC's BIOS routines also fall into this category. Unfortunately BIOS does not provide a 'BIOS-BUSY' flag or a multiplex interrupt.

    How will you prevent reentering a BIOS routine. Give code fragment to support your solution. Use 10h (video services) as the example BIOS interrupt in your answer.

  6. Give the code fragment, for a .COM program, execution of which sets ES:BX to point to name (max 8 characters) of the currently executing program.

  7. Give the sequence of steps, MS-DOS follows for a typical I/O request.

  8. A file of size 5.5 Kbytes is allocated contiguous clusters, starting from cluster no. 320H. Give FAT16 entries corresponding to clusters in closed range 320H-330H when ---

  9. We need to kickstart a simple screen saver automatically every time when system goes idle. Give a solution to accomplish this.

  10. We are switching from real mode to protected mode on an 80286 machine and intend to use same interrupt handlers in protected mode also. Code for these handlers resides in 36 Kbytes area starting from physical address 4000H.

    Give the interrupt descriptor for interrupt vector 0, and also LDT/GDT descriptor(s) if required for complete answer. Consider that ---

  11. Many of you have used macros like below, to print message from your program.

    Write "hello world",10,13

    Give the NASM implementation of above macro. Are there any issues with your implementation? Indicate those.

  12. TLINK provides an option to link one/more .OBJ files into single .COM file, so that you don't have to include multiple .ASM files into one .ASM file to generate a .COM file via NASM or any other assembler.

    Illustrate using small .ASM file(s), how to write code so as to be able to link .OBJ file(s) into .COM file via TLINK. Indicate the crucial aspects of this very 'clearly and correctly'.

  13. We need to write a program that converts .COM files to corresponding .EXE files w/o changing the functional/executional behaviour of the original executables. The straight solution that comes to mind is to construct a suitable EXE header and prepend it before the original COM file content.

    1. Compute the EXE header for 'mycom.exe' that is generated out of 'mycom.com' sized 2000 bytes.
    2. Is current scheme going to work for all the COM programs? If you think NOT, then --
      • point out this category of COM programs, explaining why(s) behind it.
      • give the modified solution that will work for any COM program. Use the same input as in (a), for your computations.


Quizzes

Quiz #2

Why should interrupts be kept disabled till stack is setup properly (i.e. SS and SP are set to proper values)?

Quiz #3

What is the size of smallest, valid .COM program that will execute properly (i.e. w/o hanging/trashing the operating system)? Justify your answer technically.

Quiz #4

How many valid instruction encodings are possible for a valid mov instruction where both the operands are registers? Justify your answer.

Quiz #5

What will be the output of given program, when compiled and executed successfully? Justify your answer technically. Give the values in output completely and correctly.

#include 

union tryme {
	int x;
	float y;
} avar;

int main()
{
	float f2;

	avar.y = 0.25f ;
	f2 = avar.x ;

	printf("avar.y = %f\n", avar.y);
	printf("f2 = %f\n", f2);

	return 0;
}

Assignment #1

Sort finite number of 64 bit signed numbers using quicksort algorithm.

Course Project

Build an enhanced 'doskey' program (henceforth referred to as doskeyim) where command history can persist across machine bootups, loading/unloading of doskeyim.

Following features will be required in doskeyim, to meet the requirments --

  1. Indicating the history file

    Your program will have a default name/location for history file, but that can be overridden via "/F filename" command line option or via "HISTFILE" environment variable.

  2. Indicating the number of most recent commands to be saved

    Your program will have a default value for number of recent commands to be saved, that can be overridden via "/L no.-of-recent-commands-to-be-saved" command line option or via "HISTFILESIZE" environment variable

  3. Indicating the periodic time interval (in minutes)

    Since first loading of doskeyim, at the end of evey period, required number of most recent commands in command history will be save in the history file.

    Your program will have a default value for this also, that you should choose reasonably, this value can be overridden either via the command line option "/T periodic-time-interval" or via environment variable "HISTSAVEINTERVAL".

    You should arrive at a comfortable periodic time-interval-value based on other specified parameter values and in case you find that user has asked for a value less than that arrived-at value, issue a message to user and continue with your arrived-at value.

  4. Since doskeyim will be a tsr program, we will have a command line option "/U" to unload it .

  5. Another command line option "/?" that will display brief information about doskeyim usage, mentioning each of following, as applicable.

Please Note :


Created on January 28, 2006