This code creates a bmp file with all the white pixels:
initialize_bmp:
#description:
# fill the header of the bmp file an initialize all pixels with white
#arguments:
# none
#return value: none
la $t0, image #image is a buffer or we can say array that stores all the 90122 bytes (equivalent to the image size) in register t0.
li $t1, 'B' #Loading the first letter 'B' in the register t1
sb $t1, ($t0) #Storing the letter 'B' from t1 to the 0th byte of t0
li $t1, 'M' #Storing the letter 'M' in t1
sb $t1, 1($t0) #Loading the letter 'M' in the 1st byte of register t0.
li $t1, BMP_FILE_SIZE
sw $t1, 2($t0)
sw $0, 6($t0)
li $t1, 0x7a
sw $t1, 10($t0)
addi $t0, $t0, 14
li $t1, 27 # loop counter
la $t2, header
copy_loop: # loop to copy header in the image
lw $t3, ($t2)
sw $t3, ($t0)
addi $t0, $t0, 4
addi $t2, $t2, 4
addi $t1, $t1, -1
bnez $t1, copy_loop
li $t1, 5625 # loop counter
li $t3, 0xFFFFFFFF # white color
initialize_loop: # loop to initialize the image with all white pixels
sw $t3, ($t0)
sw $t3, 4($t0)
sw $t3, 8($t0)
sw $t3, 12($t0)
addi $t0, $t0, 16
addi $t1, $t1, -1
bnez $t1, initialize_loop
jr $ra
I have this code of creating a bmp file with all the white pixels in mips. I don't understand what is going on in this part of the code:
li $t1, BMP_FILE_SIZE
sw $t1, 2($t0)
sw $0, 6($t0)
li $t1, 0x7a
sw $t1, 10($t0)
addi $t0, $t0, 14
Can somebody explain me the code?
This is the bmp file format so in accordance with this image can somebody explain me the code that how are we actually initializing the bmp file here with the white pixels?
sw $0...
stores 2 half words of zeros using a single instruction. After setting all the fields of the header, it advances the pointer value in the$t0
register by the size of the BMP header (14 bytes). The use of 0x7a suggests that then DIB header is the 108 byte version (0x7a - 14).