Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.16 KB | None | 0 0
  1. #Barcode 39 decoding
  2. #--------------------------------
  3. .eqv BMP_FILE_SIZE 90122
  4. .eqv BYTES_PER_ROW 1800
  5.  
  6. .data
  7. .align 4
  8. res:        .space 2
  9. image:  .space BMP_FILE_SIZE
  10. #PROMPTS:
  11. prompt:         .asciiz "After:\n "
  12. prompt1:            .asciiz "Please enter which line should be checked:\n "
  13. prompt2:            .asciiz "Prompt checked: \n "
  14. promptb:            .asciiz "black \n "
  15. promptw:            .asciiz "white \n "
  16. enter:          .asciiz "\n"
  17. promptf:            .asciiz "fat \n "
  18. promptt:            .asciiz "thin \n "
  19. #ERRORS:
  20. dsc_error_message:  .asciiz     "File descriptor error!"
  21. h_error_message:    .asciiz "Header error!"
  22. size_error_message: .asciiz "Size error!"
  23. f_error_message:    .asciiz "Format error!"
  24.  
  25.  
  26. buffer:         .space  2
  27. header:         .space  54
  28. width:          .word   600
  29. height:         .word   50
  30.  
  31. fname:          .asciiz     "/home/orzelke/Assmeblert/3.bmp"
  32. .text
  33. main:
  34.     jal read_bmp
  35.     #input y coordinate:
  36.     li  $v0,    4
  37.     la  $a0, prompt1
  38.     syscall
  39.    
  40.     #input y coordinate:
  41.     li  $v0,    5
  42.     syscall
  43.     move    $t7,    $v0
  44.     li  $t8,    50
  45.     sub     $t7,    $t8,    $t7
  46.    
  47.     li  $a0, 0  #x
  48.     la  $a1, ($t7)      #y
  49.     xor $t7,    $t7, $t7
  50.     j   loop_condition
  51.    
  52.  
  53.  
  54.  
  55.  
  56.    
  57.  
  58.  
  59. get_pixel: 
  60. #description:
  61. #   returns color of specified pixel
  62. #arguments:
  63. #   $a0 - x coordinate
  64. #   $a1 - y coordinate - (0,0) - bottom left corner
  65.  
  66.     la  $a0, ($t7)
  67.    
  68.  
  69.     la $t1, image + 10  #adress of file offset to pixel array
  70.     lw $t2, ($t1)       #file offset to pixel array in $t2
  71.     la $t1, image       #adress of bitmap
  72.     add $t2, $t1, $t2   #adress of pixel array in $t2
  73.    
  74.     li  $t0,    0
  75.    
  76.     #pixel address calculation
  77.     mul $t1, $a1, BYTES_PER_ROW #t1= y*BYTES_PER_ROW
  78.     move $t3, $a0      
  79.     sll $a0, $a0, 1
  80.     add $t3, $t3, $a0   #$t3= 3*x
  81.     add $t1, $t1, $t3   #$t1 = 3x + y*BYTES_PER_ROW
  82.     add $t2, $t2, $t1   #pixel address
  83. #t2 holds pixel adress
  84.     #get color
  85.     lb  $v0,    ($t2)
  86.     move $t4,   $v0
  87.     #if white -> loop_condition
  88.     bnez    $t4,    loop_condition
  89.     bgtz    $t9,    loop_condition
  90.    
  91.  
  92. find_width_thin: #t9 holds width
  93.    
  94.     addiu   $t9,    $t9, 1
  95.     addiu   $t2,    $t2,    3
  96.     lb  $v0,    ($t2)
  97.     beqz    $v0,    find_width_thin
  98.     li  $t8,    3
  99.     mul $t6,    $t9,    $t8 #how many bytes we need to go back
  100.     sub $t2, $t2,   $t6
  101.     xor $t8,    $t8,    $t8
  102.     li  $v0,    4
  103.     la  $a0, prompt
  104.     subiu   $t2,    $t2, 3
  105.     j   decoding_prep
  106.  
  107. loop_condition:
  108.     addiu $t7, $t7, 1
  109.     lw  $t5,    width
  110.     beq $t7,    $t5, exit
  111.     j   get_pixel
  112.  
  113. decoding_prep:
  114.     li  $t8,    9   #after 9 bars/spaces we got new symbol
  115. decoding:
  116.    
  117.     addiu $t2$t2, 3
  118.     lb  $t4,    ($t2)
  119.    
  120.     beqz    $t4,    black
  121.  
  122. white:
  123.     addiu   $s1, $s1, 1
  124.     bgtz    $s2,    saveb
  125.    
  126.     j loop_condition2
  127. black:
  128.     addiu   $s2, $s2, 1
  129.     bgtz    $s1,    savew
  130.    
  131.     j loop_condition2
  132. savew:
  133.     la  $s4,    ($s1)
  134.     li  $s1, 0
  135.     bgt $s4, $t9,    fat
  136.    
  137.     j thin
  138. saveb:
  139.     la  $s4,    ($s2)
  140.     li  $s2, 0
  141.     bgt $s4,    $t9 fat
  142.     j thin
  143. fat:
  144.     li  $s3,    10
  145.     mul $s5,    $s5, $s3
  146.     addiu   $s5,    $s5, 2
  147.     addiu   $t0,    $t0,    1
  148.     j   loop_condition2
  149. thin:
  150.     li  $s3,    10
  151.     mul $s5,    $s5, $s3
  152.     addiu   $s5,    $s5,    1
  153.     addiu   $t0,    $t0,    1
  154.    
  155. loop_condition2:
  156.     beq $t0,    $t8,    print
  157.     addiu $t7, $t7, 1
  158.     lw  $t5,    width
  159.     beq $t7,    $t5, exit
  160.     j   decoding
  161.  
  162. print:
  163.     li  $v0,    1
  164.     la  $a0,    ($s5)
  165.     syscall
  166.     li  $v0,    4
  167.     la  $a0,    enter
  168.     syscall
  169.     li  $t0,    0
  170.     li  $s5,    0
  171. skip_to_black:
  172.     li  $v0,    4
  173.     la  $a0,    enter
  174.     syscall
  175.     addiu   $t2,    $t2,    3
  176.     lb  $t4,    ($t2)
  177.     beqz    $t4,    black
  178.     li  $s5,    0
  179.     j   skip_to_black
  180.    
  181. read_bmp:
  182. #description:
  183. #   reads the contents of a bmp file into memory
  184. #arguments:
  185. #   none
  186. #return value: none
  187.     sub $sp, $sp, 4     #push $ra to the stack
  188.     sw $ra,4($sp)
  189.     sub $sp, $sp, 4     #push $s1
  190.     sw $s1, 4($sp)
  191. #open file
  192.     li $v0, 13
  193.         la $a0, fname       #file name
  194.         li $a1, 0       #flags: 0-read file
  195.         li $a2, 0       #mode: ignored
  196.         syscall
  197.     move $s1, $v0      # save the file descriptor
  198.    
  199.     bltz    $s1,    dsc_error
  200.  
  201. #read file
  202.     li $v0, 14
  203.     move $a0, $s1
  204.     la $a1, image
  205.     li $a2, BMP_FILE_SIZE
  206.     syscall
  207.  
  208. #close file
  209.     li $v0, 16
  210.     move $a0, $s1
  211.         syscall
  212.    
  213.     lw $s1, 4($sp)      #restore (pop) $s1
  214.     add $sp, $sp, 4
  215.     lw $ra, 4($sp)      #restore (pop) $ra
  216.     add $sp, $sp, 4
  217.     jr $ra
  218. dsc_error:
  219.     li  $v0, 4
  220.     la  $a0, dsc_error_message
  221.     syscall
  222.     j   exit
  223.    
  224. bitmap_error:
  225.     li  $v0, 4
  226.     la  $a0, h_error_message
  227.     syscall
  228.     j   exit
  229.    
  230. size_error:
  231.     li  $v0, 4
  232.     la  $a0, size_error_message
  233.     syscall
  234.     j   exit
  235.    
  236. format_error:
  237.     li  $v0, 4
  238.     la  $a0, f_error_message
  239.     syscall
  240.     j   exit
  241.    
  242. exit:
  243.     li      $v0,    10
  244. syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement