Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This Hex/Decimal Converter program should prompt the user to enter a hex number

ID: 3632847 • Letter: T

Question

This Hex/Decimal Converter program should prompt the user to enter a hex number then display the number as a decimal integer on the console. Next, prompt the user to enter a decimal number and then display the hex value, ASCII string, on the console.

HINT: Create two functions, int stringTOnumber(char *s) and void numberT0string( int n ,char *s)). The stringTOnumber() converts an ASCII string of hex characters into it a 32-bit numeric value. The numberTOstring() function converts a 32-bit binary number into an ASCII string of characters which represents the value as a hex number.

Explanation / Answer

# Write a MIPS code that asks the user for decimal number # Convert it to hex and print the result .data prompt: .asciiz "Enter the decimal number to convert: " ans: .asciiz " Hexadecimal equivalent: " result: .space 8 .text .globl main main: la $a0, prompt li $v0, 4 syscall li $v0, 5 syscall move $t2, $v0 la $a0, ans li $v0, 4 syscall li $t0, 8 # counter la $t3, result # where answer will be stored Loop: beqz $t0, Exit # branch to exit if counter is equal to zero rol $t2, $t2, 4 # rotate 4 bits to the left and $t4, $t2, 0xf # mask with 1111 ble $t4, 9, Sum # if less than or equal to nine, branch to sum addi $t4, $t4, 55 # if greater than nine, add 55 b End Sum: addi $t4, $t4, 48 # add 48 to result End: sb $t4, 0($t3) # store hex digit into result addi $t3, $t3, 1 # increment address counter addi $t0, $t0, -1 # decrement loop counter j Loop Exit: la $a0, result li $v0, 4 syscall la $v0, 10 syscall

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote