flat assembler
Message board for the users of flat assembler.

Index > Main > Implementation of the 'yield' operator [HELP]

Author
Thread Post new topic Reply to topic
snify



Joined: 02 Dec 2004
Posts: 39
snify 28 Nov 2007, 23:21
I try to implement the python/c# yield operator in asm, but failed. Yield is multiple returning a value. [EDIT: Almost succeded]

Code:
format pe console 5.0
entry start

include 'C:\Program Files\FASM\include\win32a.inc'

fmt           db '%i',10,13,0
buff          rb 128

; print ints()
;
; sub ints()
; for i = 1 to 5
;     yield i
; next i
; end sub

macro yield val {
       mov    eax, val ; eax = current yield return value
       pushad          ; save all registers
       push   @f       ; [esp-4] = pointer to next opcode          [1]
       push   @b       ; [esp-0] = pointer to next yield operation [2]
       ret
@@:  ; [1]
       popad           ; load all registers
}


start:
       call   ints
@@: ; [2]
       invoke wsprintf,buff,fmt,eax
       add    esp, 4*3

       invoke WriteFile,7,buff,eax,0,0
       ret             ; continue the code in yield, jumps to [esp-0] [1]

       invoke ExitProcess,0

;proc intmul
;       push   ebp
;       mov    ebp, esp
;
;       call   ints
;       imul   eax, 5
;       yield  eax
;
;       mov    esp, ebp
;       pop    ebp
;       ret
;endp

proc ints
       push   ebp
       mov    ebp, esp

       mov    ecx, 1
@next:
       yield  ecx

       add    ecx, 1
       cmp    ecx, 5
       jng    @next

       invoke ExitProcess,0

       mov    esp, ebp
       pop    ebp
       ret
endp













section '.idata' import data readable

library kernel32,'KERNEL32.DLL',\
        user32,  'USER32.DLL'

include 'c:\program files\fasm\include/api/kernel32.inc'
include 'c:\program files\fasm\include/api/user32.inc'


    


Last edited by snify on 04 Dec 2007, 15:45; edited 1 time in total
Post 28 Nov 2007, 23:21
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.