Re: pointers to variables
- Posted by bernie Aug 02, 2009
- 1206 views
prickle said...
bernie said...
I already have dynamic assembler working on Euphoria.
All I want is call_backs to work in DOS.
Really? Can you tell me anything more about it? is it just an assembler?
This is a sample of how you can write assembler code in ver 4.0
of Euphoria with my include file.
I just would like to be able to do call_backs in DOS.
export function strlen(atom str) -- tested Asm("strlen_", "prolog4eu "& "cld "& "mov edi, [ebp+8] "& "xor eax, eax "& "or ecx, -1 "& "repne scasb "& "not ecx "& "dec ecx "& "mov eax, ecx "& "epilog4eu "& "ret 0 ",1,u) return f("strlen_",{str}) end function -- export function strspn(atom str1, atom str2) -- tested Asm("strspn_", "prolog4eu "& "cld "& "xor eax, eax "& "mov ecx, [ebp+8] "& "jmp ssp004 "& "ssp001: "& "inc ecx "& "mov edi, [ebp+12] "& "ssp002: "& "mov dh, [edi] "& "or dh, dh "& "jz ssp005 "& "cmp dl, dh "& "je ssp003 "& "inc edi "& "jmp ssp002 "& "ssp003: "& "inc eax "& "ssp004: "& "mov dl, [ecx] "& "or dl, dl "& "jnz ssp001 "& "ssp005: "& "epilog4eu "& "ret 0 ",2,u) return f("strspn_",{str1,str2}) end function -- export function strpbrk(atom str1, atom str2) -- tested Asm("strpbrk_", "prolog4eu "& "cld "& "mov eax, [ebp+8] "& "jmp sb004 "& "sb001: "& "mov ecx, [ebp+12] "& "sb002: "& "mov dh, [ecx] "& "or dh, dh "& "jz sb003 "& "cmp dl, dh "& "je sb005 "& "inc ecx "& "jmp sb002 "& "sb003: "& "inc eax "& "sb004: "& "mov dl, [eax] "& "or dl, dl "& "jnz sb001 "& "xor eax, eax "& "sb005: "& "epilog4eu "& "ret 0 ",2,u) return f("strpbrk_",{str1,str2}) end function -- export function strtok(atom buff, atom delim) -- tested Asm("strtok_", "prolog4eu "& -- -- "mov esi, [ebp+8] "& -- get buffer "test esi esi "& -- first call ? "jz nexttok "& -- no "mov [@ptr], esi "& -- save buffer "nexttok: "& -- "mov edi, [ebp+12] "& -- yes get delimit "mov esi, [@ptr] "& -- get current ptr "cmp esi, 0 "& -- "je near endtok "& -- bail out "push edi "& -- delimit "push esi "& -- buffer "mov eax, "&AGet("strspn")& -- << ---- << THIS IS A CALL BACK "call near eax "& -- find start of token "add [@ptr], eax "& -- goto first token "mov edi, [ebp+12] "& -- get delimit "mov esi, [@ptr] "& -- get current ptr "cmp esi, 0 "& -- "je near endtok "& -- bail out "cmp [esi], 0 "& -- pointing to zero ? "je near endtok "& -- bail out "push edi "& -- delimit "push esi "& -- buffer "mov eax, "&AGet("strpbrk")& -- << ---- << THIS IS A CALL BACK "call near eax "& -- find the end of the token "mov esi, [@ptr] "& -- get current ptr "cmp eax, esi "& -- "je near endtok "& -- "cmp eax, 0 "& -- "je exact "& -- "mov [@ptr], eax "& -- "mov edi, eax "& -- "mov eax, 0 "& -- "mov [edi], al "& -- "mov eax, esi "& -- "add [@ptr], 1 "& -- "epilog4eu "& -- "ret 0 "& -- "exact: "& -- "mov esi, [@ptr] "& -- get current ptr "push esi "& -- "mov eax, "&AGet("strlen")& -- << ---- << THIS IS A CALL BACK "call near eax "& -- "cmp eax, 0 "& -- "jne lasttok "& -- "jmp endtok "& -- "lasttok: "& -- "mov ecx, 0 "& -- "mov eax, [@ptr] "& -- get current ptr "mov [@ptr], ecx "& -- block next call "epilog4eu "& -- "ret 0 "& -- "endtok: "& -- "mov eax, 0 "& -- "epilog4eu "& -- "ret 0 "& -- "ptr: dd 0 ",2,u) return f("strtok_",{buff,delim}) end function