flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > [DONE]High Level Programming Language

Author
Thread Post new topic Reply to topic
BlastWave



Joined: 05 Oct 2006
Posts: 6
BlastWave 20 Oct 2006, 18:02
Im trying to make my own programming language. DON'T STOP READ!
Im not asking for source, parsing etc so please don't stop reading or/and get mad!.
I have program for quite a while now, i know the basic stuff plus a bit more. But i have troubles with the variables. I need some like dynamic arrrays(c++ vectors) for hold my variables, I ofcourse used lot of time research google/search here so please don't tell me to UTFG(Use the f*cking google).
The way i see it there are a couple of interresting ways to do it. First one is this simpelst but also the most ugly and bruggy and cannot not changed if needed.
Code:
rept 1024 cc {
var_name#cc rb 20         ; MAX 20!
var_value#cc rb 100        ; MAX 100! :(
}
    

as you can see its ugly and bad becuase its gonna fill LOT in the execute plus if someone make a really big library it cannot use all variables.

Second is more better "style" and could be nice too BUT still ppl can ran outta memory.

Code:
rept 1024 cc {
var_name#cc dd 0
var_value#cc dd 0
}
    


Then after make a GlobalAlloc/VirtualAlloc when a new variable is used and put the stuff in but it can still run outta memory when big librarys is made.

The last thing i think about is only a idea i try made it become true but got whiped my HD so lost the source of the "non working" code so i try recover it from my mind plus a bit more "working".
Code:
invoke GlobalAlloc,GMEM_FIXED,0                 ; Make 0 Variables
mov [mem],eax

; Now we need one variable with value aka two dwords.
add dword[var_size],1
mov eax,dword[size]
mul eax,8
invoke GlobalReAlloc,[mem],eax,GMEM_MOVEABLE    ; Now we Allocated the memory so we 8bytes more space aka 2 * dwords
mov [mem],eax                                   ; Remember it.

mov eax,dword[var_size]                         ; Get the size to eax.
mul eax,8                                       ; Multiply it for get the real size
sub eax,8                                       ; The Variable name.
add eax,dword[mem]                              ; Now its the accutly address.
mov edi,eax                                     ; Esi is the Variable name.
add eax,4                                       ; The next dword (Variable value)
mov esi,eax                                     ; Edi is the variable value.

invoke GlobalAlloc,GMEM_FIXED,30                ; Make Space for the variable name max 30.
mov dword[esi],eax                              ; Save it

invoke GlobalAlloc,GMEM_FIXED,100               ; Make Space for the variable value max 100.
mov dword[edi],eax                              ; Save it


var_size     dd 0 ; The size of it.
mem          dd 0 ; The handler of all sub variables/values.
    

Is this just totaly dumb way doing it becuase i think it would be the best.
Hope you understand me and my code.
Please respect that I brought the source and only ask for a little currection.
Thanks in Advanges.


Last edited by BlastWave on 21 Oct 2006, 00:01; edited 1 time in total
Post 20 Oct 2006, 18:02
View user's profile Send private message Reply with quote
BlastWave



Joined: 05 Oct 2006
Posts: 6
BlastWave 20 Oct 2006, 22:53
I have added headers and bug fixed it so it work, but i still can't get it to work :S
Heres my snip
Code:
format PE console 4.0
include 'win32a.inc'

; Initiate.
invoke GlobalAlloc,GMEM_FIXED,0
mov [mem],eax


call AddArray

invoke lstrcpy,esi,theName            ; Im going use movsb instead of lstrcpy.  Just want it to work first..
invoke lstrcpy,edi,theMsg
mov eax,[mem]
add eax,4
invoke MessageBox,0,[mem],eax,0

call AddArray
invoke lstrcpy,esi,theName2
invoke lstrcpy,edi,theMsg2
mov eax,[mem]
add eax,4
invoke MessageBox,0,[mem],eax,0

invoke ExitProcess,0

theName  db 'hello()',0
theMsg   db 'im a variable',0
theName2 db 'hmm()',0
theMsg2  db 'me tooooo',0

AddArray:
add dword[var_size],1
mov eax,dword[var_size]
imul eax,4
invoke GlobalReAlloc,[mem],eax,GMEM_MOVEABLE    ; Now we Allocated the memory so we 8bytes more space aka 2 * dwords
mov [mem],eax                                   ; Remember it.

mov eax,dword[var_size]                         ; Get the size to eax.
imul eax,8                                      ; Multiply it for get the real size
sub eax,8                                       ; The Variable name.
add eax,dword[mem]                              ; Now its the accutly address.
mov edi,eax                                     ; Esi is the Variable name.
add eax,4                                       ; The next dword (Variable value)
mov esi,eax                                     ; Edi is the variable value.

invoke GlobalAlloc,GMEM_FIXED,30                ; Make Space for the variable name max 30.
mov dword[esi],eax                              ; Save it

invoke GlobalAlloc,GMEM_FIXED,100               ; Make Space for the variable value max 100.
mov dword[edi],eax                              ; Save it
ret


var_size     dd 0 ; The size of it.
mem          dd 0 ; The handler of all sub variables/values.


section '' import data readable
library user32,'user32.dll',\
        kernel32,'kernel32.dll'

import  user32,\
        MessageBox,'MessageBoxA'


import kernel32,\
       lstrcpy,'lstrcpy',\
       GlobalAlloc,'GlobalAlloc',\
       GlobalReAlloc,'GlobalReAlloc',\
       ExitProcess,'ExitProcess'
    


Im thinking about using stack instead, seen ppl use it when googleing, and also here. Should I? and what "good" and "bad" would there be with it.

Thanks in advanges


I have try with stack's and work perfeclty for my needs. I will post the code for learning.
Code:
format pe console 4.0
include 'win32a.inc'

mov edi,ebp

sub edi,8
invoke GlobalAlloc,GMEM_FIXED,1024
invoke lstrcpy,eax,one
mov [edi],eax

invoke GlobalAlloc,GMEM_FIXED,1024
invoke lstrcpy,eax,oneone
mov [edi + 4],eax

sub edi,8
invoke GlobalAlloc,GMEM_FIXED,1024
invoke lstrcpy,eax,two
mov [edi],eax
invoke GlobalAlloc,GMEM_FIXED,1024
invoke lstrcpy,eax,twotwo
mov [edi + 4],eax


cmp ebp,edi
je arrayexit
@@:
invoke MessageBox,0,[edi],[edi + 4],0
add edi,8
cmp edi,ebp
je arrayexit


jmp @B
arrayexit:

invoke ExitProcess,0
one    db 'the one',0
oneone db 'oneee oneee',0
two    db 'der two',0
twotwo db 'twooo twoooo',0




section '' import data readable
library kernel32,'kernel32.dll',\
        user32,'user32.dll'


import  user32,\
        MessageBox,'MessageBoxA'

import kernel32,\
       ExitProcess,'ExitProcess',\
       GlobalAlloc,'GlobalAlloc',\
       lstrcpy,'lstrcpy'
    


Sorry for wastefull topic i didn't think i would have the solutions on my own hands :oops:


GoodBye for now
Post 20 Oct 2006, 22:53
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 21 Oct 2006, 13:22
1. you are forgetting to check return value from Global(Re)Alloc / GlobalFree.

2. you are creating array of size 4*var_size, but accessing it as if it was 8*var_size. one of these two is wrong:
Code:
imul eax,4
imul eax,8                                      ; Multiply it for get the real size    

i believe it's the first one, you may want "imul eax,8" or "shl eax, 3"
Post 21 Oct 2006, 13:22
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number 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.