Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern printf
- extern putchar
- section .data
- format: dd "%d", 10, 0
- char_form: db "%c", 10, 0
- int_form: db "%d", 10, 0
- str_form: db "%s", 10, 0
- string: db "Wind On The Hills!", 20, 0
- section .text
- global IsBetweenAandB, RemCharCodeFromAToB, DebugStart, DebugEnd
- ;==========================================================================
- ; RemCharCodeFromAToB - removes all chars between a and e from str
- ; arguments:
- ; str - string to be processed
- ; a - start
- ; e - end
- ; return value:
- ; n/a
- ;--------------------------------------------------------------------------
- RemCharCodeFromAToB:
- ; standard entry sequence
- push ebp ; save the previous value of ebp for the benefi$
- mov ebp, esp ; copy esp -> ebp so that ebp can be used as a $
- ; accessing arguments
- ; [ebp + 0] = old ebp stack frame
- ; [ebp + 4] = return address
- mov edx, [ebp + 8] ; string address
- while_loop_rcc:
- mov cl, [edx] ; obtain the address of the 1st character of the string
- cmp cl, 0 ; check the null value
- je while_loop_exit_rcc ; exit if the null-character is reached
- mov al, cl ; save cl
- mov cl, [ebp + 16] ; end-char
- push cx ; push end-char
- mov cl, [ebp + 12] ; start-char
- push cx ; push start-char
- push ax; ; push ch
- call IsBetweenAandB
- add esp, 12
- cmp eax, 0 ; if(ch is not between 'a' and 'e')
- je inner_loop_exit_rcc
- mov eax, edx ; copy the current address
- inner_loop_rcc:
- mov cl, [eax+1]
- cmp cl, 0
- je inner_loop_exit_rcc
- mov [eax], cl
- inc eax
- jmp inner_loop_rcc
- inner_loop_exit_rcc:
- inc edx ; increment the address
- jmp while_loop_rcc ; start the loop again
- while_loop_exit_rcc:
- ; standard exit sequence
- mov esp, ebp ; restore esp with ebp
- pop ebp ; remove ebp from stack
- ret ; return the value of temporary variable
- ;===================================================================
- DebugStart:
- mov eax, 'x'
- call PrintChar_db
- ret
- DebugEnd:
- mov eax, 'y'
- call PrintChar_db
- ret
- ;===================================================================
- ; IsBetweenAandB - tests a character if it is between 'a' and 'b'
- ; arguments:
- ; ch = character to be tested
- ; a = start character
- ; b = end character
- ; return value:
- ; 1 = yes
- ; 0 = no
- ;----------------------------------------------------------------
- IsBetweenAandB:
- push ebp
- mov ebp, esp
- ; [ebp] = old ebp stack frame
- ; [ebp + 4] = return address
- mov eax, [ebp + 8] ; [ebp+8] = ch
- push ecx
- mov ecx, [ebp + 12] ; 'a' = start
- mov edx, [ebp + 16] ; 'e' = end
- cmp eax, ecx ; compare 'ch' with 'a'
- jae next_test_ibab ; if(ch>='a')
- jb set_zero_ibab ; if(ch<'a')
- next_test_ibab:
- cmp eax, edx ; compare 'ch' with 'e'
- jbe set_one_ibab ; if(ch<='e')
- ja set_zero_ibab ; if(ch>'e')
- set_one_ibab:
- mov eax, 1
- jmp returns_ibab
- set_zero_ibab:
- mov eax, 0
- returns_ibab:
- pop ecx
- mov esp, ebp
- pop ebp
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement