Unaligned address in inst/data fetch: 0x100100cb -> Exception 4 [Address error in inst/data fetch] occurred and ignored

0

I am working on a MIPS morse code to ascii and ascii to morse converter. I was given the ascii to morse and I am working on the other way now.

I encountered this error after trying to come up with a loop to make it parse through the values. (we use spim to run this)

Exception occurred at PC=0x00400174 Unaligned address in inst/data fetch: 0x100100cb Exception 4 [Address error in inst/data fetch] occurred and ignored

Below is my code and I marked where my code is between the comment lines. I would like some help to figure out what the error is talking about as I don't understand this kind of error. I know that it is coming from the loopMC2A.

.data
string0: .asciiz "Select Operation Mode [0=ASCII to MC, 1=MC to ASCII]:"
string1: .asciiz "Enter a Character: "
string2: .asciiz "Enter a Pattern: "
string3: .asciiz "Morse Code: "
string4: .asciiz "ASCII: "
string5: .asciiz "End of Program\n"
string6: .asciiz "[Error] no ASCII2MC!\n"
string7: .asciiz "[Error] no MC2ASCII!\n"
string8: .asciiz "[Error] Invalid combination!\n"
buffer: .space 6

endLine: .asciiz "\n"

dict: .word 0x55700030, 0x95700031, 0xA5700032, 0xA9700033, 0xAA700034, 0xAAB00035, 0x6AB00036, 0x5AB00037, 0x56B00038, 0x55B00039, 0x9C000041, 0x6AC00042, 0x66C00043, 0x6B000044, 0xB0000045, 0xA6C00046, 0x5B000047, 0xAAC00048, 0xAC000049, 0x95C0004A, 0x6700004B, 0x9AC0004C, 0x5C00004D, 0x6C00004E, 0x5700004F, 0x96C00050, 0x59C00051, 0x9B000052, 0xAB000053, 0x70000054, 0xA7000055, 0xA9C00056, 0x97000057, 0x69C00058, 0x65C00059, 0x5AC0005A
s_dsh: .byte '-'
s_dot: .byte '.'
s_spc: .byte ' '

.text
main:
  
  li $v0, 4                 # print "Select Operation Mode [0=ASCII to MC, 1=MC to ASCII]:"
  la $a0, string0  
  syscall                   # syscall print string0 

  li $v0, 5
  syscall                   # syscall Read int 

  bne $v0, $0, MC2A

A2MC:
  li $v0, 4                 # print "Enter a Letter:" 
  la $a0, string1
  syscall                   # syscall print string1

  li $t0, 1                 # Define length
  li $v0, 12                # Read character
  syscall                   # syscall Read character
  move $t0,$v0              # Transfer the char entered to the temporary value
  
  li $t2, 1                 # Define length
  li $v0, 12                # Read NULL character 
  syscall                   # syscall Read character

  la $t2, dict              # Load address of dir
  li $t3, 0                 # Initialize index
  li $t4, 36                # Initialize boundary

LoopA2MC:
  lb $t5, ($t2)             # Load value to be compared
  beq $t0, $t5, FndA2MC     # Compare values
  addi $t2, $t2, 4          # Next symbol
  addi $t3, $t3, 1          # Next index
  blt $t3, $t4, LoopA2MC    # Evaluate index condition
  j ErrorA2MC

FndA2MC:
  li $v0, 4                 # print "Enter a Letter:" 
  la $a0, string3
  syscall                   # syscall print string3

  lw $t3, ($t2)             # Load value to be printed
  li $t4, 0x80000000        # Load bitmask

snext:
  and $t5, $t3, $t4         # Apply bitmask
  beq $t5, $0, caseZ        # Zero Found

caseO:
  sll $t3, $t3, 1           # Shift Left
  and $t5, $t3, $t4         # Apply bitmask  
  sll $t3, $t3, 1           # Shift Left
  beq $t5, $0, pdot         # 10 Found

caseE:
  li $v0, 4                 # Print string code
  la $a0, endLine           # Print NewLine
  syscall                   # syscall print value
  j EXIT                    # End

caseZ:
  sll $t3, $t3, 1           # Shift Left
  and $t5, $t3, $t4         # Apply bitmask  
  sll $t3, $t3, 1           # Shift Left
  beq $t5, $0, caseN        # 00 Found

pdash:
  li $v0, 11                # Print char
  lb $a0, s_dsh             # Load value to be printed
  syscall                   # Print value
  j snext

pdot:
  li $v0, 11                # Print char
  lb $a0, s_dot             # Load value to be printed
  syscall                   # Print value
  j snext

caseN:
  li $v0, 4                 # print "Error, Invalid combination!" 
  la $a0, string8
  syscall                   # syscall print string
  j EXIT

ErrorA2MC:
  li $v0 , 4                # print "Error no ASCII2MC!" 
  la $a0 , string6
  syscall                   # syscall print string6

  j EXIT
  
MC2A:
  li $v0 , 4            # print "Enter a Pattern:" 
  la $a0 , string2        
  syscall           # syscall print string2

#--------------------------------------------------------------#
  li $v0, 8             #load read string system call
  la $a0, buffer        #load address of buffer
  la $a1, 6             #buffer size is 6

  syscall

loopMC2A:
  li $t0, 0 #load in initial value to t0
  li $t1, 1 #load 00001 into t1 DOT BITS
  li $t2, 2 #load 0010 into t2 DASH BITS
  li $t3, 3 #load 0011 into t3 NULL TERMINATION BITS
  la $s0, buffer #load string address
  lw $s1, ($s0) #load character
  lb $s2, s_dot
  beq $s1, $s2, dotbit #compare to dot, then add 01
  lb $s2, s_dsh
  beq $s1, $s2, dashbit #compare to dash then add 10
  lb $s2, s_spc
  beq $s1, $s2, endbit #compare to space then add 11
  j ErrorMC2A #if it wasn't one of those three it's an error

dotbit:#or with 01, shift left 2
  or $t0, $t0, $t1 #or with 01 to write in a 01
  sll $t0, $t0, 2 #shift left 2
  addi $s0, $s0, 4 #move buffer over 4 bytes
  j loopMC2A #back to loop

dashbit:
  or $t0, $t0, $t2
  sll $t0, $t0, 2 #shift left 2
  addi $s0, $s0, 4 #move pointer over 4 bytes
  j loopMC2A

endbit:
  or $t0, $t0, $t3
  j EXIT


  li $v0, 4
  la $a0, buffer        #print buffer
  syscall

#--------------------------------------------------------------#
FndMC2A:
  li $v0 , 4            # print "Enter a Pattern:" 
  la $a0 , string4        
  syscall           # syscall print string4

  
PrintMC2A:
  li $v0 , 11
  addiu $a0, $t0, 'A' -41
  syscall
#--------------------------------------------------------------#

caseQ:
  li $v0 , 4                # Print string code
  la $a0 , endLine          # Print NewLine
  syscall                   # syscall print value
  j EXIT            # End

ErrorMC2A:
  li $v0 , 4                # print "Error no MC2ASCII!" 
  la $a0 , string7
  syscall                   # syscall print string7

  j EXIT

EXIT:        
  li $v0, 4
  la $a0, string5
  syscall

  li $a0, 0
  li $v0, 17              #exit
  syscall

mips
spim
asked on Stack Overflow Dec 5, 2020 by CluelessCman

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0