Just a curious thought went to my mind.

I was wonder how does everyone code when it comes to asm. For me I just stick to non-caps when it comes to asm. I wonder about the rest. Give me your comment. :)
Posted on 2003-06-12 08:21:19 by roticv
I use a traditional ASM style -- all opcodes have the same indentation. I don't use HLL constructs (such as .IF and .WHILE) because I work with other assemblers (for other processors) that don't have these.

Lots of comments and long variable names.

I use either mixed case or underscores to separate words within variable names. Default case is lower case.

I'm not a big fan of Hungarian except for one case -- I always use p for a pointer DWORD.
Posted on 2003-06-12 15:04:14 by tenkey
- everything is lower case except for the important parts I want to stress out.
- I never use .IF .WHILE ... except for specific situations like showing an example how to use a function properly, there are routines in code that really has a long list of things to do before you get to the main point and sometimes during this process, too much CMP's, TEST's are performed and can possibly lead to confusion.
- Descriptive labels.
- I always use a double underscore prefix for the label
- sometimes I follow hungarian notation when coding an app that requires you to show the source code to "professional" people. But aside from that I really don't care.
- create lots of templates, macros and functions. Reasons? the most unproductive part is the startup code where you spend a portion of your time initializing structures(win32 programming) - which is very common thing to do, so its best to be ready to have all the necessary "tools" for construction...
- I rarely comment except for the part I wish the person who looks at my code to understand what exactly it's doing...
- 1 tab inbetween the instuction and it's "required parameters"
- 2++(depends...) tabs when coding with the usage of MMX and SSE plus other macros that contains long names.
    punpckldq MM0, MM1


invoke LoadCursor, NULL, IDC_ARROW
mov [wcx+28], eax
invoke RegisterClassEx, wcx
notice punpckldq, it doesn't look nice with the invoke macro.... I want everything to be aligned
    punpckldq   MM0, MM1


invoke LoadCursor, NULL, IDC_ARROW
mov [wcx+28], eax
invoke RegisterClassEx, wcx
- indentation on loops. E.G.
__loop:

inc eax
cmp eax, ecx
jb __loop
There are still more. These are just the common things I keep in mind.
Posted on 2003-06-12 16:06:05 by arkane
i use lowercase everywhere, except for labels/variables, where i cap the first letter of each word except the first unless it is prefixed (e.g. lpszStringForBleh or timeVal)

i only prefix strings as lpsz, pointers /w a 'p' and handles /w an 'h' (the last only if it is written that way in the SDK doco).

i use .IF, .ENDIF, .ELSEIF for long sections executed conditionally (indented another space), my message loop, and when i'm debugging stuff. i comment the fuunction of my functions (ins and outs)... and individual lines if i'm having major problems /w bugs (writing down expected return values, etc). i also comment data structures.

i like short variable names and labels like perrMsg or hFileIn.
Posted on 2003-06-12 17:21:32 by jademtech
what is hungarian? unless you are referring to the language?

i use lowercase and align same as arkane, aside from my variables are all lowercase, i.e "hWnd" would be "hwnd", or maybe even "h_wnd" if the var name was long enough.

i love macros and write as many as i can, they are all prefixed with "_" and all my labels start with "@@".
Posted on 2003-06-13 07:42:02 by abc123
what is hungarian? unless you are referring to the language?

Hungarian notation is about name the variables according to their uses/function. For example pointers are prefixed with a 'p', handles prefixed with a 'h' and strings prefixed with 'sz'.

My code is
-lack of usage of proc, replaced by call labels (Generally no stack frame)
-lack of comments
-use hungarian notation (for handles and pointers)
-labels prefixed with 1 underscore
-labels not descriptive
-mostly lowcase

Sample code:


lea edi, _1byteopcode3
_stringopcode1:
movzx edx,byte ptr[esi]
shr edx,1
pushfd
cmp edx,[edi]
jnz @F
xor edx,edx
test ebx,prefix_F3h
jz _norep
push offset _rep
push [esp+8][8]
call stringcopy
_norep:
add edi,4
popfd
jc _stringnotbyte
push [edi]
push [esp+8][4]
call strcat
inc eax
retn 8
_stringnotbyte:
add edi,4
xor edx,edx
test ebx,prefix_66h
setz dl
lea edi,[edi+edx*4]
push [edi]
push [esp+8][4]
call strcat
inc eax
retn 8
@@:
popfd
add edi,4*4
dec ecx
jnz _stringopcode1
Posted on 2003-06-13 08:04:00 by roticv
In assembler I am using preferably Pascal (Delphi) style as most readble. Polish notation for labels and variables (every word begins with capital letter - CreateWindowEx ) the type of variables as prefix - hWnd, ptrArray. Long type names C Style like lpsz are only for Windows sys structures, they are meaningless for assembler where types are only byte, word or dword. I am using some prefixes like: cl - for color, h - hor handle, ptr - pointer, c - constant etc.

About procedures - local variables in stack frame if needed. Short procedures always with register argument passing. Local labels in the procedures.

Comments, everywhere, because I forget the project for 2 weeks and then I must remember what and why I am wrote in this source ;)
Posted on 2003-06-13 08:23:59 by JohnFound
MY code is just a big mess....
just kidding

-I use all lower case letters for instructions and it seems weird to me to read someone who uses all caps for their CPU opcdes.

-Make use of the .IF, .ENDIF if I want to test some flags (SIGN?, CARRY?) but not too heavily (especially in computationally heavy loops)

-I also tend to loop large source code files into one large file, a habbit that I must get rid of quickly.

-I also like using the registers the way they were defined and I rarely (if ever ) stray away from Intel's definition of how the register is to be used. (For example I almost ALWAYS use ECX as a counter, ESI and EDI as memory pointers, and EAX, EBX and EBX for mathematical operations)

-no labels prefexied with _

Some of my code:



SetFPUPrec PROC fpuprec:DWORD
.IF fpuprec==FPU_SINGLE
fstcw cword ;Store the FPU control word into LOCAL stack RAM
and cword,0FCFFh ;Set it
fldcw cword
;Load it back onto FPU
.ELSEIF fpuprec==FPU_DOUBLE
fstcw cword
and cword,0FCFFh
or cword,0200h
fldcw cword
.ELSEIF fpuprec==FPU_EXTENDED
fstcw cword
and cword,0FCFFh
or cword,0300h
fldcw cword
.endif

ret

SetFPUPrec endp

;Byte encoding 01h, nn <--WORD
inc [esi].PC ;Increment Program counter
push [esi].PC ;Push Z-80 program counter onto x86 stack
push Z80_READ ;Tell about read
push 0
call [esi].memproc ;Call
;AL has byte in Z-80
mov tempbyte,al ;Store in RAM
inc [esi].PC ;Increment Z-80 program counter
push [esi].PC
push Z80_READ
push 0
call [esi].memproc ;Read 2nd byte in AL
;Now if I recall correctly Z-80 is little endian so first byte goes into C and last byte goes
;into B
movzx ebx,[esi].BC ;Fetch state of Virtual Z-80 BC register
mov bl,al ;Store last byte into B
mov bh,tempbyte ;Store first byte into C
mov [esi].BC,bx ;Write back new register
;Invoke NEXTINSTRUCTION MACRO
NEXTINSTRUCTION


Messy isn't it?
Posted on 2003-06-15 18:04:35 by x86asm
My code seems different to understand at first glance, but I follow a strict pattern in coding. I tend to make all my procs "private" and most of them use esi and edi a lot.
Here's a sample:


;=====[[ Some Function >>===\
SomeFunction proc uses ebx esi edi me,x,y
local baka, file1
local f1:myfile ; my own types of files
local str1[260]:byte ; strings are always the last to define

; **** !! Note! If you change the structure, match the cr1 module's one,
; otherwise cr1 won't work


;---< Initiate variables >--\
lea eax,f1
mov file1,eax
mov ebx,me
;---------------------------/

;---< Load files >-----------------------------------------------------------\
; this loads a packed file
Scall [ebx].myProgram.LoadFile,CTEXT("c:\ilko.refill?SomeFolder\settings.ini")
or ebx,ebx
jz _ret ; Absolutely every function has this label!!
SetupMyFile
;----------------------------------------------------------------------------/

;--< Load string and get len >---\
invoke ReadStr,file1,addr str1,260
xor ecx,ecx
@@:
cmp str1[ecx],0
je @F
inc ecx
jmp @B
@@:
or ecx,ecx
jz _ret2
;--------------------------------/

;---< Do computation >--------------------------\
mov ebx,me
mov eax,[ebx].myProgram.ScrollBar1.ScrollTotalPos
mov ecx,[ebx].myProgram.ScrollBar1.ScrollTotalHei
mul ecx
mov ecx,720
div ecx
mov baka, eax
fild baka
fiload edx
fmul
fload 2.446
fmul
fistp baka
mov eax,baka
sub eax,17
mov [ebx].myProgram.ScrollBar1.ScrollPos,eax
;-----------------------------------------------/

msgbox "At last! My greatest work's complete! Nooooo, DeeDee...."
_ret2: FreeMyFile
_ret: ret
SomeFunction endp
;=======/

Explanatory: all functions have their variables named baka,file1 or esi2, or otherwise something specific "Key","ZoomY". If a variable consists of one word and I use this variable a lot, I will use lowcase. I use uppercase only for constants, and I find myself in a nightmare while looking at code that has "MOV EAX,7h", and is equally tabbed. Variables, named "file1" contain filehandles, or my custom filehandles. Variables "baka" are like a ninth register for me, and I use them to store data that is to be processed again later in the procedure. If I am short of such variables, I always make "local baka, baka2,baka3,baka4" but when I use them , I explicitly put a comment to show what stuff this variables contain in every significant moment of the procedure. When a large loop is to be executed, and it will use esi , I store the register into the local esi2. Strings (arrays) are named "str1, str2, str3" . Most procedures have "me" for its first argument, which is a pointer to some structure with data and functions' pointers.
I code with my XASM, as it gives me the power to hide the code that I do not need currently, so you see the ";=====[[ TAG_NAME >>===\" and ";=======/" tags, that define a block of code and its name. I use several macros at places that are not time-critical.
I use .if .endif at those places, too.
Posted on 2003-06-16 10:49:53 by Ultrano
Hmm. I usually have everything in lowercase, but some big, important subroutines get a capital first letter in their name (e.g. Drawsprites). I never use hungarian notation or leading underscores and I don't give names to temporary variables, because I'm not a big fan of typing. There are no comments, since I work alone. I wouldn't trust anyone to touch my code anyway :P

Here's some sample code from a 6502 project I'm working on:
...

getblock:
lda blkdata
sta 18
sec
sbc #$90
sta 11
lda (12),y
tay
asl
rol 11
asl
rol 11
sta 10
lda (17),y
and #3
tay
lda colors,y
rts
...

And an excerpt from an (incomplete) OPL3 emulator I made last summer, which emulates the OPL3 chip for users of the Creative SBPCI64 card running old DOS programs:
...

push byte 0
push ebx
push eax
int 32
dd 0x10063
add esp,12
pop eax
cli
mov dl,0xe8
mov [eax+0x37b2d],dl
mov edx,hook1-0x37b32
sub edx,eax
mov [eax+0x37b2e],edx
mov edi,oldjumps
lea esi,[eax+0x4b398]
mov ecx,8
rep movsd
lea esi,[eax+0x4b338]
mov ecx,8
rep movsd
...

After some hours of working with my code, you'd start to hurt yourself :P
Posted on 2003-06-16 16:31:44 by Sephiroth3
one main rule for good looking code is to be very strict! Just choose some conventions for your code, like caps or small letters, naming conventions, label conventions and apply them very strict on your text. This results in good readable and professional looking sources.
Posted on 2003-06-17 02:48:38 by beaster
my style is based on the order of everithing.

+Global Variables start as g_
+Local Starts as s_
+I sort all the variables for name, it takes longer time but lower for maintenance
+I write all my code as much coulmn aligned as possible
+No .IF .ENDIF as someone said some time ago, are we asm coders or what ?
+Divide program sections with big comments, plus descriptive commets of every routine

Sorry i'm at job now, can't past code image :(

B7
Posted on 2003-06-17 06:55:35 by Bit7