以下是我编写的x86汇编语言子例程,旨在从C程序调用:
;================================================================
; 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
add esp, 12 ;<------------------------------------------(1)
; [ebp] = old ebp stack frame
; [ebp + 4] = return address
mov eax, [ebp + 8] ; [ebp+8] = ch
push ebx ;<------------------------------------------(2)
mov ebx, [ebp + 12] ; 'a' = start
push edx ;<------------------------------------------(2)
mov edx, [ebp + 16] ; 'e' = end
cmp eax, ebx ; 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 edx ;<------------------------------------------(2)
pop ebx ;<------------------------------------------(2)
mov esp, ebp
pop ebp
ret
我在这里有两个问题:
add esp, 12
吗?ebx
和 edx
的旧值寄存器)?esp
造成任何干扰吗?