flat assembler
Message board for the users of flat assembler.
Index
> Windows > Coding style for large projects |
Author |
|
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 |
|||
04 Dec 2009, 04:44 |
|
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.
|
|||
04 Dec 2009, 17:50 |
|
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 _________________ Previously known as The_Grey_Beast |
|||
04 Dec 2009, 22:24 |
|
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.
|
|||
04 Dec 2009, 23:00 |
|
madmatt 09 Dec 2009, 00:31
bitshifter wrote: Hello 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 , most of the CPP (OOP) code I've seen looks like the spaghetti code of early 80's BASIC (GOTO's everywhere ). 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! |
|||
09 Dec 2009, 00:31 |
|
Borsuc 09 Dec 2009, 20:56
madmatt wrote: and in OOP a lot of lines of code does very little! _________________ Previously known as The_Grey_Beast |
|||
09 Dec 2009, 20:56 |
|
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 |
|||
10 Dec 2009, 03:09 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.