flat assembler
Message board for the users of flat assembler.

Index > Windows > Ugggghhhh...I need some encouragement

Thread Post new topic Reply to topic

Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 21 Feb 2011, 03:52
Ok So i thought I would implement a biological Virus cell. But Alas, being such a slacker and the fact that I'm tired. I decided to give up. Very Happy

The program was almost done and there are some debugging variables in there.

Feel free to take it as your own, i have no interest in it any more. My life is in need of encouragement, because I like to give up on things.

So here's the code. Assuming you know C/C++


format pe console 4.0

include 'win32ax.inc'
include 'api/kernel32.inc'

        INFINITE         EQU     0xFFFFFFFF
        GENERIC_LIFESPAN EQU     0xFA0 ; 4,000 Milliseconds
entry main

    notify_produce    db  '*A new cell with DNA code: [0x%x] has been produced by parent cell with DNA code: [0x%x]',10,10\
                         ,'Cell with DNA code: [0x%x] has children: %u.',10,10,0

    notify_Population db 'There is now a total of %u cell(s).',10,10,0

    notify_death      db 'Cell with DNA code 0x%x has died, Sad news !',10,13,0
    cell_age dd 0
    cell_stage dd 1;  stages are 1 to 6
    msg_0 DB 'This is a simple implementation of a biological virus cell.'\
             ,10,10,'This virus cell will grow and produce other viruses as it grows.'\
             ,10,10,'It will reproduce at a certain age and also die at a certain age.'\
             ,13,10,'|Created by typedef - 2011                                       |'\

    ;Create a structure holding the cell's info
    struct CELL
           dwDNA       dd ? ; DNA of the cell
           dwAge       dd ? ; How long has the cell lived ? Maximum age is 4 Minutes old
           dwChildren  dd ? ; How many cells has this 'mother-cell' reproduced ? Will alway end up to be 1 Smile
           dwTimeStamp dd ? ; When did it first come into existence (Calculated in Minutes)
           hHandle     dd ? ; Just a handle for destroying it so it doesn't clutter up in the system.
           dwCelliD    dd ? ; Will contain system thread id. This thread's ID, the child one will be dwDNA


           dwCellPop   dd 0 ; Cell population; Static data member

 cellParent CELL 0,0,0,0,0  ; Initialize first
 cellTemp   CELL

    proc main
     invoke SetConsoleTitle,'A biological virus cell implementation'
     cinvoke printf,msg_0
     mov     [cellParent.dwAge],1       ; Increase every 1000 Milliseconds
     INC     [dwCellPop]
     MOV     [cellParent.dwTimeStamp],1  ; If timestamp

     ; Create the parent cell
     push   cellParent.dwDNA
     push   0
     push   cellParent         ;Pass this cell's instance as a parameter
     push   The_Life_Of_A_Cell ;Give it a life (LOL, a life, atleast I have a life, and I have given a life to a thing)
     push   0
     push   0
     call   [CreateThread]

     mov    [cellParent.hHandle],eax

     XOR    EAX,EAX

     call   [GetCurrentThreadId]

     MOV    [cellParent.dwCelliD],EAX
     ; Now what, hmmmmm..... Wait for the cell, right ?
     invoke WaitForSingleObject,[cellParent.hHandle],INFINITE
            CMP EAX,WAIT_OBJECT_0

            JNE .Not_Done
            cinvoke  printf,'The virus ecosystem doesn''t exist anymore. Sad Huh ?'

     invoke system,'pause'

     push eax
     call [ExitProcess]
; This procedure creates another cell from the given cells DNA and ID
  proc  Make_Another_Cell_From_Cell
        PUSH ESP
        MOV  EBX,[ESP+4]

        MOV  EAX,[ESP+CELL.dwCelliD]

        MOV [cellTemp.dwCelliD],EAX
        MOV [cellTemp.dwDNA],0
        MOV [cellTemp.dwChildren],0
        MOV [cellTemp.dwTimeStamp],1
        MOV [cellTemp.hHandle],0
        MOV [cellTemp.dwAge],1

        invoke CreateThread,0,0,The_Life_Of_A_Cell,cellTemp,0,[cellTemp.dwDNA]
        MOV    [cellTemp.hHandle],EAX

        cinvoke WaitForSingleObject,EAX,INFINITE

        POP ESP

;As this program is the grand / mother of all cell's. It will create it's first child here
proc Cell_Reproduce ; void Cell_Reproduce(CELL *lpCell);
     MOV  EBX,[ESP+8]

          ccall Make_Another_Cell_From_Cell,EBX

          ;;;cinvoke printf,notify_death,[EBX+CELL.dwAge] this was here for testing, Jeez leave me alone Very Happy
     POP  ESP
proc Notify_Cell_Produced   ; VOID Notify_Cell_Produced (CELL *lpCell);
               ;not done
     POP ESP
; main cell Procedure
; This is the life of each cell. Each cell with have it's own image of this life
proc The_Life_Of_A_Cell;, LPVOID:DWORD <------- save some bytes here Smile


     MOV EBX,[ESP+8]
     ;Create a local variable pointing to this cell
     ; I was using EBP here, so It doesn't exist anymore. You'll know what to do

     MOV ECX,[EBX+CELL.dwChildren]

     INC [EBX+CELL.dwChildren]

     ;Print to screen the Cell's life data
     cinvoke printf,notify_produce,[EBX+CELL.dwCelliD],[EBX+CELL.dwDNA],[EBX+CELL.dwDNA],[EBX+CELL.dwChildren]
     MOV     EAX,[dwCellPop]
     ADD     EAX,[EBX+CELL.dwChildren]
     MOV     [dwCellPop],EAX
     cinvoke printf,notify_Population,[dwCellPop]

    ;Now, grow the cell up to four minutes, every second

     CMP   [EBX+CELL.dwAge], 120 ; 2minutes Is cell mature enough to reproduce ?  2 mins old yet ?
     JNE   .TooYoungOrTooOld

     ccall Cell_Reproduce,EBX


     CMP   [EBX+CELL.dwAge],GENERIC_LIFESPAN;  4 minutes, die mfkr die !! !!
     JGE   .Cell_Dies

     invoke     Sleep,1000 ;    Sleep for 1 second
     INC        [EBX+CELL.dwAge] ; aging ? every living thing grows, Hey :/
     JMP        .Grow_Cell

     invoke    CloseHandle,[EBX+CELL.hHandle]
     invoke    TerminateThread,[EBX+CELL.dwDNA]
    ; ADD       ESP,4    ;Clear the previous 4 allocated bytes
    ; <----------- Again, I was using EBP previously so don't be like 'Uhhhg'
          POP ESP

section '.idata' import data readable
        library kernel32,'kernel32.dll',\
                msvc  ,  'msvcrt.dll'
 import msvc,\

You can see that some procedures are not being called because I wasn't done. So yeah, have fun figuring it out: JK

I also have some other projects that I never finished Very Happy, you want the source? Ask & it shall be given to ya. Very Happy
Post 21 Feb 2011, 03:52
View user's profile Send private message Reply with quote

Joined: 21 Jul 2003
Posts: 3524
Location: vpcmipstrm
bitRAKE 23 Feb 2011, 03:54
Why a thread for each cell - are they computationally heavy objects?

You do realize cells can grow exponentially?
Post 23 Feb 2011, 03:54
View user's profile Send private message Visit poster's website Reply with quote

Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 23 Feb 2011, 05:46
the whole point of it was multithreading

get it now? Very Happy
and the cell is just a simple one with a life span of 4 mins.
Post 23 Feb 2011, 05:46
View user's profile Send private message 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.