flat assembler
Message board for the users of flat assembler.
Index
> Main > FASMLIB tutorial part 1 |
Author |
|
pelaillo 24 Mar 2006, 13:33
Vid, you have awesome didactic capabilities. It's all very clear.
A suggestion for the error handling: Code: start: ;initialize modules call mem.init jc mem_error call str.init jc str_error ; ... do the work ... ;uninitialize modules call str.uninit jc str_error call mem.uninit jc mem_error ;exit process push dword 0 call exit mem_error: call mem.last_error ;last error in eax to do further handling jmp error str_error: call str.last_error ;last error in eax to do further handling jmp error error: ;try to uninitialize what we can call str.uninit call mem.uninit ;exit with code -1 push dword -1 call exit |
|||
24 Mar 2006, 13:33 |
|
vid 28 Mar 2006, 01:37
pellialo: error handling is more advanced than described here.... i'll cover it later. and it will be even more advanced in future (ability to store call stack with argument values, on error). Of course this will be optional.
|
|||
28 Mar 2006, 01:37 |
|
Reverend 28 Mar 2006, 09:35
pelaillo: Why create whole new proc xxx.last_error? I guees that every proc should alert error by setting CF and also copy error code to eax immidietaly. So it would be always obvious that when CF is set, eax contains info about error (and if implemented in whole library - it would be easy to accustom for particulaer programmer)
|
|||
28 Mar 2006, 09:35 |
|
RedGhost 28 Mar 2006, 11:17
Reverend wrote: pelaillo: Why create whole new proc xxx.last_error? I guees that every proc should alert error by setting CF and also copy error code to eax immidietaly. So it would be always obvious that when CF is set, eax contains info about error (and if implemented in whole library - it would be easy to accustom for particulaer programmer) i agree this is the best approach (also much simpler and probably faster than all that redundant HLL error handling) _________________ redghost.ca |
|||
28 Mar 2006, 11:17 |
|
vid 28 Mar 2006, 12:34
error code in eax is interesting... but now it always copies error code to [err] variable, which i think is somewhat better, you can need eax in error handling and then you
also error descirption is always in [err.str]. I also found nice way to make unique error code (you can be sure that if you declare new error, it's code is not used). Trick is using label of error message as error code. So [err] is always address of simple error message: Code: ERR_FILE_NOT_FOUND db "File not found",0 ... mov [err], ERR_FILE_NOT_FOUND but sometimes you can get error message from system, in such cases error message can be something like ERR_FILE_NOT_FOUND and description is gotten from system, like "Invalid path", "Invalid drive" etc. Also in future there will be stack trace i mentioned included, and maybe some formatted messages: "MyProc - Invalid argument #4 - fileHandle (00004ACC)" So [err] is used for your program to find out what didn't work (file not found) and [err.str] is for user (path doesn't exist). Error handling will be better described in future. I have not even completely implemented this yet, there are still few issues i need to solve with this. |
|||
28 Mar 2006, 12:34 |
|
shism2 29 Mar 2006, 02:40
Where is the fasmlib?
|
|||
29 Mar 2006, 02:40 |
|
RedGhost 29 Mar 2006, 04:15
_________________ redghost.ca |
|||
29 Mar 2006, 04:15 |
|
MazeGen 29 Mar 2006, 13:24
vid wrote:
If these should be always included, why these are not included by default using: Code: include "fasmlib/fasmlib.inc" In other words, is it good idea to include them always by hand? vid wrote:
Again, couldn't these be initialized by default, if they are included? |
|||
29 Mar 2006, 13:24 |
|
vid 29 Mar 2006, 14:28
Quote: In other words, is it good idea to include them always by hand? For clearness. I want that user of library always knows what is hapenning. That's also why i first explain how things work without macros. I don't want to end up with too complex, things. Understatnding these lines is in my opinion easier than understanding and remembering sentence in documentation. Quote: Again, couldn't these be initialized by default, if they are included? Same reason as before, plus FASMLIB doesn't execute any code itself, you must call it. There is no entry code, you again always know what is happening. Doing it yours way would save only very little coding time, these things are writen about once per project, and this approach can prevent big confusion and need to explore library internals. One of my main goals is to make library CLEAR, so it's user always knows what he doing. That's why we code assembly, no? |
|||
29 Mar 2006, 14:28 |
|
Reverend 30 Mar 2006, 21:57
I have nice idea about initalization. We will have one equate with list of modules. Every included module will add another string to the equate list. Then we will have this list defined somewhere as data. There would be only one initalization procedure which will just jump through the jump table. Check below the example:
Code: ; USER CODE include 'mem.inc' ; list equ mem.init ; count = 1 include 'str.inc' ; list equ mem.init, str.init ; count = 2 ... call fasmlib.init Code: ; FASMLIB CODE idata { fasmlib.jump_table dd list, 0 } fasmlib.init: mov eax, fasmlib.jump_table mov ecx, count @@: call dword [eax+ecx*4-4] loop @B stc retn |
|||
30 Mar 2006, 21:57 |
|
MazeGen 31 Mar 2006, 07:27
vid:
If you use "proc" or "local" macros in your code, do you exactly know the offsets of your local variables and what instructions are generated? You don't and you even don't bother about it, because it simply works. Only rough knowledge is needed. No hand coding of stack frame and local offsets. Same way, one don't want to bother with forced initialization at the entry and uninitialization at the exit. |
|||
31 Mar 2006, 07:27 |
|
vid 31 Mar 2006, 07:46
Reverend: you don't always want to initialize module at startup. your solution will be better in most cases, but will not work in all cases - it's not general. Imagine some modules which need to allocate lot of memory on initialization, and are needed only for some particular operation (like some packing or encryption algos that need to make big tables).
|
|||
31 Mar 2006, 07:46 |
|
Reverend 31 Mar 2006, 13:37
MazeGen: It will be like pushing ebx esi edi in the beginning of your code modifying them.
Code: push esi edi ebx ... ; your code ... pop ebx edi esi Code: call xxx.init ... ; your code ... call xxx.uninit vid: You're right. I thought only about programs which use all procs from the beginning to the very end, ie. initalization is at startup and uninitialization at the end. But it will not always be true. So my idea won't work then. |
|||
31 Mar 2006, 13:37 |
|
MazeGen 31 Mar 2006, 14:24
Reverend wrote: MazeGen: It will be like pushing ebx esi edi in the beginning of your code modifying them. Yes, the initialization would be done at the entry and the uninitialization would be done when you call "exit" function. Anyway, vid already told me private that he don't want to go this way. [edit] Eh, I got it now. You meant this un/initialization is as natural as it is in procedures. It is really about one's choice. [/edit] |
|||
31 Mar 2006, 14:24 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.