flat assembler
Message board for the users of flat assembler.

Index > DOS > how to do DUP(@) work as in tasm

Author
Thread Post new topic Reply to topic
kevin



Joined: 10 May 2004
Posts: 1
kevin
how to realize the DUP work in fasm?
just like in tasm/masm.[/i][/code]
Post 22 May 2004, 03:46
View user's profile Send private message Yahoo Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
you have "times" diretive:
times <count> <instruction>
for example
times 5 db 30
or
times 10 db 'string',0

To repeat more than one line of code use "repeat" block:
repeat <count>
<code>
<code>
end repeat
Post 23 May 2004, 09:30
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
veach1



Joined: 16 Jul 2004
Posts: 165
veach1
and what about
Code:
buffer db 256 dup 0    

how to declare string variables
Post 16 Jul 2004, 09:29
View user's profile Send private message Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard
1)
Code:
times 256 db 0    

2)
Code:
some_string db "thats a string", 0
some_other_string db "and thats another string", 0    
etc
Post 16 Jul 2004, 09:37
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
1) might be also:
Code:
label buffer byte
times 256 db 0    
Post 16 Jul 2004, 09:47
View user's profile Send private message Visit poster's website Reply with quote
veach1



Joined: 16 Jul 2004
Posts: 165
veach1
Thank you all.

Last exmple fills buffer with 256 zeros, I assume that
Code:
buffer rb 256    
will be filled with junk, am I right?
Post 16 Jul 2004, 11:00
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
generally yes. But if this data isn't at end of section / file, it will be filled by zeroes, but better never rely on this.
Post 16 Jul 2004, 18:40
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
veach1



Joined: 16 Jul 2004
Posts: 165
veach1
Quote:
But if this data isn't at end of section / file, it will be filled by zeroes

Does it means that whole .com file (exept psp, code and data) will be filled with zeroes?
Post 17 Jul 2004, 06:40
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
nope, EXCEPT dat on the end. File like:
Code:
org 100h ;COM file
rb 10
db 'some data'
rb 10
    

will contain 10 zeroes and then 'some data'. Reserved data on the end will contain junk. In .COM file this isn't important, because it doesn't have headers and whole reamining memory is left for it. But in MZ or PE file, there is some variable in file header which says how much data should be reserved behind end of file image (.exe file).
Post 17 Jul 2004, 09:27
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
VitalOne



Joined: 29 Jul 2003
Posts: 54
Location: USA
VitalOne
Or you could do:
Code:
buffer: times 256 db 0
    


Or, using the fix directive you could do:
Code:
dup fix :times
    


Which would let you do:
Code:
buffer dup 256 db 0
    


Which is the closest I could get it to the original tasm/masm code. Well, you're still better off using the rb directive in my opinion.
Post 18 Jul 2004, 01:41
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
veach1



Joined: 16 Jul 2004
Posts: 165
veach1
Thank you.
Post 18 Jul 2004, 08:13
View user's profile Send private message Reply with quote
simpaticool



Joined: 12 Jan 2005
Posts: 16
Location: Romania
simpaticool
How do I access the array's elements?

In pascal if I had var v:array[1..5] of integer v[1] was the first element
v[2] was the second one ... and so on.

In C it was something like int v[10] v[0] was the first element and so on.

In asm how do I access array's elements?
I do understand that there is a big diff between asm and other programming
languages. I do understand that there are no variabiles in asm and that
xyz db ? it's just a label.
But I don't understand arrays (in fasm).
It was really easy in TASM.
But fasm is easy to use (example: mov dx,var_name)
so now I code only in fasm.

Please help me! Shocked

Thanks! Very Happy
Post 03 Feb 2005, 06:59
View user's profile Send private message Reply with quote
beppe85



Joined: 23 Oct 2004
Posts: 181
beppe85
The general pattern for loading an element is:
mov your_reg, [array+reg_index*element_size-bound_first*element_size]

your_reg is a GPR to hold the element
array means what it means
reg_index is a register containing the index into array
element_size is 1 for byte[], 2 for word[], 4 for dword[], etc...
bound_first is the index of first element; it was 1 on the pascal snippet and always 0 in C

For storing a value on array, the pattern is just the inverse, but it can accept an immediate source operand.

Code:
var v:array[1..5] of integer;
...
eax := V[2];    


Code:
v rd 5
mov edx, 2 ; index
mov eax, [v+edx*4-1*4]
    
Post 03 Feb 2005, 10:17
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
hello,
i will intrude a little:

var v:array[1..5] of byte;
var xy:array[1..10] of dword;
...
al := v[2];
eax := xy[5];

Code:

org 256 ; com offset

mov al,[v+1*(2-1)] ; offset + 1 (byte) * 2 nd element -1 ( so first element will be 1 )

mov eax,[xy+4*(5-1)] ; offset + 4 (dword) * 5 nd element ( so first element will be 1 )

; you can index using registers too
mov ebx,xy
mov eax,[ebx+4*(5-1)] ; offset + 4 (dword) * 5 nd element ( so first element will be 1 )

mov ebx,xy ; variable address
mov edx,xy ; element
mov eax,[ebx+4*(edx-1)] ; offset + 4 (dword) * 5 nd element ( so first element will be 1 )

int 20h ; exit
v:times 5 db 0 ; this fills zeroes if any other after
xy:times 4*10 db 0 ; this fills zeroes if any other after
    
Post 03 Feb 2005, 23:29
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
Quote:
Code:
v:times 5 db 0 ; this fills zeroes if any other after
xy:times 4*10 db 0 ; this fills zeroes if any other after
    

You did mean db ?, not db 0, didn't you?
Post 04 Feb 2005, 01:37
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
Privalov wrote:
Quote:
Code:
v:times 5 db 0 ; this fills zeroes if any other after
xy:times 4*10 db 0 ; this fills zeroes if any other after
    

You did mean db ?, not db 0, didn't you?


yeah, thank you

i meant this
Code:
v:times 5 db ? ; this fills zeroes if any other after
xy:times 4*10 db ? ; this fills zeroes if any other after
    

or this
Code:
v: rb 5 ; this fills zeroes if any other after
xy:rb 4*10 ; this fills zeroes if any other after
    
Post 04 Feb 2005, 04:44
View user's profile Send private message Visit poster's website Reply with quote
simpaticool



Joined: 12 Jan 2005
Posts: 16
Location: Romania
simpaticool
Thanks!
I hope u are not upset!
Very Happy
Post 10 Feb 2005, 06:44
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
And the latest fasm finally supports also the DUP operator compatible with TASM's.
Post 12 Jun 2005, 09:25
View user's profile Send private message Visit poster's website Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 604
Location: Germany
MCD
Privalov wrote:
And the latest fasm finally supports also the DUP operator compatible with TASM's.


I remember I asked you about it maybe a year ago or so, but EQUates are usually fine for it.

_________________
MCD - the inevitable return of the Mad Computer Doggy

-||__/
.|+-~
.|| ||
Post 13 Jun 2005, 07:44
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
Post 25 Jun 2005, 04:41
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.