Name:_______________________

 

INEL 4206 Final Exam

Spring 2008

May 13, 2008

 

Open book and notes.  Only the text copies, instruction sheet handout, slide printouts and your own notes may be used.  In the interests of originality and creativity please turn off all electronic communication devices including celulares, laptops, and pocket computing devices

A copy of the instruction set for the 80X86 family and the MIPS are included on separate sheets.

1.      This problem relates to division and multiplication in both processors

a.       The machine (not pseudo) divide and instructions in MIPS have two arguments..  The pseudoinstructions have three.  In the 80x86 they have only one.

i.        What are the destination registers and sizes in MIPS, and also in the 80x86 family- for integer arithmetic?

MIPS – registers LO and HI – both 32-bit
80x86 – 16 bit operations – DX, AX, both  are 16-bit
80x86 – 8bit operations – AH, AL, both  are 8-bit

ii.      Can multiplicative or divide overflow.(as opposed to division-by-zero) occur in MIPS in the machine (as opposed to pseudo-) instructions.  Explain.

No, the HI-LO pair act as a single 64-bit register, and the product of two 32-bit numbers fits inside 64 bits in signed and unsigned.

iii.    Two’s complement add/subtract and unsigned unsigned add/subtract are the same instruction and operation in any computer that supports this integer format.  What instruction do you use to branch on overflow in 80x86?overflow (incorrect result)? Answer for both signed and unsigned arithmetic.

Unsigned is JC (jump on carry)
Signed is JO (jump on overflow)

 
 DISP  PROC  NEAR

      PUSH  CX          ;save CX

      MOV   CX,4        ;set up loop counter

NYBL: ROL   AX,1        ;get upper nybble of AX

      ROL   AX,1

      ROL   AX,1

      ROL   AX,1

      PUSH  AX          ;save AX

      AND   AL,0FH      ;mask out upper nybble

      ADD   AL,30H      ;add ASCII bias

      CMP   AL,3AH      ;are we greater than 9?

      JC    NO7         ;no, go save digit

      ADD   AL,7        ;correct to hex-alpha

NO7:  MOV   [DI],AL     ;save digit in memory

      POP   AX          ;get AX back

      ADD   DI,2        ;advance memory pointer

      LOOP  NYBL        ;repeat until done

      POP   CX          ;get CX back

      RET

DISP  ENDP

        This question relates to the program above.  Many of your answers can be indicated on the program itself.

b.      Is this a complete program or does it have to be linked or included with other code to make it work?  Explain how you deduced this.

It is only a function – you assemble it first and then link the resulting .obj file with the main program and any other functions with the linker

c.       Why the 4 consecutive ROL instructions?

8086 permits only ,1 or ,CL to specify the number of places to shift.  It takes no more instructions; and they are faster, to use this method.  See the next part

d.      Show how you would use ROL AX, CL instead; and explain why this is really not a good approach

push       cx
mov        cx,4

rol       ax,cl
pop        cx

Note this is also 4 instructions, and the push/pop and the immediate are both longer than the rol.  This saves  neither time nor program memory.

e.       Show a sequence of instructions to pass parameters into this function and call it.

If DI is in use otherwise the sequence is

push       di
mov        al, thisbyte
call       disp

pop        di

f.       Many DOS functions return larger arguments using the specification ES:BP, but they pass large arguments using DS:DX

i.        Why is ES used in preference to DS?

ES is relatively rarely used, whereas DS will likely be in use at the same time to save the arguments in the data segment.  Consequently the amount of save/restoring is reduced.

ii.      BP is often used to refer to the stack.  How do you refer to the number 5 word in the argument returned with ES:BP?

ES:[BP-10]            ; this is 5 words into the array, which is in the extra segment.

iii.    How do you push a pointer to a location on the stack?

PEA     SS:[BP – how_deep]

iv.    How do you dereference that pointer inside the function (this is not as easy as it looks)

This has no general answer; that depends on what registers you have pushed, or whether you have a spare register.  If you do, you can copy BP to a spare register, then

mov     bp,[bp]    ; this dereferences bp
mov     destreg,[bphowdeep]
mov     bp, whereitwas







2.      The stack diagram below resulted from the execution of code both before, during, and after a proc is called.  Note that the addresses are in increasing order.  Just after OLD BP appeared on the stack the instruction MOV BP,SP was executed.  At present, SP is pointing to the first of the 50 uninitialized words, BP is pointing to OLD BP.


Description

Address [BP]

Instruction that placed this

50 uninitialized words

[BP - 102]

sub   sp,100

Old CX

[BP - 2]

push  cx

Old BP

[BP]

push  bp

Return address (offset)

[BP + 2]

Part of call far

Return address (segment)

[BP + 4]

Part of call far

Argument called NVALS

[BP + 6]

push  NVALS

Pointer to word array called VALS

[BP + 8]

pea   VALS

a.       When, relative to the sequence of instructions you will fill in, was  the instruction MOV BP,SP executed.  Explain.

After the push bp

b.      Fill in the blank addresses in the table in the form [BP + number (plus or minus)]

In the table

c.       Fill in the instructions that caused each quantity to be pushed onto the stack

In the table

d.      State the order in which the instructions were executed (top-to-bottom or bottom-to-top).  Explain

Bottom to top, i. e., the pea VALS came first


e.       State which instructions were executed in the main program and which in the proc.  Explain.

The pea, the push NVALS, and the call are done in the calling program
the push bp, mov bp,sp, the push CX, the sub sp,100 are done in the proc


f.       Explain more carefully (including what numerical value you used) what instruction reserved the space for the uninitialized words.  (hint:  the presence of OLD CX is a factor)

pushing cx makes no difference in the instruction, it does cause the 102 rather than the 100 in the reference

g.       Show a sequence of instructions that will return from the function and remove the argument and pointer.  Explain.

mov  sp,bp      ; this abandons old cx
pop  bp
ret  2          ; this abandons the two items by moving sp