flat assembler
Message board for the users of flat assembler.

Index > Main > times vs dup? And ' symbol?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1082
Roman
What is times and dup differents ?
Code:
times 16 db 0x0f
db 16 dup (0x0f)
    

What is this mean ?
Code:
dq 0F0F0F0F'0F0F0F0Fh    

I am about symbol ' in hex value
Post 20 Jan 2021, 12:02
View user's profile Send private message Reply with quote
Calanor



Joined: 19 Jul 2015
Posts: 32
Location: Sweden
Calanor
Regarding the second question, in this particular context a single quote can be used as a separator to increase readability. A value expressed as "10'000" is simply treated as 10000. I'd actually forgotten about this feature until your post reminded me! Smile
Post 20 Jan 2021, 13:21
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1082
Roman
O !
times 2000 nop
Do repeat 2000 asm command nop !
As rept 2000 { nop }

Some times its usefull.
Post 20 Jan 2021, 15:12
View user's profile Send private message Reply with quote
Calanor



Joined: 19 Jul 2015
Posts: 32
Location: Sweden
Calanor
Well, yes, "times" can be useful. I don't know exactly what goes on behind the scenes when it comes to "times" vs "dup", although I presume that using the former to create data would result in longer compilation times than when using the latter.
Post 20 Jan 2021, 15:33
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18222
Location: In your JS exploiting you and your system
revolution
Calanor wrote:
... I presume that using the former to create data would result in longer compilation times than when using the latter.
Test it.
Post 20 Jan 2021, 22:32
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7938
Location: Kraków, Poland
Tomasz Grysztar
Roman wrote:
What is times and dup differents ?
Code:
times 16 db 0x0f
db 16 dup (0x0f)
    
There is no substantial difference when these constructs are used like here, they differ in how you can use them with other things. First, you can put a label before DB that would be automatically considered a label for a byte-sized data, while TIMES cannot be labeled - you can put a label followed by ":" before it, but this works the same as with any other instruction and is not considered related to the statement that follows. So to make the same kind of label for a TIMES statement you'd need to use additional directive:
Code:
buffer db 16 dup 0x0f

label buffer:byte
times 16 db 0x0f    
Also, DUP works only with data values, while TIMES can be used with any instructions (it is more or less just a shortened single-line form of REPEAT).
Roman wrote:
What is this mean ?
Code:
dq 0F0F0F0F'0F0F0F0Fh    

I am about symbol ' in hex value
Both the ` and _ (single quote and underscore) can be used to separate the digits in numbers. This is a purely visual aid, you can use it to group the digits to emphasize their positions and counts (for example to mark bit fields), or just to make a number easier to read.
Post 21 Jan 2021, 09:13
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1082
Roman
Thanks Tomasz.

What is this and what is mean ?
label buffer:byte

I compile this in code.

Code:
.code:
Start:
       mov     eax, buffer
label buffer:byte
    

IDA Pro show eax = address buffer
Like simple label.
Code:
.code:
Start:
       mov     eax, lb1
lb1:
    

But what magicaly in buffer:byte ?
Post 21 Jan 2021, 10:09
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7938
Location: Kraków, Poland
Tomasz Grysztar
Compare this:
Code:
buffer:
db 0

mov [buffer],1   ; Error: operand size not specified
add [buffer],ax  ; add word [buffer],ax    
Code:
buffer db 0

mov [buffer],1   ; mov byte [buffer],1
add [buffer],ax  ; Error: operand sizes do not match    
And analogously:
Code:
label buffer

mov [buffer],1   ; Error: operand size not specified
add [buffer],ax  ; add word [buffer],ax    
Code:
label buffer:byte

mov [buffer],1   ; mov byte [buffer],1
add [buffer],ax  ; Error: operand sizes do not match    
Post 21 Jan 2021, 10:28
View user's profile Send private message Visit poster's website Reply with quote
Calanor



Joined: 19 Jul 2015
Posts: 32
Location: Sweden
Calanor
revolution wrote:
Test it.
Yeah, I did a simple test and not surprisingly "dup" is considerably faster. On my machine, "times 200000000 db 100" (for those who don't want to count the 0's: 200 million) took 5.4 seconds to compile, while "db 200000000 dup 100" required 2.2 seconds. Adding parenthesis after the "dup" (i.e. "dup (100)") increased the time to 2.4 seconds.

As a side-note, one noteworthy difference between using "times" and "rept" is that "times" won't generate a truckload of lines, while "rept" does.
Post 21 Jan 2021, 12:49
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18222
Location: In your JS exploiting you and your system
revolution
Calanor: Good.

BTW: There is also repeat.
Post 21 Jan 2021, 12:55
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1082
Roman
Tomasz.
I try this.
Code:
    
     mov [.buffer],1 ;this put byte 
     jmp lp1
label .buffer:byte
lp1:
     mov [.buffer],1 ;this put dword 
label .buffer:dword  
    

Its cool !
How change dynamicly from label buffer:dword to label buffer:word ?
Code:
.data
buffer rb 4000
.code
   mov [buffer],1
   mov [buffer+1],2
;now i want write dword in buffer
buffer:dword
   mov [buffer],1
   mov [buffer+4],2
   
    

Its be nice and usefull.
For fill structs or buffers.
Post 21 Jan 2021, 14:18
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1082
Roman
' and _ not work in float values.
Code:
mov dword [val],48_828_125.0 ;error reserved word used as symbol
mov dword [val],48_828_125f ;error reserved word used as symbol

mov dword [val],48'828'125.0 ;error reserved word used as symbol
mov dword [val],48'828'125f ;error reserved word used as symbol
    
Post 25 Jan 2021, 12:13
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7938
Location: Kraków, Poland
Tomasz Grysztar
They do with fasmg.
Post 25 Jan 2021, 12:54
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.