CSE306 Homework 2

CSE306 Processing Systems and Structures Lockwood, Spring 2003

Homework Assignment 2

Due: Tuesday Feb. 18, 2003, 5pm

75 Points

The answers to this homework assignment are to be submitted via the World Wide Web (WWW). You may use any Mosaic browsers (such as Netscape or Internet Explorer) to submit this assignment. No special software is needed. 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

    Conditional branching opcodes enable software to perform loops, cases, clauses, and comparisons of logical and numeric values. Analyze the following program and calculate the final values for each of the JmpCtr elements.
    Express all answers in hex.

    JmpCtr dw 11 dup(0) 
      ..
             MOV CX, 0
    
    JmpLoop: Inc JmpCtr[0]   ; There is no excuse for bad comments
             CMP CX, 4800h   ; in well-written source code.
             JAE BigNum
    
             Inc JmpCtr[2]   ; Unfortunately, these are bad comments!
    
             MOV AX,0F000h
             ADD AX,CX
    
             JC  JCdone      ; Good comments help you understand
             Inc JmpCtr[4]   ; what the program is doing.
                            
             TEST CX,1
             JZ JCDone
             Inc JmpCtr[6]   ; Bad comments are just a waste of time,
                             ; both for the author and for the reader.
             JMP JCDone
    
    BigNum:  Inc JmpCtr[8]  
    
             CMP CX,6000h    ; It would be silly, for example, to have
             JGE  RealBig    ; a comment like: 'Compare CX to 6000 hex'
             Inc JmpCtr[10]  ; since the code already says that!
                            
             CMP CX,-32512
             JL  Small       ; It is a good idea to give your 
             Inc JmpCtr[12]  ; jump labels meaningful names
    
             CMP CX,57
             JO  HappyLabel  ; Note that this label is useless
             JS  JCDone      ; as you try to understand the program
    
             Inc JmpCtr[14]  
             NOP             ; No operation - Let the CPU rest for a cycle.
             JMP JCDone     
             
    HappyLabel:  
             Inc JmpCtr[16]  ; Joy joy Joy
             JMP JCdone
    
    RealBig: Inc JmpCtr[18]  ; This label was more logical.
             JMP JCdone
    
    Small:   Inc JmpCtr[20]   
             JMP JCdone
    
    JCDone:  Inc CX          
             CMP CX,0A000h   ; Continue with main loop of program
             JNE JmpLoop    
             RET 

  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 multiplication and division operations.
    Given the initial value of the registers below, determine the final values of the registers after running the program.
    All values are given in hex.

    RegInitial
    Value
    AH10h
    AL40h
    BH44h
    BLFFh
    CHFEh
    CL07h
    DH00h
    DL60h
    SI0020h
    DI0100h

    DIV DI MOV ES,AX MOV BP,DX MOV AX,BX IMUL BH MOV BX,AX SHL DI,CL SAR DI, 1 MOV AL,33h IMUL CH CWD MOV BP,AX MOV CX,DX XOR AX,AX IDIV SI

  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)


    CSE306 TAs should be commended for their abilities to understand and debug complex and/or confusing assembly code. To appreciate their efforts, analyze the following procedure and determine each of the six values.

    LATER EQU 8 NOW EQU LATER/2 ORANGES EQU 9 THREE EQU 3 .... EAT MACRO BURGER, FRIES LOCAL SHIP MOV AX, BURGER MOV CX, FRIES ROR AX, CL JC SHIP INC CX SHIP: ENDM .... APPLES DW 5 MANGOS DB 7,4,5,6,3 PEACHES DW 9,3,2,1,8 FRUITCAKE DW 0BADh .... HOME PROC NEAR SUB FRUITCAKE, THREE CMP APPLES, ORANGES JAE PEAR ADD APPLES, 2 CALL HOME PEAR: MOV AX, FRUITCAKE RET HOME ENDP .... Really_Bad_Code proc far EAT 0F00Dh NOW Question 1 : AX = ? EAT CX AX Question 2 : AX = ? MOV AX, PEACHES[3] MOV AL, MANGOS[3] Question 3 : AX = ? CALL HOME Question 4 : AX = ? MOV AX, APPLES Question 5 : AX = ? MOV CX, 8 SUB AX, AX For_a_while: ADD AX, CX LOOP For_a_while Question 6 : AX = ? Really_Bad_Code endp

  20. Question A : [hex] (3 pts)
  21. Question B : [hex] (3 pts)
  22. Question C : [hex] (3 pts)
  23. Question D : [hex] (3 pts)
  24. Question E : [hex] (3 pts)
  25. Question F : [hex] (3 pts)

Once you have completed this homework assignment, press: