flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > How divided c number in rept ?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1872
Roman 25 Jan 2025, 13:41
Fasmw 1.73
Code:
rept 7 n:0,c:1000000000 { 
                     mov ebx,c
                     c equ (c/10)
                     mul ebx } 
    

IDA Pro show:
mov ebx,1000000000
mul ebx
mov ebx,1000000001
mul ebx
mov ebx,1000000002
mul ebx

I want get this:
Code:
mov ebx,1000000000
mul ebx
mov ebx,100000000
mul ebx
mov ebx,10000000
mul ebx    
Post 25 Jan 2025, 13:41
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20487
Location: In your JS exploiting you and your system
revolution 25 Jan 2025, 14:10
You have to use the 'c' variable outside of the rept.
Code:
c equ 1000000000
rept 7 n:0 {
        dd c
        c equ (c/10)
}    
Which allows you to use the native aritmetic:
Code:
c = 1000000000
rept 7 n:0 {
        dd c
        c = c/10
}    
Post 25 Jan 2025, 14:10
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1872
Roman 25 Jan 2025, 14:20
Thanks.
Work fine.
Post 25 Jan 2025, 14:20
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20487
Location: In your JS exploiting you and your system
revolution 25 Jan 2025, 14:40
You also don't need 'n':
Code:
c = 1000000000
rept 7 {
        dd c
        c = c/10
}    
Post 25 Jan 2025, 14:40
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20487
Location: In your JS exploiting you and your system
revolution 25 Jan 2025, 14:59
To illustrate what happens there, try to predict what this code will display:
Code:
rept 1 c:10 { c equ (c/10) }
display 10 + '0'    
It will display '1':
Code:
flat assembler  version 1.73.31  (16384 kilobytes memory)
1
1 passes, 0 bytes.    
Because the string '10' has been equated to '(10/10)' in the first line, since all strings matching 'c' are replaced with '10'.

The same code with comments explaining:
Code:
rept 1 c:10 { c equ (c/10) }    ; 10 equ (10/10)
display 10 + '0'                ; display (10/10) + '0'    
Post 25 Jan 2025, 14:59
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.