CozyCoder

Blurr filter asm

Sep 1st, 2017
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. section .text
  2.     global _start
  3.  
  4. _start:
  5.  
  6.     call openFileIn         ;open the org image
  7.     call readFromFileIn     ;read the data
  8.     call closeFileIn        ;close file
  9.  
  10.     call openFileOut        ;open output file
  11.     call writeToFile        ;write the data in data
  12.     call closeFileOut       ;close file
  13.  
  14.     call exitProg           ;exit process
  15.  
  16. openFileIn:
  17.     ;opening the file roller1.raw
  18.     mov eax, 5
  19.     mov ebx, fileName
  20.     mov edx, 0777
  21.     int 0x80
  22.  
  23.     mov [fd_in], eax    ;get pointer to indexbuffer
  24.     ret
  25.  
  26. openFileOut:
  27.     ;opening the file roller1.raw
  28.     mov eax, 5
  29.     mov ebx, outName
  30.     ;mov ecx, 1
  31.     mov edx, 0777
  32.     int 0x80
  33.  
  34.     mov [fd_out], eax   ;get pointer to indexbuffer
  35.     ret
  36.  
  37. writeToFile:
  38.     ;1. Put sys_write(), 4, in EAX
  39.     ;2. Put fileDesc in EBX
  40.     ;3. Put the pointer to data in ECX
  41.     ;4. Put buffer size of data in EDX
  42.     ;5. call kernel
  43.  
  44.     ;returns the actual nr of bytes written in EAX
  45.    
  46.     ;mov ecx, [info + 2]
  47.     ;mov [blurr], ecx
  48.  
  49.     ;mov ax, [info + 2]
  50.     ;movzx eax, ax
  51.     ;mov bx, [info + 3]
  52.     ;movzx ebx, bx
  53.  
  54.     ;d6 + d5 = 1AB
  55.     ;add eax, ebx
  56.     ;mov [blurr], eax
  57.  
  58.     call blurrTopRow
  59.  
  60.  
  61.     ;mov eax, 4
  62.     ;mov ebx, [fd_out]
  63.     ;mov ecx, info
  64.     ;mov edx, IMAGE_SIZE
  65.     ;int 0x80
  66.  
  67.  
  68.  
  69.     mov eax, 4
  70.     mov ebx, [fd_out]
  71.     mov ecx, blurr
  72.     mov edx, 1
  73.     int 0x80
  74.  
  75.     ret
  76.  
  77. blurrTopRow:
  78.     ;from 0 - 251 there will be no pixels above the active pixel
  79.  
  80.     ;first pixel
  81.     ;set sum to 0
  82.     ;mov [sum], byte 0
  83.  
  84.     ;set ah to 0 to be sure that no other values changes the byte
  85.     ;save byte in al, ax should be [0000](ah) value(al)
  86.     mov ah, byte 0
  87.     mov al, byte [info + 0]
  88.    
  89.     ;store sum all pixels in sum, divition will be done here
  90.     add [sum], ax
  91.  
  92.     ;add pixel beside it (1)
  93.     ;mov ah, byte 0
  94.     mov al, byte [info + 1]
  95.  
  96.     ;add the value to sum
  97.     ;add [sum], ax    If i add this value, the program stops working
  98.  
  99.  
  100.     ;divsion here, edx has to be 0
  101.  
  102.     ;add the pixels below the first pixel
  103.     ;move data to the first 8-bits
  104.     mov ah, 0
  105.     mov al, byte [info + 251]
  106.     add [sum], ax
  107.  
  108.     ;set the last 8-bits in the 16-bit register (ax) to 0
  109.     ;to avoid messing up the value
  110.     mov ah, 0
  111.     mov al, byte [info + 252]
  112.     add [sum], ax
  113.  
  114.     mov eax, 0
  115.     mov ax, [sum]
  116.  
  117.     mov ebp, 4
  118.     mov edx, 0
  119.     idiv ebp
  120.  
  121.     mov [blurr], al
  122.  
  123.     ret
  124.  
  125. readFromFileIn:
  126.     ;Process: Read from file
  127.     ;1. put the system call sys_read() number 3 in EAX
  128.     ;2. Put the file descriptor in the EBX register
  129.     ;3. Put the pointer to the input buffer in the ECX register
  130.     ;4. Put the buffer size, in EDX
  131.     ;5. call kernel
  132.  
  133.  
  134.     ;the system call returns the number of bytes rad in the EAX
  135.     ;register, in case of error code is in the EAX register
  136.  
  137.     ;read the file
  138.     mov eax, 3
  139.     mov ebx, [fd_in]    ;pointer to inputBuffer
  140.     mov ecx, info       ;buffer size
  141.     mov edx, IMAGE_SIZE
  142.     int 0x80
  143.  
  144.     ret
  145.  
  146. readFromFileOut:
  147.     ;Process: Read from file
  148.     ;1. put the system call sys_read() number 3 in EAX
  149.     ;2. Put the file descriptor in the EBX register
  150.     ;3. Put the pointer to the input buffer in the ECX register
  151.     ;4. Put the buffer size, in EDX
  152.     ;5. call kernel
  153.  
  154.  
  155.     ;the system call returns the number of bytes rad in the EAX
  156.     ;register, in case of error code is in the EAX register
  157.  
  158.     ;read the file
  159.     mov eax, 3
  160.     mov ebx, [fd_in]    ;pointer to inputBuffer
  161.     mov ecx, info       ;buffer size
  162.     mov edx, IMAGE_SIZE
  163.     int 0x80
  164.  
  165.     ret
  166.  
  167. printBuffer:
  168.     ;1. put syscall sys_write to EAX
  169.     ;2. put an argument in EBX
  170.     ;3. put the data into ECX
  171.     ;4. put the size of the segment in EDX
  172.     ;5. call kernel
  173.     mov eax, 4
  174.     mov ebx, 1
  175.     mov ecx, info
  176.     mov edx, IMAGE_SIZE
  177.    
  178.     int 0x80
  179.     ret
  180.  
  181. closeFileIn:
  182.     ;Closing a file
  183.     ;1.Put the system call sys_close(), 6, in the EAX register
  184.     ;2.Put the file descriptor in the EBX register
  185.     mov EAX, 6
  186.     mov EBX, [fd_in]
  187.     int 80h
  188.  
  189.     ;the system call returns error code in eax
  190.     ret
  191.  
  192. closeFileOut:
  193.     ;Closing a file
  194.     ;1.Put the system call sys_close(), 6, in the EAX register
  195.     ;2.Put the file descriptor in the EBX register
  196.     mov EAX, 6
  197.     mov EBX, [fd_out]
  198.     int 80h
  199.  
  200.     ret
  201.  
  202. exitProg:
  203.     ;call system exit
  204.     mov eax, 1
  205.     int 0x80
  206.  
  207. section .data
  208. fileName db 'roller1.raw', 0 ;glöm förfan inte nollan
  209. ;lenfFileName equ $-fileName ; adress
  210. outName db 'roller2.raw', 0
  211. ;lenOutName equ $-fileName
  212. IMAGE_SIZE equ 64256
  213.  
  214. section .bss
  215. fd_out resb 1
  216. fd_in resb 1
  217. info resb 64256
  218. blurr resb 64256
  219. sum resw 1
Advertisement
Add Comment
Please, Sign In to add comment