Author Topic: How to calculate ....  (Read 753 times)

Amadeus

  • Regular Member
  • *
  • Posts: 21
How to calculate ....
« on: June 05, 2022, 01:40:28 AM »
the size of code between 2 labels?

my approach/idea was:

Code: [Select]
@Start:
some code here
        .
        .
        .

@End:

lea ebx, @End
lea edx, @Start

sub ebx,edx

but all i get is this error:
Code: [Select]
error A2138: invalid data initializer
tia
Amadeus

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: How to calculate ....
« Reply #1 on: June 05, 2022, 01:44:40 AM »
CodeSize

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

Amadeus

  • Regular Member
  • *
  • Posts: 21
Re: How to calculate ....
« Reply #2 on: June 05, 2022, 02:14:11 AM »
thanks @jj2007

the code is:
Code: [Select]
.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
« Last Edit: June 05, 2022, 04:32:55 AM by Amadeus »

NoCforMe

  • Member
  • *****
  • Posts: 1124
Re: How to calculate ....
« Reply #3 on: June 27, 2022, 11:59:45 AM »
Don't forget the "$' operator, which gives you the current address in your code (or data):
Code: [Select]
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.

Amadeus

  • Regular Member
  • *
  • Posts: 21
Re: How to calculate ....
« Reply #4 on: July 01, 2022, 12:41:28 AM »
thanks for the tip