Advertisement
Guest User

func.asm

a guest
Apr 6th, 2019
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extern printf
  2. extern putchar
  3.  
  4. section .data
  5.     format: dd "%d", 10, 0
  6.     char_form: db "%c", 10, 0
  7.     int_form: db "%d", 10, 0
  8.     str_form: db "%s", 10, 0
  9.     string: db "Wind On The Hills!", 20, 0     
  10.  
  11. section .text
  12.     global  IsBetweenAandB, RemCharCodeFromAToB, DebugStart, DebugEnd
  13.  
  14. ;==========================================================================
  15. ; RemCharCodeFromAToB - removes all chars between a and e from str
  16. ; arguments:
  17. ;   str - string to be processed
  18. ;   a   - start
  19. ;   e   - end
  20. ; return value:
  21. ;   n/a
  22. ;--------------------------------------------------------------------------
  23. RemCharCodeFromAToB:
  24.     ; standard entry sequence
  25.     push    ebp             ; save the previous value of ebp for the benefi$
  26.     mov     ebp, esp        ; copy esp -> ebp so that ebp can be used as a $   
  27.  
  28.     ; accessing arguments  
  29.                             ; [ebp + 0] = old ebp stack frame
  30.                             ; [ebp + 4] = return address
  31.     mov     edx, [ebp + 8]  ; string address
  32.  
  33.     while_loop_rcc:
  34.         mov cl, [edx]       ; obtain the address of the 1st character of the string
  35.         cmp cl, 0           ; check the null value  
  36.  
  37.         je  while_loop_exit_rcc     ; exit if the null-character is reached
  38.    
  39.         mov al, cl ; save cl
  40.         mov cl, [ebp + 16]      ; end-char
  41.         push cx                 ; push end-char
  42.         mov cl, [ebp + 12]      ; start-char
  43.         push cx                 ; push start-char
  44.         push ax;                ; push ch
  45.         call IsBetweenAandB
  46.         add esp, 12
  47.  
  48.         cmp eax, 0          ; if(ch is not between 'a' and 'e')
  49.  
  50.         je inner_loop_exit_rcc
  51.  
  52.         mov eax, edx    ; copy the current address
  53.  
  54.         inner_loop_rcc:
  55.             mov cl, [eax+1]
  56.             cmp cl, 0
  57.             je  inner_loop_exit_rcc
  58.  
  59.             mov [eax], cl
  60.  
  61.             inc eax
  62.             jmp inner_loop_rcc
  63.         inner_loop_exit_rcc:
  64.  
  65.         inc edx             ; increment the address
  66.         jmp while_loop_rcc  ; start the loop again
  67.     while_loop_exit_rcc:
  68.  
  69.     ; standard exit sequence
  70.     mov     esp, ebp        ; restore esp with ebp
  71.     pop     ebp             ; remove ebp from stack
  72.     ret                     ; return the value of temporary variable    
  73. ;===================================================================
  74.  
  75. DebugStart:
  76.     mov eax, 'x'
  77.     call PrintChar_db
  78.     ret
  79.  
  80. DebugEnd:
  81.     mov eax, 'y'
  82.     call PrintChar_db
  83.     ret
  84.  
  85. ;===================================================================
  86. ; IsBetweenAandB - tests a character if it is between 'a' and 'b'
  87. ; arguments:
  88. ;   ch = character to be tested
  89. ;   a = start character
  90. ;   b = end character
  91. ; return value:
  92. ;   1 = yes
  93. ;   0 = no
  94. ;----------------------------------------------------------------
  95. IsBetweenAandB:
  96.     push    ebp
  97.     mov ebp, esp   
  98.                         ; [ebp]     = old ebp stack frame
  99.                         ; [ebp + 4] = return address
  100.     mov eax, [ebp + 8]  ; [ebp+8] = ch
  101.     push ecx
  102.     mov ecx, [ebp + 12] ; 'a' = start
  103.     mov edx, [ebp + 16] ; 'e' = end
  104.  
  105.     cmp eax, ecx    ; compare 'ch' with 'a'
  106.     jae next_test_ibab  ; if(ch>='a')
  107.     jb  set_zero_ibab   ; if(ch<'a')
  108.    
  109. next_test_ibab:
  110.     cmp eax, edx    ; compare 'ch' with 'e'
  111.     jbe set_one_ibab        ; if(ch<='e')
  112.     ja  set_zero_ibab   ; if(ch>'e')
  113.  
  114. set_one_ibab:
  115.     mov eax, 1 
  116.     jmp returns_ibab
  117.  
  118. set_zero_ibab:
  119.     mov eax, 0
  120.  
  121. returns_ibab:
  122.     pop ecx
  123.  
  124.     mov     esp, ebp
  125.     pop     ebp
  126.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement