Advertisement
IvoB1n

Untitled

Mar 23rd, 2021
1,338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %include "rw32-2018.inc"
  2. ;%include "io.inc"
  3.  
  4. ;esp - stack 7c-end
  5.  
  6. ; db   dw   dd
  7. ;byte word dword
  8. ; 8    16   32
  9.  
  10. ; [var] - value  var - adress
  11.  
  12. section .bss ; uninicialized values
  13. ; name resb size
  14. ar_num_3 resd 10
  15.  
  16. section .data ; inicialized values
  17. ; name size value
  18. ar_num_2 dd 1, 10, 100
  19. ar_num_1 dd 3, 30, 300
  20.  
  21. section .text
  22.  
  23. array_operations:
  24.     xor ebx, ebx
  25.     _for:
  26.         cmp al, 0
  27.         je .add
  28.         cmp al, 1
  29.         je .sub
  30.         cmp al, 2
  31.         je .div
  32.         cmp al, 3
  33.         je .mul
  34.         .add:
  35.             mov edx, [ar_num_1 + ebx]
  36.             add edx, [ar_num_2 + ebx]
  37.             mov dword [ar_num_3 + ebx], edx
  38.             jmp .end
  39.         .sub:
  40.             mov edx, [ar_num_1 + ebx]
  41.             sub edx, [ar_num_2 + ebx]
  42.             mov dword [ar_num_3 + ebx], edx
  43.             jmp .end
  44.         .div:
  45.             push eax
  46.             mov eax, [ar_num_1 + ebx]
  47.             mov edx, [ar_num_2 + ebx]
  48.             div edx
  49.             mov dword [ar_num_3 + ebx], eax
  50.             pop eax
  51.             jmp .end
  52.         .mul:
  53.             push eax
  54.             mov eax, [ar_num_1 + ebx]
  55.             mov edx, [ar_num_2 + ebx]
  56.             mul edx
  57.             mov dword [ar_num_3 + ebx], eax
  58.             pop eax
  59.             jmp .end
  60.         .end:
  61.             add ebx, 4
  62.             sub ecx, 1
  63.             cmp ecx, 0
  64.             jne _for
  65.             ret
  66. CMAIN:
  67.     mov ebp, esp; for correct debugging
  68.     xor eax, eax
  69. ;Implementujte podprogram, který sečte dvě pole a výsledek uloží do pole třetího.
  70. ;Bonus: Implementujte funkci, která na základě obsahu registru AL nad poli jednu z operací: +,-,*
  71.     xor eax, eax
  72.     mov al, 3; operation type 0-add 1-sub 2-div 3-mul
  73.     mov ecx, 3; array size
  74.     call array_operations
  75.    
  76.     mov eax, [ar_num_3]
  77.     mov ebx, [ar_num_3+4]
  78.     mov ecx, [ar_num_3+8]
  79.    
  80.    
  81.     xor eax, eax
  82.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement