Code: Select all
asm do
' ...
end
The following inline assembly example is from the SharpBASIC system library and copies a block of memory. Note that inside assembly code blocks, comments start with a semicolon.
Code: Select all
' ----------------------------------------------------------------------------
' COPY MEMORY
' ----------------------------------------------------------------------------
' copy a memory block
' _saddr: source address
' _daddr: destination address
' _len: length in bytes to be copied
' ----------------------------------------------------------------------------
sub cpmem(_saddr: ptr, _daddr: ptr, _len: uint)
do
asm do
push esi
push edi
push eax
push ecx
mov ecx, [_len] ; length
cmp ecx, #h0 ; larger than 0 ?
jle .__out
mov esi, [_saddr] ; source
mov edi, [_daddr] ; destination
.__copy:
mov al, [esi] ; from source
mov [edi], al ; to destination
inc esi ; increment pointers
inc edi
dec ecx ; decrement counter
cmp ecx, #h0 ; done?
jne .__copy
.__out:
pop ecx
pop eax
pop edi
pop esi
end
end
Code: Select all
mov esi, _local_var ; NOT ok
lea esi, [_local_var] ; OK