flat assembler
Message board for the users of flat assembler.
Index
> Tutorials and Examples > String processing routines |
| Author |
|
|
AsmGuru62 15 Dec 2025, 13:51
Very nice looking code!
Especially, I like how you use blank lines. I do that too. |
|||
|
|
FoXx 15 Dec 2025, 14:06
AsmGuru62 wrote: Very nice looking code! Thank you Blank lines separate code into blocks. I follow certain rules in my procedures. My principle is to use registers as often as possible. This speeds up my procedures. |
|||
|
|
FoXx 15 Dec 2025, 14:32
Useful command line splitting procedure.
Applied after the call [GetCommandLine] Code: ;------------------------------------------------ ; * * * Get paramameters of string ;------------------------------------------------ proc GetParamComnandLine ; mov EDI, TableParamameters ; mov ESI, szComnandLine mov EBX, EDI .scan: lodsb cmp AL, '"' je skip cmp AL, "'" je skip dec ESI mov AL, ' ' @@: mov DL, AL mov EAX, ESI stosd @@: lodsb cmp AL, ' ' jb .end cmp AL, DL jne continue mov EDX, ESI dec ESI xor EAX, EAX mov [ESI], AL mov ESI, EDX @@: lodsb cmp AL, ' ' jb .end je continue dec ESI jmp .scan .end: mov ECX, EDI xor EAX, EAX stosd dec ESI mov [ESI], AL mov EAX, ECX sub EAX, EBX shr EAX, 2 ; count of paramameters ret endp |
|||
|
|
AsmGuru62 16 Dec 2025, 01:29
I found out the strange thing about the command line parameters.
In C language, using the double quotes preserves blanks inside of the quotes. Everyone knows that, but what is interesting --- if there is no blank between, say, parameter #2 and parameter #3 --- the parameter includes all text. Here is an example: Code: PROGRAM.EXE -param1 -param2"C:\My Files Are Here\Source.Asm"more When PROGRAM.EXE is a C program, you get the following 2 parameters (not 3 or 4): Code: -param1 -param2C:\My Files Are Here\Source.Asmmore You see? Parameters are stuck together if you have no blanks. Very interesting. And I think, it is not a bug in C. Probably done to put the flag, like "-mydir" together with actual directory name: Code: PROGRAM.EXE -mydir:"C:\My Files Are Here" |
|||
|
|
revolution 16 Dec 2025, 01:42
Quote characters are not generally considered as separators, that's what spaces are for. Quotes are used to "hide" the spaces from the tokeniser.
|
|||
|
|
FoXx 16 Dec 2025, 07:59
revolution wrote: Quote characters are not generally considered as separators, that's what spaces are for. Quotes are used to "hide" the spaces from the tokeniser. And in old-school C programming, the convention was to not use long file names. AsmGuru62 wrote: I found out the strange thing about the command line parameters. Last edited by FoXx on 16 Dec 2025, 08:23; edited 1 time in total |
|||
|
|
FoXx 16 Dec 2025, 08:22
Finding a variable index by keyword.
Code: proc FindKeyWordIndex ; mov ESI, TableKeyWords ; mov EDX, length ; mov EAX, String push EBP mov EBP, EAX xor EAX, EAX mov EBX, EAX mov ECX, EAX @@: inc EBX ; index counter add ESI, ECX lodsb mov ECX, EAX ; end of table jECXz skip cmp EAX, EDX jne continue mov EDI, EBP repe cmpsb jne continue mov EAX, EBX @@: pop EBP ret endp Code: ; data section TableKeyWords DB 5,'Apple',4,'Pear',6,'Orange',6,'Banana',7,'Coconut',9,'Pineapple' TableParamIndex ANY_STRUCTURE ? Code: struct ANY_STRUCTURE Apple dd ? Pear dd ? Orange dd ? Banana dd ? Coconut dd ? Pineapple dd ? ends ; define a constant ERROR_INDEX = 0 APPLE_INDEX = 1 PEAR_INDEX = 2 ORANGE_INDEX = 3 BANANA_INDEX = 4 COCONUT_INDEX = 5 PINEAPPLE_INDEX = 6 mov ESI, TableKeyWords mov EDX, length mov EAX, String call FindKeyWordIndex or EAX, EAX jz .no_found mov EAX, [value] mov [TableParamIndex+EBX*4], EAX |
|||
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.