The MASM Forum

General => The Campus => Topic started by: Amadeus on June 05, 2022, 01:40:28 AM

Title: How to calculate ....
Post by: Amadeus on June 05, 2022, 01:40:28 AM
the size of code between 2 labels?

my approach/idea was:


@Start:
some code here
        .
        .
        .

@End:

lea ebx, @End
lea edx, @Start

sub ebx,edx


but all i get is this error:
error A2138: invalid data initializer

tia
Amadeus
Title: Re: How to calculate ....
Post by: jj2007 on June 05, 2022, 01:44:40 AM
CodeSize (https://www.jj2007.eu/MasmBasicQuickReference.htm#Mb1221)

Btw your code works, too. Post the complete version, so we'll find out which line made it crash.
Title: Re: How to calculate ....
Post by: Amadeus on June 05, 2022, 02:14:11 AM
thanks @jj2007

the code is:

.data?
str1  dd ?
Hits dd ?

.code
start:
;#########################################################################
invoke crt_printf,chr$ ("Collatz Theorem",CR,LF,CR,LF)

@Start:
and Hits,0
mov str1,input("enter a number between 4 and 2000 : ")
mov esi,sval(str1)
push esi
invoke crt_printf,chr$ (CR,LF,CR,LF,"%d -> { "),esi
pop esi
mov ebx,3
.repeat
; test esi,1
.if !(esi & 1) ;ZERO?
mov eax,esi
shr eax,1
mov esi,eax
.if (eax != 1)
invoke crt_printf,chr$("%d, "),eax
.else
invoke crt_printf,chr$("%d }"),eax
.endif
.else
mov eax,esi
; mov ecx,3
mul ebx
add eax,1
mov esi,eax
invoke crt_printf,chr$("%d, "),eax
.endif
inc Hits
.until esi==1

@End:

lea ebx, @End
lea edx, @Start

sub edx,ebx

invoke crt_printf,chr$("used Bytes : %d ",CR,LF,CR,LF),edx


; invoke crt_printf,chr$ (CR,LF,CR,LF)

invoke crt_printf,chr$ (CR,LF,"%d -> Nodes",CR,LF),Hits

;#########################################################################
invoke wait_key
        invoke ExitProcess, 0
end start


PS: found it (sub edx,ebx) registers inverted

again thanky you @jj2007 have nice weekend

Amadeus
Title: Re: How to calculate ....
Post by: NoCforMe on June 27, 2022, 11:59:45 AM
Don't forget the "$' operator, which gives you the current address in your code (or data):

TokenParseChars DB ' ', ',', "'", 'H', $hexChar, $EOL, $EOF, ';'
$numParseChars EQU $ - TokenParseChars

gives you the number of characters in that list. You can put it in code segments too to measure distance.
Title: Re: How to calculate ....
Post by: Amadeus on July 01, 2022, 12:41:28 AM
thanks for the tip