Another example for the manual:
Around the first function, I have put a more typical framework, which involves preserving important registers, allocating workspace for local variables and giving parameters proper names to refer to. The EBX register also gets an address to the o2 runtime kernel.
You will find that this is typical of compiled functions in other languages - but with Assembly code, if your function does not alter ebx esi or edi or use local variables then you can dispense with the overhead.
[code=thinbasic]
' Asmosphere
' test Declare .. at
uses "OXYGEN"
dim src as string
src="
indexers `ebp` offset 8 ascending ' params
var 4 cchar ' params passed on stack
indexers `ebp` offset 0 descending ' locals
var 4 a b c d ' local stack variables
push ebp '
mov ebp,esp ' set up local ptr
sub esp,100 ' space for locals
push ebx ' save vital registers
push esi '
push edi '
mov ebx,KERNEL ' base address of o2 kernel funs
;------- start here
mov eax,cchar
and eax,0xff
(
cmp al,97
jl exit
cmp al,122
jg exit
sub al,32
)
;------ restore status quo
pop edi
pop esi
pop ebx
mov esp,ebp
pop ebp
ret 4 ' return releasing param bytes from stack (stdcall)
"
o2_buf 1 : o2_asmo src
if len(o2_error) then msgbox 0,o2_view src : stop
Declare Function upper (ByVal cChar As Byte) As Long at o2_buf 1
src="
xor eax,eax
mov al,[esp+4]
(
cmp al,65
jl exit
cmp al,90
jg exit
add al,32
)
ret 4
"
o2_buf 2 : o2_asmo src
Declare Function lower (ByVal cChar As Byte) As Long at o2_buf 2
msgbox 0,"uppercase of ascii 100 is "+upper (100) + $crlf + _
"lowercase of ascii 68 is "+lower (6 + $crlf
[/code]
Bookmarks