################################################# # Translate Number: # This program prints a number # in decimal, hexadecimal, and binary. # # Student Name: # # Example: # Decimal: 16 # Binary: 00000000000000000000000000010000 # Hexadecimal: 0x0000 0010 # ################################################## .data number: .word 0x1234fedc # You can change this for testing .text ################################################# # Main: # This program reads a number and prints the number # in decimal, hexadecimal, and binary. # # PseudoCode: # Print "Decimal:" and print number # Print_Binary(number) # Print_Hexadecimal(number) # # Register Usage: (You provide) # # Stack Usage: (You provide) # ################################################# main: li $v0,10 # exit syscall ################################################# # Print Binary: # This procedure loops through a word and prints # a 1 or 0 for each binary bit. # # PseudoCode: # Pass parameter in register $a0 # Print "Binary:" # Create a string which shows each binary bit in word # Print string # # Calling Sequence: # lw $a0,number # jal PrBin # # Register Usage: (You provide) # # Stack Usage: (You provide) ################################################# PrBin: jr $ra ################################################# # Print Hexadecimal: # This procedure loops through a word and prints # 8 hexadecimal digits, for each nibble in a word. # Put a space between each 4 hexadecimal digits. # # PseudoCode: # Print "Hexadecimal: 0x" # Print the first four nibbles using PrintNibble (PrNib) # Print a space # Print the last four nibbles using PrintNibble (PrNib) # Print a carriage return # Example: "Hexadecimal: 0x54ab cde0 # # Calling Sequence: # Pass parameter on the stack # lw $a0,number # sw $a0,-4($sp) # jal PrHex # # Register Usage: (You provide) # # Stack Usage: (You provide) ################################################# PrHex: jr $ra # return ################################################# # Print Nibble: # This procedure prints an ASCII character given one nibble. # This is an extension of homework 3. # # PseudoCode: # String = HexTable[nibble] # Print string # # Calling Sequence: # Pass parameter on the stack # lw $a0,nibble # sw $a0,-4($sp) # jal PrNib # # Register Usage: (You provide) # # Stack Usage: (You provide) ################################################# PrNib: jr $ra # return ################################################# # Print Carriage Return: # This procedure prints a Carriage Return # # PseudoCode: # Print String consisting of Carriage Return # # Calling Sequence: # No arguments # jal PrCR # # Register Usage: (You provide) # # Stack Usage: (Must contain space for $RA) ################################################# PrCR: jr $ra # return ################################################# # Print Space: # This procedure prints a Space # # PseudoCode: # Print String consisting of Space # # Calling Sequence: # No arguments # jal PrSpace # # Register Usage: (You provide) # # Stack Usage: (Must contain space for $RA) ################################################# PrSpace: jr $ra # return