CSE306 Homework 2

CSE306 Processing Systems and Structures Lockwood, Spring 2004

Homework Assignment 2

Due: Monday Feb. 16, 2004, 11pm

75 Points

The answers to this homework assignment are to be submitted via the World Wide Web (WWW). You may use any web browser to submit this assignment. Your answers will be graded automatically. Your score will be immediately posted to the on-line gradebook. You will have the opportunity to resubmit the homework and improve your score.

ID Important: Use the same ID as selected in HW0
Name (First Last)


Homework Questions

Analyze the following program and calculate the final values for each of the JmpCtr elements. Express all answers in hex.

.. data ..
JmpCtr dw 11 dup(0)     ; Result variables

.. code ..
         MOV CX, 9000h  ; Always comment your code

JmpLoop: MOV AX, CX
         Inc JmpCtr[0]  ; A sports-announcer comment would say:
         CMP CX, 5000h  ;   Compare CX , 5000h
         JA BigNum      ;   (which we already knew from the code)

         Inc JmpCtr[2]  

         ADD AX,0E100h  ; Hint: it is important to note that the body 
         JNC JCdone     ;   of this program has an outside loop 
         Inc JmpCtr[4]  
                        
         TEST CX,3      ; The comments in this program are really
         JZ JCDone      ;   bad because they add little value to help
         Inc JmpCtr[6]  ;   a human understand what is going on.  You
         JMP JCDone     ;   will never want to write comments like this!

BigNum:  Inc JmpCtr[8]  
                        
         CMP CX,4500h
         JG  RealBig    ; You might want to draw a flow chart
         Inc JmpCtr[10] ; to see where the program branches
                        
         CMP CX,-31000  
         JLE Small
         Inc JmpCtr[12]

         SUB AX,2000    ; There are lots of tricks in this code 
         JO  JCOver     
                       
         NEG AX
         JS  JCDone     ; Accounting skills can be used to help 
         Inc JmpCtr[14] ; analyze the operation of this program 
         JMP JCDone
         
JCOver:  Inc JmpCtr[16] ; As you can see, there are tricky
         JMP JCdone     ; issues with signed and unsigned compares

RealBig: Inc JmpCtr[18]   
         JMP JCdone

Small:   Inc JmpCtr[20] ; Done at last!
         JMP JCdone

JCDone:  Loop JmpLoop  

  1. JmpCtr[0]: [hex] (3 pts)
  2. JmpCtr[2]: [hex] (3 pts)
  3. JmpCtr[4]: [hex] (3 pts)
  4. JmpCtr[6]: [hex] (3 pts)
  5. JmpCtr[8]: [hex] (3 pts)
  6. JmpCtr[10]: [hex] (3 pts)
  7. JmpCtr[12]: [hex] (3 pts)
  8. JmpCtr[14]: [hex] (3 pts)
  9. JmpCtr[16]: [hex] (3 pts)
  10. JmpCtr[18]: [hex] (3 pts)
  11. JmpCtr[20]: [hex] (3 pts)


    These problems test your understanding of the multiplication, division, and operation of the stack. Assume that the initial values of the registers are as follows (you'll need to track the their values as they change). All values are given in hex.

    RegValue
    AX 8921
    BX 23FE
    CX 14FF
    DX 0341
    SI 0004
    DI 1000

    Determine the values of all registers after running the program.

    .... PUSH AX DIV DI PUSH AX POP ES PUSH CX PUSH DX MOV BP , SP MOV CX , [BP] POP AX POP AX IMUL AH PUSH AX MOV AX,BX POP BX MUL SI PUSH AX CBW MOV SI,AX IDIV AH POP BP POP DI .....

  12. AX = [hex] (3 pts)
  13. BX = [hex] (3 pts)
  14. CX = [hex] (3 pts)
  15. DX = [hex] (3 pts)
  16. DI = [hex] (3 pts)
  17. SI = [hex] (3 pts)
  18. BP = [hex] (3 pts)
  19. ES = [hex] (3 pts)


    The graders of this class should be commended for their abilities to understand and debug complex and/or confusing assembly code. To appreciate their efforts, analyze the following program and determine the each of the six values.

    NUTTY_AS_A_FRUITCAKE EQU 13 APPLES EQU 7 EAT MACRO BURGER, FRIES LOCAL SHIP MOV AX, BURGER MOV CX, FRIES ROR AX, CL JC SHIP INC CX SHIP: INC AX ENDM ... ORANGES DW 4 MANGOS DB 3,4,5,6,7 PEACHES DW 13,12,11,10,9 BANANA DW 23 HOME PROC NEAR DEC BANANA CMP ORANGES, APPLES JAE PEAR ADD ORANGES, 2 CALL HOME PEAR: MOV AX, BANANA RET HOME ENDP ... Main Routine ... EAT 0F00Dh 3 ; Question 20 : AX = ? EAT CX AX ; Question 21 : AX = ? MOV AX, PEACHES[5] MOV AL, MANGOS[4] ; Question 22 : AX = ? CALL HOME ; Question 23 : AX = ? MOV AX, ORANGES ; Question 24 : AX = ? MOV CX, NUTTY_AS_A_FRUITCAKE MOV AX, 0 Avoid_NonDescriptive_Labels: ADD AX, CX LOOP Avoid_NonDescriptive_Labels ; Question 25 : AX = ?

  20. AX = [hex] (3 pts)
  21. AX = [hex] (3 pts)
  22. AX = [hex] (3 pts)
  23. AX = [hex] (3 pts)
  24. AX = [hex] (3 pts)
  25. AX = [hex] (3 pts)

Once you have completed this homework assignment, press: