flat assembler
Message board for the users of flat assembler.

Index > Windows > Coding style for large projects

Author
Thread Post new topic Reply to topic
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 04 Dec 2009, 03:57
Hello
I am wondering about convention for organizing data/code in large projects.
Normally in HLL we can have a header file and a source file.
Only data in the source file is visible in its own files scope.
But data declared in the header file is visible by any reference to it.
So without many data and code sections how can this be done?
Maybe just to have a lot of sections and link them together?
The thing is that my project is getting very large and keeping data
all in one section is starting to get confusing, and its only getting worse.
Ok, thanks for your ideas...

_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.
Post 04 Dec 2009, 03:57
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak 04 Dec 2009, 04:44
Well, typically in HLLs this is handled by their scopes, as said. You could handle this with macros, or you could do what i do and name variables after their sections. You could also do what HLLs do behind the scenes and use the stack, but that would look messy to us. Personally, I like to name my variables (and jump locations) after the function or section of the code i'm operating. Take this code for a small OS i was working on for example:

Code:
;+----------------------------------+
;| GETS                             |
;| AH is the color byte             |
;| EBX is a pointer to a buffer     |
;| ECX is the length of this buffer |
;+----------------------------------+
isrGets_clr db 0
isrGets_CAPS db 0
isrGets:
   push ebx
    mov byte [isrGets_clr], ah
  sti
 dec ecx ;making room for null terminator
isrGets_loop:
       hlt
 cmp ah, 0x1C
        je isrGets_End
      call isrGets_SpecialCheck
   mov dl, [isrGets_CAPS]
      mov al, ah
  movzx eax, al
       or dl, dl
   cmovz dx, word [isrGets_SScan+eax]
  cmovnz dx, word [isrGets_CScan+eax]
 or dh, dh
   jz isrGets_loop ;ecx isn't subtracted because we don't support the letter
 mov byte [isrGets_PrintChar], dh
    mov byte [ebx], dh
  inc ebx
     push ebx
    push ecx
    mov bh, [isrGets_clr]
       mov esi, isrGets_PrintChar
  int 0x31
    pop ecx
     pop ebx
     loop isrGets_loop
isrGets_End:
       mov byte [ebx], 0
   cli
 pop ebx
     iretd
isrGets_SpecialCheck:
  cmp ah, 0x2A ;lshift down
   jne @f
      or byte [isrGets_CAPS], 1
@@:    cmp ah, 0xAA ;lshift up
     jne @f
      and byte [isrGets_CAPS], 6
@@:   cmp ah, 0x36 ;rshift down
   jne @f
      or byte [isrGets_CAPS], 2
@@:    cmp ah, 0xB6 ;rshift up
     jne @f
      and byte [isrGets_CAPS], 5
@@:   cmp ah, 0x3A ;capslock
      jne @f
      xor byte [isrGets_CAPS], 4
@@:   cmp ah, 0x0E
        jne @f
      cmp ebx, [esp+4]
    je @f
       inc ecx
     dec ebx
     pusha
       mov esi, isrGets_PrintChar
  mov byte [esi], 8
   mov bh, [isrGets_clr]
       int 0x31
    popa
        sub edi, 2 ;bugfix: Not sure why this bug is here... Might be even smarter to find out why instead of making this patch code...
@@:  ret
isrGets_PrintChar db 0
isrGets_SScan  db        0,   0,   0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=',   0,\ ;Lots of extra characters, I know, but i like to play safe.
                         9, 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']',   0,   0, 'a',\
                 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',  27, '`',   0, '\', 'z', 'x', 'c',\
                      'v', 'b', 'n', 'm', ',', '.', '/',   0,   0,   0,   0,   0,   0,   0,   0,   0,\
                       0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\
                     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\
                     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\
                     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\
                     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\
                     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\
                     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\
                     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\
                     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\
                     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\
                     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0
isrGets_CScan db        0,   0,   0, '!', '@', '#', '$', '%', '^', '&', '(', ')', '0', '_', '+',   8,\
                         9, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}',   0,   0, 'A',\
                       'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':',  22, '~',   0, '|', 'Z', 'X', 'C',\
                   'V', 'B', 'N', 'M', '<', '>', '?',   0,   0,   0,   0,   0,   0,   0,   0,   0,\
                         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\
                     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\
                     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\
                     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\
                     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\
                     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\
                     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\
                     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\
                     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\
                     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\
                     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0    
Post 04 Dec 2009, 04:44
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
Defsanguje



Joined: 07 Aug 2006
Posts: 7
Location: Finland
Defsanguje 04 Dec 2009, 17:50
My approach would be using FASM to generate .obj-files and then use a linker. I'd anyway suggest to use C++ or some other object-oriented language for large projects. Admit it or not, but HLLs are much more suitable for large projects than assembly or C.
Post 04 Dec 2009, 17:50
View user's profile Send private message MSN Messenger Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 04 Dec 2009, 22:24
asm maybe but C? OOP (C++) always (as most these days) puts me away from looking at source code, it makes it so hard to "get" what it does. Too much abstraction.

Also I hate about how difficulties you have to just compile some damn code sometimes. I like FASM because you don't need all sorts of packages or crap to compile. Sometimes when I want to make a small modification to open source programs, believe it or not, i find it easier to just disassemble it than to recompile the code Confused

_________________
Previously known as The_Grey_Beast
Post 04 Dec 2009, 22:24
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak 04 Dec 2009, 23:00
Ah, and i forgot that you could use macros and use the local variable feature of it. It'd be like coding in C and having a ton of functions, only you won't have all the extra work of linking or all that, just make sure you use the macro.
Post 04 Dec 2009, 23:00
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 09 Dec 2009, 00:31
bitshifter wrote:
Hello
I am wondering about convention for organizing data/code in large projects.
Normally in HLL we can have a header file and a source file.
Only data in the source file is visible in its own files scope.
But data declared in the header file is visible by any reference to it.
So without many data and code sections how can this be done?
Maybe just to have a lot of sections and link them together?
The thing is that my project is getting very large and keeping data
all in one section is starting to get confusing, and its only getting worse.
Ok, thanks for your ideas...


You can split up you assembly file into different sections, one file for all equates and structure definitions, another file for defined data, and a file for each category of functions
(Examples: matrix math, direct3d setup, direct3d mesh, etc., etc.). All the while using "Main.asm" to coordinate everything.

Borsuc wrote:
asm maybe but C? OOP (C++) always (as most these days) puts me away from looking at source code, it makes it so hard to "get" what it does. Too much abstraction.


I agree Exclamation , most of the CPP (OOP) code I've seen looks like the spaghetti code of early 80's BASIC (GOTO's everywhere Rolling Eyes ). One thing about those early basic days though is that a few lines of code did a lot, and in OOP a lot of lines of code does very little! Ahhhh, I miss the good ole' days.

_________________
Gimme a sledge hammer! I'LL FIX IT!
Post 09 Dec 2009, 00:31
View user's profile Send private message Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 09 Dec 2009, 20:56
madmatt wrote:
and in OOP a lot of lines of code does very little!
exactly

_________________
Previously known as The_Grey_Beast
Post 09 Dec 2009, 20:56
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4073
Location: vpcmpistri
bitRAKE 10 Dec 2009, 03:09
I have coded some very simple examples using NMAKE and FASM in a modular fashion. You will need some high-level organization at some point (inversely proportionate to the number of people working on the project, and depth proportionate to lines of code - imho).

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 10 Dec 2009, 03:09
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.