News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

How to calculate ....

Started by Amadeus, June 05, 2022, 01:40:28 AM

Previous topic - Next topic

Amadeus

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

jj2007

CodeSize

Btw your code works, too. Post the complete version, so we'll find out which line made it crash.

Amadeus

#2
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

NoCforMe

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.
Assembly language programming should be fun. That's why I do it.

Amadeus