Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Barcode 39 decoding
- #--------------------------------
- .eqv BMP_FILE_SIZE 90122
- .eqv BYTES_PER_ROW 1800
- .data
- .align 4
- res: .space 2
- image: .space BMP_FILE_SIZE
- #PROMPTS:
- prompt: .asciiz "After:\n "
- prompt1: .asciiz "Please enter which line should be checked:\n "
- prompt2: .asciiz "Prompt checked: \n "
- promptb: .asciiz "black \n "
- promptw: .asciiz "white \n "
- enter: .asciiz "\n"
- promptf: .asciiz "fat \n "
- promptt: .asciiz "thin \n "
- #ERRORS:
- dsc_error_message: .asciiz "File descriptor error!"
- h_error_message: .asciiz "Header error!"
- size_error_message: .asciiz "Size error!"
- f_error_message: .asciiz "Format error!"
- buffer: .space 2
- header: .space 54
- width: .word 600
- height: .word 50
- fname: .asciiz "/home/orzelke/Assmeblert/3.bmp"
- .text
- main:
- jal read_bmp
- #input y coordinate:
- li $v0, 4
- la $a0, prompt1
- syscall
- #input y coordinate:
- li $v0, 5
- syscall
- move $t7, $v0
- li $t8, 50
- sub $t7, $t8, $t7
- li $a0, 0 #x
- la $a1, ($t7) #y
- xor $t7, $t7, $t7
- j loop_condition
- get_pixel:
- #description:
- # returns color of specified pixel
- #arguments:
- # $a0 - x coordinate
- # $a1 - y coordinate - (0,0) - bottom left corner
- la $a0, ($t7)
- la $t1, image + 10 #adress of file offset to pixel array
- lw $t2, ($t1) #file offset to pixel array in $t2
- la $t1, image #adress of bitmap
- add $t2, $t1, $t2 #adress of pixel array in $t2
- li $t0, 0
- #pixel address calculation
- mul $t1, $a1, BYTES_PER_ROW #t1= y*BYTES_PER_ROW
- move $t3, $a0
- sll $a0, $a0, 1
- add $t3, $t3, $a0 #$t3= 3*x
- add $t1, $t1, $t3 #$t1 = 3x + y*BYTES_PER_ROW
- add $t2, $t2, $t1 #pixel address
- #t2 holds pixel adress
- #get color
- lb $v0, ($t2)
- move $t4, $v0
- #if white -> loop_condition
- bnez $t4, loop_condition
- bgtz $t9, loop_condition
- find_width_thin: #t9 holds width
- addiu $t9, $t9, 1
- addiu $t2, $t2, 3
- lb $v0, ($t2)
- beqz $v0, find_width_thin
- li $t8, 3
- mul $t6, $t9, $t8 #how many bytes we need to go back
- sub $t2, $t2, $t6
- xor $t8, $t8, $t8
- li $v0, 4
- la $a0, prompt
- subiu $t2, $t2, 3
- j decoding_prep
- loop_condition:
- addiu $t7, $t7, 1
- lw $t5, width
- beq $t7, $t5, exit
- j get_pixel
- decoding_prep:
- li $t8, 9 #after 9 bars/spaces we got new symbol
- decoding:
- addiu $t2, $t2, 3
- lb $t4, ($t2)
- beqz $t4, black
- white:
- addiu $s1, $s1, 1
- bgtz $s2, saveb
- j loop_condition2
- black:
- addiu $s2, $s2, 1
- bgtz $s1, savew
- j loop_condition2
- savew:
- la $s4, ($s1)
- li $s1, 0
- bgt $s4, $t9, fat
- j thin
- saveb:
- la $s4, ($s2)
- li $s2, 0
- bgt $s4, $t9 fat
- j thin
- fat:
- li $s3, 10
- mul $s5, $s5, $s3
- addiu $s5, $s5, 2
- addiu $t0, $t0, 1
- j loop_condition2
- thin:
- li $s3, 10
- mul $s5, $s5, $s3
- addiu $s5, $s5, 1
- addiu $t0, $t0, 1
- loop_condition2:
- beq $t0, $t8, print
- addiu $t7, $t7, 1
- lw $t5, width
- beq $t7, $t5, exit
- j decoding
- print:
- li $v0, 1
- la $a0, ($s5)
- syscall
- li $v0, 4
- la $a0, enter
- syscall
- li $t0, 0
- li $s5, 0
- skip_to_black:
- li $v0, 4
- la $a0, enter
- syscall
- addiu $t2, $t2, 3
- lb $t4, ($t2)
- beqz $t4, black
- li $s5, 0
- j skip_to_black
- read_bmp:
- #description:
- # reads the contents of a bmp file into memory
- #arguments:
- # none
- #return value: none
- sub $sp, $sp, 4 #push $ra to the stack
- sw $ra,4($sp)
- sub $sp, $sp, 4 #push $s1
- sw $s1, 4($sp)
- #open file
- li $v0, 13
- la $a0, fname #file name
- li $a1, 0 #flags: 0-read file
- li $a2, 0 #mode: ignored
- syscall
- move $s1, $v0 # save the file descriptor
- bltz $s1, dsc_error
- #read file
- li $v0, 14
- move $a0, $s1
- la $a1, image
- li $a2, BMP_FILE_SIZE
- syscall
- #close file
- li $v0, 16
- move $a0, $s1
- syscall
- lw $s1, 4($sp) #restore (pop) $s1
- add $sp, $sp, 4
- lw $ra, 4($sp) #restore (pop) $ra
- add $sp, $sp, 4
- jr $ra
- dsc_error:
- li $v0, 4
- la $a0, dsc_error_message
- syscall
- j exit
- bitmap_error:
- li $v0, 4
- la $a0, h_error_message
- syscall
- j exit
- size_error:
- li $v0, 4
- la $a0, size_error_message
- syscall
- j exit
- format_error:
- li $v0, 4
- la $a0, f_error_message
- syscall
- j exit
- exit:
- li $v0, 10
- syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement