######################################################## # Homework Assignment 2 # Name = # Floating point is described in section 9.6 in our text. ######################################################## .data # Store the parsed opcode/registers in parsed float: .float 43000000 parsed: .word 0,0,0 #sign, exponent, significand HexTbl: # Nibble Hexadecimal Tranlation Table .asciiz "0" # 0 .asciiz "1" .asciiz "2" .asciiz "3" .asciiz "4" .asciiz "5" .asciiz "6" .asciiz "7" .asciiz "8" .asciiz "9" .asciiz "a" .asciiz "b" .asciiz "c" # 12 .asciiz "d" .asciiz "e" .asciiz "f" .text .globl main ########################### Program ###################### # This program interprets floating point data # # Pseudocode: # print("Hexadecimal:") # parse(float, parsed) # print_sign(sign) # print_mantissa(significand) // in hexadecimal # print_exponent(exponent) // in hexadecimal # print("Decimal:" + float) // print in decimal # # Stack Usage: # # Register Conventions: # ######################################################## # The call to syscall has the following parameters: # $a0: thing to be printed # $v0: Mode # 1=integer # 4=null-terminated string ######################################################## main: # print("Hexadecimal:") # parse(float, parsed) lw $t1,float sw $t1,-4($sp) la $t1,parsed sw $t1,-8($sp) jal Parse # print_sign(sign) lw $a1,parsed jal PrSign # print_mantissa(significand) // in hexadecimal # print_exponent(exponent) // in hexadecimal # print("Decimal:" + float) // print in decimal li v0,10 # exit syscall ######################################################## # Parse: This procedure parses a floating point single into an array # // Single-precision # sign = data[31] # exponent = data[23-30] # significand = data[0-22] # # Calling Sequence: # sw $rX,-4($sp) # Floating point data # sw $rY,-8($sp) # Address of array to parse into # jal Parse # # Returns: In the output array, the following is stored: # Word 0: Sign # Word 1: Exponent # Word 2: Significand or Mantissa # # Stack Usage: # # Register Convention: ######################################################## Parse: addi $sp,$sp,-12 sw $ra,0($sp) lw $t1,4($sp) lw $t2,8($sp) # sign = data[31] # exponent = data[23-30] # significand = data[0-22] lw $ra,0($sp) addi $sp,$sp,+12 jr $ra ######################################################## # PrSign: Prints a Sign # # Pseudocode: # if sign == 0 print + # else if sign == 1 print - # # Calling Sequence: # lw $a1, # jal PrSign # # Returns: Nothing # # Stack Usage: # # Register Convention: ######################################################## PrSign: jr $ra ######################################################## # PrintMant: Prints the significand (or mantissa) passed as a parameter # # Pseudocode: # Print "1." # Shift significand 1 bit to the left to get 24 bits to print # Print significand nibbles in hexadecimal (call PrintHex) # # Calling Sequence: # sw $rX,-4($sp) # Significand # jal PrMant # # Returns: Nothing # # Stack Usage: # # Register Convention: ######################################################## PrMant: jr $ra ######################################################## # PrintHex: Prints the number passed as a parameter in hex # # Pseudocode: # For each nibble do: # nibble = (word >> shiftnum) # nibble = nibble.maskBottom4Bits() # address = (nibble * 2) + HexTbl # Print(*address) // nibble in ASCII from table # Until all nibbles printed # # Calling Sequence: # lw $a1, # lw $a2, # jal PrintHex # # Returns: Nothing # # Stack Usage: # # Register Convention: ######################################################## PrintHex: jr $ra ######################################################## # PrintExp: Prints the exponent passed as a parameter # # Pseudocode: # exponent = exponent - 127 # print ' x 2**' # print exponent (in hex) # print linefeed # # Calling Sequence: # lw $a1, # jal PrintExp # # Returns: Nothing # # Stack Usage: # # Register Convention: ######################################################## PrintExp: jr $ra