flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
kevin
how to realize the DUP work in fasm?
just like in tasm/masm.[/i][/code] |
|||
![]() |
|
veach1
and what about
Code: buffer db 256 dup 0 how to declare string variables |
|||
![]() |
|
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 |
|||
![]() |
|
Tomasz Grysztar
1) might be also:
Code: label buffer byte times 256 db 0 |
|||
![]() |
|
veach1
Thank you all.
Last exmple fills buffer with 256 zeros, I assume that Code: buffer rb 256 |
|||
![]() |
|
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.
|
|||
![]() |
|
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? |
|||
![]() |
|
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). |
|||
![]() |
|
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. |
|||
![]() |
|
veach1
Thank you.
|
|||
![]() |
|
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! ![]() Thanks! ![]() |
|||
![]() |
|
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] |
|||
![]() |
|
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 |
|||
![]() |
|
Tomasz Grysztar
Quote:
You did mean db ?, not db 0, didn't you? |
|||
![]() |
|
Matrix
Privalov wrote:
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 |
|||
![]() |
|
simpaticool
Thanks!
I hope u are not upset! ![]() |
|||
![]() |
|
Tomasz Grysztar
And the latest fasm finally supports also the DUP operator compatible with TASM's.
|
|||
![]() |
|
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 -||__/ .|+-~ .|| || |
|||
![]() |
|
Matrix
Hy
Okey now we are full of DUP threads on this board. newbies, pls read the FASM documentation and the faqs:
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.