I'm trying to access a bmp file using RARS and I have a problem with accessing pixels of it.
I'm trying to find a black pixel in my bitmap image but the way I did it gives me address out of range error when loading a byte from t3 to t5. Therefore I am pretty sure that I did something wrong with accessing data.
.data
FileName: .space 64
width: .space 320
height: .space 240
buf: .space 54
.text
#reading what is the file name
ReadingFileName:
li a7, 8
la a0, FileName
li a1, 64
ecall
la t0, FileName
li t1, '\n'
FindEndOfString:
lbu t2, (t0)
beq t1, t2, RemoveN
addi t0, t0, 1
j FindEndOfString
RemoveN:
li t1, '\0'
sb t1, (t0)
#Reading data from file
ReadingData:
#open the file
li a7, 1024
la a0, FileName
li a1, 0
ecall
#file descriptor
mv s0, a0
#check if file was opened correctly
bltz s0, OpeningError
#read data from file
li a7, 63
mv a0, s0
la a1, buf
li a2, 54
ecall
beq zero, a0, FileClose
lw s1, buf
addi s1, s1, 54 #start of pixels
FileClose:
li a7, 57
mv a0, s0
ecall
Main:
li t1, 0 #first column of black pixels
li t2, 0 #last column of black pixels
mv t3, s1 #start of pixels
LookForBlackPixel:
lbu t5, (t3)
beqz t5, BlackPixelFound
addi t3, t3, 1
j LookForBlackPixel
BlackPixelFound:
OpeningError:
The error: Runtime exception at 0x00400094: address out of range 0x84364d78