CS306 Homework 2

CS306 Processing Systems and Structures Lockwood, Spring 2002

Homework Assignment 2

Due: Tuesday, February 5, 2002, 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.

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 0,0,0,0,0,0,0,0,0,0,0
         ; Your goal is to determine the final
         ; value of these 11 16-bit words
         ; Note that because each word occupies two bytes,
         ; the total size of this array is 22 bytes.
    
    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 word [JmpCtr+0]
    
         MOV AX, 0E700h        ; Unfortunately you won't get any help
         ADD AX, CX            ; here.
         JC  OverTheRainbow
    
         INC word [JmpCtr+2]
    
         TEST CX, 2
         JZ  OverTheRainbow    ; Here we jump over the rainbow,
                               ; sometimes...
         INC word [JmpCtr+4]
    
         JMP OverTheRainbow
    
    SomeWhere:                 ; Hey we made it somewhere!  Too bad
                               ; this label doesn't reflect what's going
         INC word [JmpCtr+6]   ; to happen in this section of code.
    
         CMP CX,7000h
         JGE ToTo
    
         INC word [JmpCtr+8]   ; Good comments not only help others read
                               ; your code, they help you debug it.
         CMP CX,-32256
         JL  Melting
    
         INC word [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 word [JmpCtr+12]
    
         JMP OverTheRainbow
    
    Oz:
         INC word [JmpCtr+14]
         JMP Kansas            ; What a state!
    
    ToTo:
    
         INC word [JmpCtr+16]
         JMP OverTheRainbow
    
    Emerald:
    
         INC word [JmpCtr+18]  ; Increments the jump counter
         JMP OverTheRainbow
    
    Melting:                   ; Yeah, the label goes with the theme but
                               ; it's completely useless.
         INC word [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!!
    

  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)


    CS306 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 .... %macro CHEW 2 MOV AX, %1 MOV CX, %2 ROR AX, CL JC %%ROPE INC CX %%ROPE: INC AX %endmacro .... 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: DEC word [DECAF] CMP word [FOLGERS_CRYSTALS], THE_NATIONAL_BRAND JBE TASTE_TEST SUB word [FOLGERS_CRYSTALS], 2 CALL MOM TASTE_TEST: MOV AX, [DECAF] RET ..start: mov ax, cs mov ds, ax ; Initialize DS register inc ax mov ss,ax mov sp,stacktop Confusion_Say: 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 CS306_is_endless_fun: ADD AX, CX LOOP CS306_is_endless_fun ; Question 6 : AX = ?

  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: