flat assembler
Message board for the users of flat assembler.
Index
> DOS > problem with I\O |
Author |
|
LocoDelAssembly 03 Nov 2005, 20:08
Put all data below the code, you are executing the data instead of "mov ax,3d00h" and all the other instructions
|
|||
03 Nov 2005, 20:08 |
|
kb_08h 03 Nov 2005, 20:21
i tried to move data below the code, but recieved an error during compiling:
"mov dx,buffer error: undefined symbol." so i keep "buffer equ $" string before the main code, and put other data below the code as you say , program compiled, but it's still not working. =\ _________________ {D is for demoscene} |
|||
03 Nov 2005, 20:21 |
|
kb_08h 03 Nov 2005, 21:09
i've moved "buffer equ $" right to the end of the code, no error during compiling but also no good result after executing. looked the source in debugger, obviously program terminate after second 21h interrupt, so problem must be somewhere here
Code: mov [handle],ax mov bx,ax mov ah,3fh mov cx,0fde8h mov dx,buffer int 21h ;read file _________________ {D is for demoscene} |
|||
03 Nov 2005, 21:09 |
|
LocoDelAssembly 03 Nov 2005, 21:52
If you need to put the buffer at the end of the initialized data then do this:
Code: ;------------- data -------------- handle dw 0 mess_ok db 'file loaded sucsessfull$' mess_error db "where's this f***ing file?!$" file_name db 'sample.txt',0 buffer: Doing "buffer equ $" means that when you use "mov dx, buffer" will be assembled as "mov dx, $" which doesn't means that dx will be loaded with the offset of the end of initialized data. I don't know if you are using the int 21h properly but fix this first. [edit]Checked, here the code (exactly the same that yours except for the buffer): Code: org 100h use16 mov ax,3d00h mov dx,file_name int 21h jc error mov [handle],ax mov bx,ax mov ah,3fh mov cx,0fde8h mov dx,buffer int 21h mov ah,3eh mov bx,[handle] int 21h mov dx,mess_ok print: mov ah,9 int 21h int 20h error: mov dx,mess_error jmp print ;------------- data -------------- handle dw 0 mess_ok db 'file loaded sucsessfull$' mess_error db "where's this f***ing file?!$" file_name db 'sample.txt',0 buffer: I'd checked with debug and the buffer is loaded with the contents of the file too. [/edit] |
|||
03 Nov 2005, 21:52 |
|
kb_08h 04 Nov 2005, 05:45
so every time when i need to put buffer i should use "buffer:", right?
i replaced "buffer equ $" with "buffer:" and it works now; thank you guys for your support and attention. _________________ {D is for demoscene} |
|||
04 Nov 2005, 05:45 |
|
LocoDelAssembly 04 Nov 2005, 12:45
Well, just if you know what are you doing, for example putting
Code: buffer: anotherBuffer: both labels will share the same address so in this case will be better reserve bytes for buffer at least Code: buffer rb aSize ;aSize is a positive integer anotherBuffer: Now both buffers has their own address. I suggest always reserve space instead of using label for clarity and for having no problems with other executable formats like PE that will raise page fault using labels for buffers (except if you put "buffer: rb aSize" of course) when you traying to access them. In fact, only is safe to put a buffer with a label at the end of the source for binary and COM executables, for the other formats is risky. |
|||
04 Nov 2005, 12:45 |
|
rugxulo 31 Dec 2005, 22:30
ArrowASM 2.00c will work correctly with buffer equ $, but some others (e.g., LazyASM 0.52) will not. I've been told by LazyASM's author to use buffer=$ instead.
Also, something simple like SEMICOLON equ ';' will work in most assemblers but not LazyASM, so SEMICOLON=';' is again recommended. Go figure. |
|||
31 Dec 2005, 22:30 |
|
Borsuc 02 Jan 2006, 13:00
Fasm's equ is a preprocessor directive... it doesn't store any value. it simply replaces the contents with the defined value. if you want to store some numeric constant, use =, like
buffer = $ but in fact it's the same as declaring a label, but I prefer the label, since it's much clearer.. you could also use label buffer and, optionally, add a size specifying the size (byte, word, dword, etc). Fasm is very flexible and easy, yet powerful. Make sure you read the documentation to use it properly. Hope it helps |
|||
02 Jan 2006, 13:00 |
|
rugxulo 03 Jan 2006, 21:08
FASM is very powerful but perhaps a little confusing/overwhelming. The doc calls = a constant but it 'can be redefined' (which is odd wording).
constant : Unchanging in nature, value, or extent; invariable (from dictionary.com) I do not use FASM exclusively, but when I do use it, I avoid macros (convenient but non-standard) and strucs (yuk) and other fancy stuff, at least to minimize changes for other assemblers. I usually do NOT trust one program by itself since they all have bugs and odd features. P.S. In OpenWatcom 1.4 equ behaves differently than 1.3 did, plus blah=$ does not work like in LZASM, for instance. Also, NASM evaulates equ only once. equ in one assembler does not necessarily equal equ in another. [EDIT] As always, Privalov knows best. [/EDIT] Last edited by rugxulo on 05 Jan 2006, 01:54; edited 1 time in total |
|||
03 Jan 2006, 21:08 |
|
Tomasz Grysztar 04 Jan 2006, 15:03
Yeah, the "constant" term used here might be really confusing - this is mainly because this term was taken from other assemblers, where similar directives used to define the truly constant (not redefinable) values initially.
In fasm term "constant" is used for the compilation-time variables, as opposed to run-time variables. From the point of view of your program they are constants, from the point of view of your source they are variables. This is because flat assembler actually constist of two layers of language - the interpreted language used to make macros and other tricks, and the compiled language - the x86 instructions. The variables of interpreted language are called constants (as they are constants from the point of view of compiled language) - thus the confusion. |
|||
04 Jan 2006, 15:03 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.