flat assembler
Message board for the users of flat assembler.
Index
> Main > struct ---> struc Goto page 1, 2 Next |
Author |
|
Tomasz Grysztar 08 Oct 2010, 16:32
To account for all the key features of "struct" it would have to look like this:
Code: struc @Header next,data_fullscan,prev_flag { .NEXT dd next+0 .DataFullScan dw data_fullscan+0 virtual at .DataFullScan .IDLE_CODE db ? .NUMB_LABEL dw ? .ADDR_LLT dd ? .SCAN_SP dd ? .NESTING dw ? .substr_end = $-$$ end virtual if .substr_end>$-.DataFullScan rb .substr_end-($-.DataFullScan) end if .PREV_FLAG dw prev_flag+0 } virtual at 0 @Header @Header sizeof.@Header = $ end virtual |
|||
08 Oct 2010, 16:32 |
|
ouadji 08 Oct 2010, 19:30
thank you very much Tomasz. it works fine. the full_struc for me is : Code: ;WINK_SEGMENT_HEADER_LENGTH struc @Header next,prev_addr,nb_char,reserved_,data_fullscan,\ prev_flag,free_db,free_dd { .NEXT dd next+0 .PREV_ADDR dd prev_addr+0 .NB_CHAR dd nb_char+0 .RESERVED_ dd reserved_+0 .Data_FullScan dw data_fullscan+0 virtual at .Data_FullScan .IDLE_CODE db ? .PROC_LABEL dw ? .ENDP__ dw ? .NUMB_LABEL dw ? .ADDR_LLT dd ? .SCAN_SP dd ? .NESTING dw ? .INDEX_PROC dd ? .FREE___ dd ? .substr_end = $-$$ end virtual if .substr_end>$-.Data_FullScan rb .substr_end-($-.Data_FullScan) end if .PREV_FLAG dw prev_flag+0 .FREE_DB db free_db+0 .FREE_DD dd free_dd+0 } virtual at 0 @Header @Header sizeof.@Header = $ end virtual but : A) why "+0" ?? B) Why is it necessary to add this: Code: virtual at 0 @Header @Header sizeof.@Header = $ end virtual To be allowed to do, for example : mov eax,[eax+ @Header.Data_FullScan] Why my code does not compile without that ? C) why this : Code: if .substr_end>$-.Data_FullScan rb .substr_end-($-.Data_FullScan) end if and not only this : " rb .substr_end " and nothing else. EDIT: (about "C") ok,i understood !!! IF "virtual/end virtual" > .Data_FullScan dw THEN rb x Last edited by ouadji on 08 Oct 2010, 19:49; edited 1 time in total |
|||
08 Oct 2010, 19:30 |
|
baldr 08 Oct 2010, 19:48
ouadji,
A) dw prev_flag+0 is a cute shortcut for Code: if prev_flag eq
dw 0
else
dw prev_flag
end if |
|||
08 Oct 2010, 19:48 |
|
ouadji 08 Oct 2010, 19:58
Code:
if prev_flag eq
dw 0
else
dw prev_flag
end i
thank you baldr, but i don't understand. Code: if prev_flag eq ;(nothing i guess) .PREV_FLAG dw 0 else .PREV_FLAG dw prev_flag wat's the difference between "dw 0" and " dw prev_flag" (in the case of this 'struct') |
|||
08 Oct 2010, 19:58 |
|
baldr 08 Oct 2010, 20:18
ouadji,
With this trick empty argument means 0 (+0, to be exact ). |
|||
08 Oct 2010, 20:18 |
|
ouadji 08 Oct 2010, 20:32
ok. YY dd X±y if X = no_thing then X = no_thing ± y = ±y (here '+y' with y=0) else X = y ± the_thing I guess that "?" doesn't exist with "struc" (like with "struct") ok, this allows to initialize each field ... in the absence of direct initialization |
|||
08 Oct 2010, 20:32 |
|
Tomasz Grysztar 08 Oct 2010, 21:29
baldr wrote: B) Another way to define sizeof.struct is to sum sizeofs of its fields, but with regard of alignment and nested structs / unions this task might be quite a challenge; much easier is to define an instance and measure its size. ouadji wrote: I guess that "?" doesn't exist with "struc" Code: if next in <,?> .NEXT dd ? else .NEXT dd next end if |
|||
08 Oct 2010, 21:29 |
|
baldr 08 Oct 2010, 21:45
ouadji,
That was (IIRC) trick from the pre-eq era, remnants can be seen in INCLUDE\MACRO\RESOURCE.INC still. As you may expect, «-0» works the same way (since +/- have lowest precedence). To detect (and use «?» instead of) empty macro argument, eq operator had to be devised. struc-macro is a macro of special behavior, in all other aspects it is exactly macro. So are instant macros like rept, irp or even so powerful match. Anyway, you may preprocess your source and see what develops. ----8<---- Tomasz Grysztar, Those are related, aren't they? I was emphasizing on the most apparent effect. Thanks for correction, though. |
|||
08 Oct 2010, 21:45 |
|
ouadji 08 Oct 2010, 21:45
Code: struc @Header ;nothing else here { .NEXT dd ? .PREV_ADDR dd ? .NB_CHAR dd ? ; "?" for all. (thank you Tomasz/baldr for your reply) indeed, "?" exists with "struc" like with "struct". this above does compile without any problem. |
|||
08 Oct 2010, 21:45 |
|
Tomasz Grysztar 08 Oct 2010, 22:08
baldr wrote: That was (IIRC) trick from the pre-eq era, remnants can be seen in INCLUDE\MACRO\RESOURCE.INC still. baldr wrote: Those are related, aren't they? I was emphasizing on the most apparent effect. Thanks for correction, though. |
|||
08 Oct 2010, 22:08 |
|
ouadji 08 Oct 2010, 22:18
Quote:
|
|||
08 Oct 2010, 22:18 |
|
bitRAKE 09 Oct 2010, 04:47
I like to use STRUC with VIRTUAL block instead of offsets because a change in base register results in a single place to change code. Also, the code seems more appealing to me. Of course, the use of offsets is more literal - matching the addressing being used.
Oh, notice the rbp+rcx*.tmp.. (I'm not evil, really.) Code: struc Temp { .a db ? .b db ? .. = $ - .a } virtual at rbp+rcx*.tmp.. .tmp Temp end virtual mov al,[.tmp.a] sub al,[.tmp.b] |
|||
09 Oct 2010, 04:47 |
|
ouadji 09 Oct 2010, 10:32
Code: mov al,[rbp+(rcx*2)] sub al,[rbp+(rcx*2)+1] I personally don't like this approach. This is powerful, I agree with you, but it removes any possibility of understanding the code directly by reading it. for me it's rather a way of complicating the code rather than simplified it. Quote: Also, the code seems more appealing to me. macros addict ? |
|||
09 Oct 2010, 10:32 |
|
bitRAKE 12 Oct 2010, 05:47
Quote: it removes any possibility of understanding the code directly by reading it. So, you'd rather look at a long string of instructions with a small variation? Do you stare at the sidewalk as you stroll through the park? I'm not the one using PROC/ENDP/STRUCT - I like the FASM language and use it - rather than an adapter layer for those familiar with another assembler. Seems we are coders of a similar nature really. |
|||
12 Oct 2010, 05:47 |
|
ouadji 12 Oct 2010, 09:57
I live in the woods, no cars, no traffic here, ... and no sidewalks ! it's paradise here ! Last edited by ouadji on 12 Oct 2010, 12:23; edited 5 times in total |
|||
12 Oct 2010, 09:57 |
|
edfed 12 Oct 2010, 11:29
ouadji wrote:
i dont find it hard to understand. it takes the byte at ebp +ecx*2, and sub the byte at ebp+ecx*2+1. it is not very hard to understand... |
|||
12 Oct 2010, 11:29 |
|
3200th 12 Oct 2010, 11:59
edfed wrote: i dont find it hard to understand. |
|||
12 Oct 2010, 11:59 |
|
ouadji 12 Oct 2010, 12:18
Quote:
how old am i ? that said, it's true that this : Code: struc Temp { .a db ? .b db ? .. = $ - .a } virtual at rbp+rcx*.tmp.. .tmp Temp end virtual mov al,[.tmp.a] sub al,[.tmp.b] Code: mov al,[rbp+(rcx*2)] sub al,[rbp+(rcx*2)+1] |
|||
12 Oct 2010, 12:18 |
|
3200th 12 Oct 2010, 13:46
ouadji wrote: how old am i ? |
|||
12 Oct 2010, 13:46 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.