CSE306 Homework 3

CSE306 Processing Systems and Structures Lockwood, Spring 2004

Homework Assignment 3

Due: Monday Mar. 22, 2004, 5:30pm

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)


Representing Floating Point Numbers

Suppose that we wish to represent floating point numbers using a 1-bit sign, a 4-bit exponent with a bias of 7, and an 8-bit mantissa with an implict 1. Determine the floating point representation for each of the following numbers.

Number = 5.0

  • Sign = (1 pt)
  • Exponent = (1 pt)
  • Mantissa = (1 pt)

    Number = 1.0

  • Sign = (1 pt)
  • Exponent = (1 pt)
  • Mantissa = (1 pt)

    Number = -1.125

  • Sign = (1 pt)
  • Exponent = (1 pt)
  • Mantissa = (1 pt)

    Number = -113.6

  • Sign = (1 pt)
  • Exponent = (1 pt)
  • Mantissa = (1 pt)

    Electronic charge of an electron, measured in Coulombs.

  • Sign = (1 pt)
  • Exponent = (1 pt)
  • Mantissa = (1 pt)


    Calculations with the Floating Point Unit

    Determine the how the floating point variables will change for the code listed below

    
    ; Excepts from Explorer-3D
    ; John Lockwood 
    ; 1998
      
      ...
    
    Vector3 STRUCT  ; Use Structure to grouping several variables
      X Real4 ?     ; into one entity.  They are the basis for classes in C++
      Y Real4 ?
      Z Real4 ?
    Vector3 ENDS
    
      ...
    
    Position   Vector3<12.5,25.0,100.0>  ; Initial position Vector
    Velocity   Vector3<10.0,20.0,30.0>   ; Initial velocity
    
    OldX       Real4  ?
    OldXR8     Real8  ?
    
    XMove      Real4 ?
    ZMove      Real4 1000.0
    
    DeltaT     Real10 0.125 ; 1/8th of a second
    MoveAngle  Real10 3.0
    
    WallHeight    DW 5      ; Height of Maze walls (Integer distance in meter)
    FloorHeight   DW 20     ; Height of Maze walls (Integer distance in meter)
    
      ...
    
            FINIT              ; Initialize the FPU
                               ; Always do this once when program begins!
    
            FLD  Position.X    ; Access element of the Vector3 Structure
            FST  OldX          ; Save Position.X
            FST  OldXR8        ; Also save as Double-precision
            FLD  Velocity.X
            FLD  DeltaT
            FMUL
            FST  XMove
            FADD
            FSTP Position.X
    
            LEA  SI , Position          ; Load effective address of Position
            FLD  (Vector3 PTR [SI]).Y   ; Cast [SI] as a pointer to a Vector3
            FILD FloorHeight            ; Load an Integer into FPU
            FILD WallHeight            
            FSUB
            FADD
            FST  (Vector3 PTR [SI]).Y
            FSTP (Vector3 PTR [SI+4]).Y ; The '+4' is important..
    
            XOR  BYTE PTR [Velocity.X+3] , 80h   ; FCHS w/o a FPU!  
    
            MOV AX,DS  ; Set ES=DS
            MOV ES,AX
            LEA  SI , Velocity.Y        ; All variables can be moved in Memory 
            LEA  DI , Velocity.Z
            MOVSD
    
            FLD ZMove         
            FLDPI
            FLD  MoveAngle
            FDIV
            FCOS                        ; FPU Calculates on Radians
            FMUL
            FSTP ZMove
    
    

  • OldX = (8 hex digits) (3 pts)

  • OldXR8 = (16 hex digits) (3 pts)

  • XMove = (8 hex digits) (3 pts)

  • Position.X = (8 hex digits) (3 pts)

  • Position.Y = (8 hex digits) (3 pts)

  • Position.Z = (8 hex digits) (3 pts)

  • Velocity.X = (8 hex digits) (3 pts)

  • Velocity.Z = (8 hex digits) (3 pts)

  • ZMove = (8 hex digits) (3 pts)


    Text-Mode Video

    For each of the elements that we wish to display on an 80x25 text-mode screen, determine the attribute (AH), character (AL), and offset (DI) into video memory that must be established before we execute the following code:
    Specify all numbers in hex.

    MOV DX, 0B800h MOV ES, DX MOV ES:[DI],AX

    The letter 'C' in blue on a black background at row 0, column 4.

  • AX= (2 pts)
  • DI= (2 pts)

    The letter 'S' in (intense) white on a green background at row 3, column 3.

  • AX= (2 pts)
  • DI= (2 pts)

    A magenta (purple) heart on a black background at row 10, column 54.

  • AX= (2 pts)
  • DI= (2 pts)

    An intensely-colored green clover on a black background on the third text-mode video page (page 2) at row 2, column 3.

  • AX= (2 pts)
  • DI= (2 pts)

    A blinking, empty, black, smiley character on a purple (red+blue) background on the fourth text-mode video page (page 3), at the lower-righthand corner of the screen.

  • AX= (2 pts)
  • DI= (2 pts)


    Table-Lookup Functions

    Consider the following code that uses a table-lookup function to efficiently encode and decode top-secret messages.

    ; ------- Data Section ------- InputString db 'PBQR*OERNX','$' OutputString db ' ','$' TableFunction db 'NOPQRSTUVWXYZABCDEFGHIJKLM' ... ; ------- Code Section ------- MOV SI, 0 MOV BH, 0 ConvLoop: MOV BL,InputString[SI] CMP BL,'$' JE ConvDone CMP BL,'Z' JA ConvNext CMP BL,'A' JB ConvNext MOV BL,TableFunction[BX-'A'] ConvNext: MOV OutputString[SI], BL INC SI JMP ConvLoop ConvDone: ...

    After running the program, OutputString =

  • (13 pts)

    Once you have completed this homework assignment, press: