Why am I getting Runtime exception at 0x004000e8: fetch address not aligned on word boundary 0x1001004a

.data
.align 2                # Align the next data item on a word boundary
intArr:             .space 28            # Array to hold integers (7 * 4 bytes)
vtdPrompt:          .asciiz "vals to do? "
entIntPrompt:       .asciiz "enter an int: "
adjMsg:             .asciiz " is bad, make it "
origLab:            .asciiz "original:\n"
backLab:            .asciiz "backward:\n"
dmPrompt:           .asciiz "do more? "
invalid_input_msg:  .asciiz "Invalid input. Please enter a valid integer.\n"

.text
.globl main

main:
li $v0, 4            # syscall code for printing string
la $a0, vtdPrompt    # load the address of the prompt
syscall

    li $v0, 4            # syscall code for printing string
    la $a0, origLab      # load the address of the original label prompt
    syscall

main_loop:
jal GetOneIntByVal   # call GetOneIntByVal to get valsToDo
move $t0, $v0        # move valsToDo to $t0

    li $a1, 1            # load minInt
    li $a2, 7            # load maxInt
    la $a3, adjMsg       # load address of the message
    jal ValidateInt      # call ValidateInt to validate valsToDo
    
    # Check for zero input before proceeding
    beq $t0, $zero, exit_program   # exit loop if valsToDo is 0
    
    # Initialize loop variables
    move $t1, $zero      # Initialize i to 0
    move $t2, $t0        # Initialize j to valsToDo

swap_loop:
beq $t1, $t2, show_backwards   # exit loop if i equals (valsToDo - 1)

    sll $t4, $t1, 2         # calculate offset for intArr[i]
    add $t3, $t4, $gp       # add offset to base address of intArr
    lw $a0, 0($t3)          # load intArr[i]
    
    addi $t4, $t2, -1    # calculate (valsToDo - 1)
    sll $t5, $t4, 2      # calculate offset for intArr[j]
    add $t5, $t5, $gp    # add offset to base address of intArr
    lw $a1, 0($t5)       # load intArr[j]
    
    jal SwapTwoInts      # call SwapTwoInts to swap intArr[i] and intArr[j]
    
    addi $t1, $t1, 1     # increment index i
    addi $t2, $t2, -1    # decrement index j
    j swap_loop

show_backwards:
move $a0, $t0        # move valsToDo to $a0
jal ShowIntArray     # call ShowIntArray to show reversed array

    li $v0, 4            # syscall code for printing string
    la $a0, dmPrompt     # load the address of the prompt
    syscall
    
    li $v0, 12           # syscall code for reading character
    syscall
    lb $a0, 0($v0)       # load the byte read
    
    li $t6, 'n'          # load 'n' into $t6
    li $t7, 'N'          # load 'N' into $t7
    beq $a0, $t6, exit_program   # exit loop if character is 'n'
    beq $a0, $t7, exit_program   # exit loop if character is 'N'
    
    j main_loop 

exit_program:
li $v0, 10           # syscall code for exit
syscall

# Function to get an integer by value

# Arguments:

# $a0: Address of the prompt

# Returns:

# $v0: The integer entered by the user

GetOneIntByVal:
li $v0, 5            # syscall code for reading integer
syscall

    # Check if the input is a valid integer
    bltz $v0, invalid_input  # If the input is negative, it's invalid
    j input_valid             # Otherwise, input is valid

input_valid:
jr $ra                  # Return if the input is valid

invalid_input:
# Print an error message
li $v0, 4
la $a0, invalid_input_msg
li $v0, 11           # syscall code for printing character
li $a0, '\n'         # load newline character to print
syscall

    # Re-prompt the user to enter an integer
    j GetOneIntByVal

# Function to validate an integer

# Arguments:

# $a0: Address of the integer to validate

# $a1: Minimum allowed value

# $a2: Maximum allowed value

# $a3: Address of the message

ValidateInt:
lw $t0, 0($a0)       # load the integer to validate
blt $t0, $a1, less_than_min
bgt $t0, $a2, greater_than_max

    jr $ra               # return if the integer is within range

less_than_min:
# Handle less than min
j set_min

greater_than_max:
# Handle greater than max
j set_max

set_min:
sw $a1, 0($a0)       # set the integer to the minimum value
jr $ra               # return to caller

set_max:
sw $a2, 0($a0)       # set the integer to the maximum value
jr $ra               # return to caller

# Function to show an array of integers

# Arguments:

# $a0: Address of the array

# $a1: Size of the array

# $a2: Address of the label

ShowIntArray:
li $v0, 4            # syscall code for printing string
move $a0, $a2        # load the address of the label
syscall

    li $t0, 0            # initialize index k to 0

show_loop:
beq $t0, $a1, end_show   # exit loop if k equals size

    lw $t1, 0($a0)       # load the integer at array[k]
    li $v0, 1            # syscall code for printing integer
    move $a0, $t1        # load the integer to print
    syscall
    
    li $v0, 11           # syscall code for printing character
    li $a0, ' '          # load space character to print
    syscall
    
    addi $a0, $a0, 4     # move to the next integer in the array
    addi $t0, $t0, 1     # increment index k
    j show_loop

end_show:
li $v0, 11           # syscall code for printing character
li $a0, '\n'         # load newline character to print
syscall

    jr $ra               # return to caller

# Function to swap two integers

# Arguments:

# $a0: Address of the first integer

# $a1: Address of the second integer

SwapTwoInts:
lw $t0, 0($a0)       # load the first integer
lw $t1, 0($a1)       # load the second integer

    sw $t1, 0($a0)       # store the second integer at the first address
    sw $t0, 0($a1)       # store the first integer at the second address
    
    jr $ra               # return to caller

It gives me that error. What should I do?

New contributor

Ryder is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật