This is a MIPS assembly program. The program to prompt the user for a single 64-bit integer in hexadecimal, convert it, and then print the overflow status, but I get the following error:
-- program is finished running (dropped off bottom) --
Here is my code: I am running the program on MARS 4.5
.data
prompt: .asciiz "Enter the 64-bit integer in hexadecimal: "
overflow_label: .asciiz "Overflow = "
newline: .asciiz "\n"
.text
# Main program
main:
# Prompt user for 64-bit integer
li $v0, 4 # syscall for print string
la $a0, prompt # load address of prompt
syscall # print prompt
# Read 64-bit integer
li $v0, 8 # syscall for read string
la $a0, buffer # load address of buffer
li $a1, 17 # maximum number of characters to read (16 hex digits + null terminator)
syscall # read integer
# Convert input string to integer
jal convert_hex_to_int # jump to convert_hex_to_int subroutine
# Print overflow status
li $v0, 4 # syscall for print string
la $a0, overflow_label # load address of overflow_label
syscall # print overflow_label
# Print overflow status
li $v0, 1 # syscall for print integer
move $a0, $t3 # move overflow status to $a0
syscall # print overflow status
# Exit program
li $v0, 10 # syscall for exit program
syscall # exit program
# Subroutine to convert hexadecimal string to integer
convert_hex_to_int:
li $t6, 0x30 # ASCII value for '0'
li $t7, 0x0A # ASCII value for 'A'
li $t8, 0 # initialize integer value to 0
convert_loop:
lb $t9, 0($a0) # load byte from buffer
addi $a0, $a0, 1 # move to next character in buffer
# Check if end of string
beqz $t9, convert_done # if byte is null, exit loop
# Check if character is between '0' and '9'
sub $t9, $t9, $t6 # convert ASCII to integer
bltz $t9, check_alpha # if character is not between '0' and '9', check if it's an alphabet
# Character is between '0' and '9'
sll $t8, $t8, 4 # shift current integer value left by 4 bits
or $t8, $t8, $t9 # combine integer value with new digit
j convert_loop # repeat loop
check_alpha:
li $t9, 0x20 # difference between lowercase and uppercase alphabets
# Check if character is between 'A' and 'F'
add $t9, $t9, $t9 # convert ASCII to uppercase
bge $t9, 0x41, convert_upper # if uppercase, check if between 'A' and 'F'
j convert_lower # if lowercase, convert to uppercase and proceed
convert_upper:
sub $t9, $t9, $t7 # convert ASCII to integer
addi $t9, $t9, 0x0A # adjust value for 'A' to 'F'
j convert_continue # continue with the conversion
convert_lower:
sub $t9, $t9, $t6 # convert ASCII to integer
convert_continue:
sll $t8, $t8, 4 # shift current integer value left by 4 bits
or $t8, $t8, $t9 # combine integer value with new digit
j convert_loop # repeat loop
convert_done:
move $v0, $t8 # store result in $v0
jr $ra # return
# Buffer for input string
.data
buffer: .space 17 # buffer for input string (64-bit integer)
Actually, I supposed to add two 64-bit integers that are signed and entered in hexadecimal format as strings. The program should output the sum in hexadecimal and indicate if there is an overflow. I minumized the prog to only process one entery.