09.12.35 Uppbygging tölva

Programming project 4


This time you are to solve a few smaller programming projects in assembly language. They are mostly old exam problems and are representative of the type of assembly language programming that you have to do in the exam.

On the exam you will not have access to a computer, so you should first try to solve the problems on paber, before entering them and trying out.

  1. Consider the following 8086 program:
                    clc
            upp:    mov     ax, [si]
                    adc     [di], ax
                    inc     si
                    inc     si
                    inc     di
                    inc     di
            loop    upp
      
    Answer the following questions on the code:

    a) Describe what the program does (with words or in pseudocode).

    b) Why is the instruction inc used to increment si and di, instead of adding 2 with the command add?

  2. [Exam '98]
    1. Below is a program to copy CX bytes from DS:SI to ES:DI. Explain carefully the purpose of each instruction
      	shr       cx, 1
      	rep movsw
      	adc       cx, cx
      	rep movsb
         
    2. Explain what the following program does. (Hint: The total size of the instructions from L1 down to the end of the program is 20 bytes)
      		lea	di, L1
      	L1:	mov	cx, 10
      		mov	bx, di
      	L2:	mov	ax, [cs:di]
      		mov	[cs:di+100], ax
      		add	di, 2
      		loop	L2
      		add	di, 80
      		jmp	bx
         

  3. [Exam 2000] Explain what the following 8086 program does. The input is in BX and the output in AX.
    		xor	ax, ax
    		mov	cx, 16
    	lyk:	ror	bx, 1
    		rcl	ax, 1
    		loop	lyk
      

  4. [Exam 2000] Write the for loop in the following C++ function by using inline IA-32 assembly language in Visual C++. You do not have the rewrite the head of the function, the declaration, the input statement, or the return statement.
    	double fall( ) {
    	    double x;
    	
    	    cin >> x; 
    	    for(int i=0; i<100 && x<100.0; i++)
    	        x = 1.3 * x;
    	
    	    return x;
    	} 
      

  5. Write the following program in IA-32 assembly language with floating point instructions so that the code could be placed inline in a C++ program. Assume that a and b are defined as double variables:
    	if ( a <= 10.0 )
    	    b = 5.0*a;
    	else
    	    b = b - a/2.0;
      

Hand in answers and printouts to Páll's box in VR-II on thursday november 8th.

hh (hja) hi.is, october 31st, 2001.