CS2011, A Term 1999 Prof. Sergio A. Alvarez Practice Problems for Test 2 Name: ______________________ Login: _____________ Section: ____ Instructions: Read each problem carefully. Write your answers clearly. Include brief explanations for your solutions. Unexplained answers may not receive full credit. Each problem is worth 50 points. Good luck! 1) Assume that the two instructions PUSH BX, PUSH CX were executed (in that order) immediately before the following debug display was produced: AX=3520 BX=00FF CX=1234 DX=FFE2 SP=FF00 BP=0000 SI=0000 DI=0000 DS=1000 ES=0FF0 SS=12EB CS=1F76 IP=010A NV UP EI PL NZ NA PO NC 1F76:010A 58 POP AX a) Give the new contents of the CS, IP, SS, and SP registers immediately after the next instruction is executed. b) Draw a diagram that shows how the top of the stack changes as a result of executing the next instruction. Give explicit segment:offset addresses and hex contents for each memory location involved. Include both the old and new stack tops in your diagram. 2) Assume that the initial register contents are exactly as given above in problem 1), except that the instruction about to be executed is now: 1F76:010A 082300 CALL 0130 a) Give the new contents of the CS, IP, SS, and SP registers immediately after the next instruction is executed. b) Draw a diagram that shows how the top of the stack changes as a result of executing the next instruction. Give explicit segment:offset addresses and hex contents for each memory location involved. Include both the old and new stack tops in your diagram. 3) Consider the following assembly language instructions: mov ax,0103h mov dx,0 mov bx,0020h div bx a) State what registers the dividend (numerator), divisor (denominator), quotient, and remainder will be taken from or placed in (in connection with the div bx instruction shown). b) Give the final hex contents of registers AX, BX, DX after the above sequence of instructions has been executed. 4) Fill in the steps below to write an 80X86 assembly language procedure named twopower that accepts a singleword unsigned integer n as input on the stack and recursively calculates the n-th power of 2, returning the result in register AX (assume that the result occupies no more than 16 bits). Your answer to part (a) should be in high-level functional notation like twopower(n) = twopower(n-5). Your answers to parts (b)-(e) should be in 80X86 assembly language. a) Let twopower(n) denote the n-th power of 2. Give a recursive definition of twopower(n), in terms of a recursive relation together with a suitable base case. b) Define the start of a procedure named twopower, set up a stack frame in the usual way, and retrieve the parameter n from the stack, placing it in register BX. c) Check for the base case, jump to a label called recurse if the base case does not occur, and handle the base case otherwise, jumping to a label called cleanup at the end. d) Starting with the label recurse, handle the recursive case, calling twopower with the appropriate arguments, and leaving the desired final result in register AX. e) Starting with the label cleanup, finalize the stack frame and return, clearing the stack as appropriate. 5) Given the data allocation: .data bitbunch dw 0010h number dw 000Ah Consider the following assembly language loop intended to accumulate in AX the product of (the low bytes of) bitbunch and number using the shift-and-add method described in class. sumloop: bt bitbunch,dx jnc L add ax,number L: shl number,1 inc dx loop sumloop a) State explicitly what the initial value should be for each of the registers AX, CX, DX immediately before executing the above loop so that the loop correctly computes the desired product in AX. In each case briefly explain why. b) Give the correct final values for each of the registers AX, CX, DX immediately after the above loop has finished executing. 6) a) Give the absolute addresses of the memory locations in which the interrupt vector for INT 10h is stored. Specify how many memory locations are needed. b) Describe the sequence of events involved in handling software interrupt INT 21h. Be explicit about memory locations, control branching, and the like. 7) Assume the following data allocation and assume that the variables defined here retain their initial values. .data buffer db 16 dup(' ') xtable db "0123456789ABCDEF" Write an assembly language procedure getascii that returns in AL the ASCII code of the hex symbol (0..9,A..F) corresponding to the number (0..15d) stored in DL. Use either the XLAT instruction or indirect addressing to extract the ASCII code from xtable. All registers except AX, IP, and the Flags register should be left unchanged by a call to your procedure.