Skip to content

Commit

Permalink
SIZEOF for area labels
Browse files Browse the repository at this point in the history
  • Loading branch information
tgrysztar committed Apr 16, 2023
1 parent 624f717 commit 7080971
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 9 deletions.
2 changes: 2 additions & 0 deletions core/docs/manual.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1898,6 +1898,8 @@ present in the original "virtual" block.

If an area label is used in an expression, it forms a variable term of a
linear polynomial. The metadata of such term is the base address of the area.
The metadata of an area label itself, accessible with "sizeof" operator,
is equal to the current length of data within the area.
There is an additional variant of "load" and "store" directives that allows
to read and modify already generated data in the output file given simply
an offset within that output. This variant is recognized when the "at" or
Expand Down
Binary file modified core/fasmg
Binary file not shown.
Binary file modified core/fasmg.exe
Binary file not shown.
Binary file modified core/fasmg.x64
Binary file not shown.
6 changes: 6 additions & 0 deletions core/source/directives.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4428,6 +4428,9 @@ load_value:
mov edx,[edi+ExpressionTerm.metadata]
test edx,edx
jz addressed_length_ok
cmp dword [edx],0
jne addressed_length_ok
add edx,4
mov esi,edi
mov ecx,4
mov edi,value_length
Expand Down Expand Up @@ -4490,6 +4493,9 @@ load_value:
mov edx,[edi+ExpressionTerm.metadata]
test edx,edx
jz output_offset_ok
cmp dword [edx],0
jne output_offset_ok
add edx,4
mov ecx,4
mov edi,value_length
call fit_value
Expand Down
33 changes: 25 additions & 8 deletions core/source/expressions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ calculate_parsed_expression:
cmp al,VALTYPE_ELEMENT
je push_element
cmp al,VALTYPE_AREA
je push_element
je push_area
cmp al,VALTYPE_STRING
je push_string
cmp al,VALTYPE_FLOAT
Expand Down Expand Up @@ -1297,10 +1297,10 @@ calculate_parsed_expression:
mov [edi+ExpressionTerm.value],ebx
jmp push_numeric_terms
numeric_terms_pushed:
add ebx,4
pop edx ecx
sub ecx,8
cmp ebx,ecx
jb symbol_metadata_ok
jbe symbol_metadata_ok
xor ebx,ebx
symbol_metadata_ok:
mov [edx+ExpressionTerm.metadata],ebx
Expand Down Expand Up @@ -1360,19 +1360,23 @@ calculate_parsed_expression:
push_float:
mov al,EXPR_FLOAT
jmp push_value
push_area:
mov esi,edx
jmp push_variable_term
push_element:
xor esi,esi
push_variable_term:
mov edx,calculation_workspace
mov ecx,3*sizeof.ExpressionTerm
call reserve_workspace
mov eax,EXPR_NUMBER
mov [edi+ExpressionTerm.attributes],eax
mov [edi+ExpressionTerm.metadata],esi
mov [edi+sizeof.ExpressionTerm+ExpressionTerm.attributes],eax
mov [edi+ExpressionTerm.value],zero_value
mov [edi+sizeof.ExpressionTerm+ExpressionTerm.value],singular_value
mov [edi+sizeof.ExpressionTerm+ExpressionTerm.metadata],ebx
xor eax,eax
mov [edi+ExpressionTerm.metadata],eax
mov [edi+2*sizeof.ExpressionTerm+ExpressionTerm.attributes],eax
and [edi+2*sizeof.ExpressionTerm+ExpressionTerm.attributes],0
add edi,3*sizeof.ExpressionTerm
jmp calculation_loop
base_address_value:
Expand Down Expand Up @@ -2536,7 +2540,7 @@ extract_metadata:
test ebx,ebx
jz replace_with_zero
test ecx,ecx
jz push_numeric_value
jz extract_label_metadata
mov edx,[ebx+SymbolTree_Leaf.definition]
test edx,edx
jz replace_with_zero
Expand All @@ -2547,13 +2551,26 @@ extract_metadata:
mov ecx,[edx+ValueDefinition.value_length]
jecxz replace_with_zero
jmp push_numeric_symbol

extract_size:
call pop_terms
mov ebx,[edi+ExpressionTerm.metadata]
test ebx,ebx
jz replace_with_zero
extract_label_metadata:
cmp dword [ebx],0
jne extract_area_size
add ebx,4
jmp push_numeric_value
extract_area_size:
call prepare_to_push_computed_value
xor edx,edx
mov eax,[ebx+ValueDefinition.value_length]
mov edi,[ebx+ValueDefinition.value]
sub eax,sizeof.AreaHeader
sub eax,[edi+AreaHeader.base_address_length]
add eax,[edi+AreaHeader.uninitialized_length]
adc edx,0
jmp push_output_position
extract_first_term_metadata:
call pop_terms
lea ebx,[edi+sizeof.ExpressionTerm]
Expand Down
Binary file modified core/source/macos/fasmg
Binary file not shown.
Binary file modified core/source/macos/x64/fasmg
Binary file not shown.
2 changes: 1 addition & 1 deletion core/source/version.inc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION equ "jz27"
VERSION equ "k0v2"

0 comments on commit 7080971

Please sign in to comment.