flat assembler
Message board for the users of flat assembler.
Index
> Compiler Internals > segments in MZ format |
Author |
|
CandyMan 24 Oct 2016, 15:47
Why segments in MZ format are 16 bytes (paragraph) aligned?
Maybe they could be 1, 2, 4, 8 or 16-bytes aligned. _________________ smaller is better |
|||
24 Oct 2016, 15:47 |
|
Tomasz Grysztar 24 Oct 2016, 17:19
In MZ format the segment label is a symbol that can be used to get the number of given segment (like "mov ax,codeseg"). Incrementing the segment number by one is the same as moving to the next paragraph.
|
|||
24 Oct 2016, 17:19 |
|
CandyMan 24 Oct 2016, 17:28
these structure is possible:
Code: SegAlign 16 ; default segment The1st Data1st db 0 Dats2nd rb 16 SegAlign 2 segment The2nd Data3rd db 0 The1st = 0x0000 Data1st = 0x0000 Data2nd = 0x0001 The2nd = 0x0010 Data3rd = 0x0002 _________________ smaller is better |
|||
24 Oct 2016, 17:28 |
|
Tomasz Grysztar 24 Oct 2016, 17:34
When you have a code like this:
Code: segment The1st
rb 16
segment The2nd |
|||
24 Oct 2016, 17:34 |
|
CandyMan 24 Oct 2016, 17:40
this way I made a mistake (I mistook adress linear from segmental), but the idea is preserved
_________________ smaller is better Last edited by CandyMan on 24 Oct 2016, 17:44; edited 1 time in total |
|||
24 Oct 2016, 17:40 |
|
Tomasz Grysztar 24 Oct 2016, 17:42
If you tried to start a new segment in a middle of paragraph, you would need a fractional segment number, it is not possible.
|
|||
24 Oct 2016, 17:42 |
|
Tomasz Grysztar 24 Oct 2016, 18:46
After reanalyzing your sample I think that our misunderstanding came from the fact that you wanted a SEGMENT directive to serve just the role of providing segment address for a label, while fasm's SEGMENT creates the new segment literally. If you write:
Code: segment new
db 'abcdef' To set up segments under a different assumption, where you would be forced to use labels and they would not be guaranteed to start at 0, you'd need to write some kind of macro. Or perhaps even better, you could use fasmg and create an alternative MZ formatting macros operating under such different rules. |
|||
24 Oct 2016, 18:46 |
|
CandyMan 24 Oct 2016, 19:43
Indeed I meant so that the first segment begins from the zero, last also (empty segment - in order to get the size of the program), and centre sections were byte aligned. At a lot of sections it is possible to gain more free memory than if all were paragraph aligned.
It is possible to create it without macros but only define "SegAlign n" directive. _________________ smaller is better |
|||
24 Oct 2016, 19:43 |
|
Tomasz Grysztar 24 Oct 2016, 19:58
What you suggested is altering the meaning of SEGMENT semantically, to mean something similar as in the case of object output (which is meant to be processed by a linker). I would not want to alter semantic meaning of any of fasm's traditional constructions, but now at least I have fasmg that I can direct to - it exists exactly for this purpose, so that one can create macro packages implementing alternative language choices.
|
|||
24 Oct 2016, 19:58 |
|
CandyMan 24 Oct 2016, 20:18
I carried it out for own purposes and I would like to share it from others:
Code: segmentalign_directive: lods byte [esi] call get_dword_value cmp [value_type],0 jne invalid_use_of_symbol cmp eax,16 ja value_out_of_range bsf edx,eax jz value_out_of_range bsr ecx,eax cmp edx,ecx jnz invalid_value dec eax mov [seg_align_value],eax jmp instruction_assembled seg_align_value dd 15 Code: mz_segment: lods byte [esi] cmp al,2 jne invalid_argument lods dword [esi] cmp eax,0Fh jb invalid_use_of_symbol je reserved_word_used_as_symbol inc esi mov ebx,eax mov eax,edi sub eax,[code_start] if 1 ;* mov ecx,[seg_align_value] ;* add eax,[seg_align_value] ;* and eax,[seg_align_value] ;* else ;* mov ecx,0Fh add eax,0Fh and eax,1111b end if ;* sub ecx,eax mov edx,edi xor eax,eax rep stos byte [edi] mov eax,edx call undefined_data push ebx call create_addressing_space if 1 mov edx,15 ;* sub edx,[seg_align_value] ;* mov eax,edi ;* sub eax,[code_start] ;* and eax,edx ;* sub [ebx+0],eax ;* sbb dword [ebx+4],0 ;* end if ;* pop ebx mov eax,edi sub eax,[code_start] shr eax,4 cmp eax,10000h jae value_out_of_range mov edx,eax mov al,16 cmp byte [esi],13h jne segment_type_ok inc esi lods byte [esi] segment_type_ok: mov [code_type],al mov eax,edx mov ch,1 mov [address_sign],0 xor edx,edx xor ebp,ebp mov [label_size],0 mov [address_symbol],edx jmp make_free_label _________________ smaller is better |
|||
24 Oct 2016, 20:18 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.