ECE291 Homework 2

ECE291 Computer Engineering II Lockwood, Spring 1999

Homework Assignment 2

Due: Tuesday, February 16, 1999, 5pm

75 Points

The answers to this homework assignment are to be submitted via the World Wide Web (WWW). You may use any Mosaic browser (such as Netscape or Internet Explorer) to submit this assignment. No special software is needed. Your answers will be graded automatically. You may resubmit this homework to improve your score. Your best score is posted immediately to the on-line gradebook. This page can accessed directly as
http://www.ece.uiuc.edu/~ece291/hw/hw2.html

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.

    
    Variable Declarations...
    
    JmpCtr dw 11 dup(0)
    
    Code section...
    
         MOV CX, 0
    
    Tornado:
    
         CMP CX, 5000h         ; Your code may be written flawlessly,
         JAE SomeWhere         ; but without good commenting nobody
                               ; can understand it! 
         INC JmpCtr[0]
         
         MOV AX, 0E700h        ; Unfortunately you won't get any help
         ADD AX, CX            ; here.
         JC  OverTheRainbow
         
         INC JmpCtr[2]
         
         TEST CX, 2
         JZ  OverTheRainbow    ; Here we jump over the rainbow,
                               ; sometimes...
         INC JmpCtr[4]
         
         JMP OverTheRainbow
         
    SomeWhere:                 ; Hey we made it somewhere!  Too bad
                               ; this label doesn't reflect what's going
         INC JmpCtr[6]         ; to happen in this section of code.
         
         CMP CX,7000h
         JGE ToTo
         
         INC JmpCtr[8]         ; Good comments not only help others read
                               ; your code, they help you debug it.
         CMP CX,-32256
         JL  Melting
         
         INC JmpCtr[10]        ; Poor comments can't help anybody.
         
         CMP CX, 67h
         JO  Emerald          ; A horrible comment would say:
         JS  OverTheRainbow    ; "Compares CX to 67h"
         
         INC JmpCtr[12]
         
         JMP OverTheRainbow    
    
    Oz:                       
         INC JmpCtr[14]
         JMP Kansas            ; What a state!
         
    ToTo:
    
         INC JmpCtr[16]
         JMP OverTheRainbow
         
    Emerald:                   
    
         INC JmpCtr[18]        ; Increments the jump counter
         JMP OverTheRainbow
         
    Melting:                  ; Yeah, it goes with the theme but
                              ; it's completely useless.
         INC JmpCtr[20]
         
    OverTheRainbow:           ; No pot of gold here.
    
         INC CX
         CMP CX, 0A000h
         JNE Tornado          ; Not again!
              
    Kansas:
         
        LOOP Oz               ; Almost the end of the program!! 
        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
    AH30h
    AL05h
    BHFFh
    BL72h
    CHFCh
    CL08h
    DH00h
    DL60h
    SI0400h
    DI0100h

    DIV SI MOV ES, AX MOV CL, DL MOV AX, BX IMUL BH MOV BX, AX SHL SI, CL SAR SI, 1 MOV AL, 75h IMUL CH CWD MOV BP, AX MOV CX, DX XOR AX,AX IDIV 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)


    ECE291 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.

    ONE_PLUS_ONE EQU 3 TEN_TIMES EQU ONE_PLUS_ONE*2 THE_NATIONAL_BRAND EQU 3 .... CHEW MACRO CHICLETS, GUM LOCAL ROPE MOV AX, CHICLETS MOV CX, GUM ; Don't swallow your gum!! ROR AX, CL JC ROPE INC CX ROPE: INC AX ENDM .... FOLGERS_CRYSTALS DW 7 THE_BEST_PART DW 3,9,5,8,2,4 OF_WAKING_UP DB 9,1,0,6,3,7 DECAF DW 0BADh .... MOM PROC NEAR DEC DECAF CMP FOLGERS_CRYSTALS, THE_NATIONAL_BRAND JBE TASTE_TEST SUB FOLGERS_CRYSTALS, 2 CALL MOM TASTE_TEST: MOV AX, DECAF RET MOM ENDP .... ; ; Assume that MAIN calls this procedure FIRST !! ; Confusion_Say proc far CHEW 0F00Dh, TEN_TIMES Question 1 : AX = ? CHEW CX, AX Question 2 : AX = ? MOV AX, THE_BEST_PART[5] MOV AL, OF_WAKING_UP[3] Question 3 : AX = ? CALL MOM Question 4 : AX = ? MOV AX, FOLGERS_CRYSTALS Question 5 : AX = ? MOV CX, 13 SUB AX, AX ECE291_is_endless_fun: ADD AX, CX LOOP ECE291_is_endless_fun Question 6 : AX = ? Confusion_Say 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: