16 July 2017, 13:40 | #41 | |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
Quote:
Here are the sizes of the executable and it's object file: Code:
With UWordRep: .o: 816 .exe: 780 Without UWordRep: .o: 788 .exe: 768 I'm unsure on how to proceed, as I don't really know how to 'join several objects'. Only thing I can think of, is putting both UByteRep and UWordRep into their separate files, compiling them and then linking them into stringUtil.lib. Or do I need an actual join command? On a side note: when I compile stringUtil.lib, vasm says 'CODE(acrx2): 152 bytes'. It then generates a file of 280 bytes. Almost everything in that file is code (I think), so how does that compute? Yep, it's asking-stupid-questions-time again, people, so gather 'round.. |
|
16 July 2017, 13:52 | #42 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
Source code is missing. But I bet you have UWordRep and UByteRep in the same file producing a single .o. Split them in two files. Make two .o files. Try (cause you don't have a compiler set, I guess) join uwordrep.o ubyterep.o to foo.lib and link against foo.lib and redo your exe size checks.
|
16 July 2017, 13:55 | #43 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
or try adding -gc-all -gc-empty to vlink's parameters.
|
16 July 2017, 14:02 | #44 | |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
Quote:
And yes, both functions are in the same file ATM. I will definitely try your suggestions, in reverse orde.. Thanks! |
|
16 July 2017, 14:34 | #45 |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
|
16 July 2017, 15:10 | #46 |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
Ok, I've separated the subroutines into their own file. Here's how I create the lib:
Code:
vasm stringUtilUByteRep.asm -o stringUtilUByteRep.o -Fhunk vasm stringUtilUWordRep.asm -o stringUtilUWordRep.o -Fhunk vlink -o stringUtil.lib stringUtilUByteRep.o stringUtilUWordRep.o -bamigahunk -gc-all -gc-empty Unfortunately, when I try to link it to my exe, it gives this warning and error: Code:
execString: vlink -o PrintDecimal2.exe PrintDecimal2.o -L "E:\Amiga\Dev\NDK_3.9\Include\linker_libs" -L "E:\Amiga\Dev\asm\my_linker_objs" -l amiga -l stringUtil -bamigahunk -gc-all -gc-empty Warning 12: "\Amiga\Dev\asm\my_linker_objs\stringUtil.lib" is already an executable file. Fatal error 16: E:\Amiga\Dev\asm\my_linker_objs\stringUtil.lib: Section appeared twice in \Amiga\Dev\asm\my_linker_objs\stringUtil.lib. Aborting. @ alkis: yeah, I forgot to include my lib source, earlier, silly me. Hopefully I've included everything this time.. |
16 July 2017, 15:33 | #47 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
You are on Windows, right?
Open a cmd and go to the folder holding the *.o and try copy /b UByteRep.o+UWordRep.o foo.lib And now link with foo.lib |
16 July 2017, 15:55 | #48 |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
YES!
That a) works and b) seems to have the desired effect! Thanks a lot for your time and patience, alkis, you've been a great help! Current lib size: 364 bytes UByteRep.o: 160 UByteRep.o: 204 Exe's: Code:
With UWordRep: .o: 816 .exe: 784 Without UWordRep: .o: 788 .exe: 656 |
16 July 2017, 18:44 | #49 | |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Quote:
Fortunately alkis knew a Windows equiavalent for join(AmigaOS) or cat(Unix). I cannot help you very much with Windows details. BTW, the -M (map file) option of vlink may show you a lot of interesting information about the linking process. So you can more easily decide what happened. |
|
16 July 2017, 18:56 | #50 |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
Summary: so far, so good!
Alright, time to take a step back and see what we've learned. I've attached the latest version of my code.
It no longer links to amiga.lib, which I'm very happy about, because people kept shouting at me that I really shouldn't be doing that -- and they were/are right. It's including LVOs.i now, which is way more practical and efficient than I thought. For one, it does not incur the 32 kb (ok, to binary) penalty I assumed it would, as it only includes the things that are needed ('dormant code', I believe it's called). It's now using gmake to build, rather than running some long winded python script. You can also use the make.exe which comes included with vbcc, which I had installed just to use vasm & vlink, but which I didn't realise came with a make.exe included. So @phx: I'm even more sorry to have wasted your time there.. It could still use some work, of course. It still uses macros for the printing code; I'd like that to become a lib, too. It's still not decently documented (*) nor optimised. And the makefiles could probably also be cleaner and more complete (eg, a make clean would be nice). Anyway, I'm very happy with the progress I've made over the last couple of days. Thank you again to all who have contributed to this! (*) I'll look into this autodoc thing. Question, though: can I write this lib (in asm) so that it can be used from C code as well? Or does that mainly happen from the C side? |
16 July 2017, 19:33 | #51 | ||
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
Quote:
Code:
asm = vasm asmopt = -Fhunk -esc lnk = vlink lnkopt = -r -bamigahunk -gc-all -gc-empty lnkin = stringUtilUByteRep.o stringUtilUWordRep.o lnkout = -o stringUtil.lib all: stringUtilUByteRep.asm stringUtilUWordRep.asm Makefile $(asm) $(asmopt) -o stringUtilUByteRep.o stringUtilUByteRep.asm $(asm) $(asmopt) -o stringUtilUWordRep.o stringUtilUWordRep.asm $(lnk) $(lnkopt) $(lnkin) $(lnkout) Quote:
Thank you, I'll look into that! |
||
16 July 2017, 19:43 | #52 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
Nice. Well done.
Add this at the bottom of your Makefile for clean Code:
clean: del *.o PrintDecimal.exe There three things you need to do to get your lib's functions callable from C. 1) prepend functions names with _ (i.e. _UByteRep) See C compilers prepend symbols automatically with '_', and if you called UByteRep compiler will change it to _UByteRep and then the linker will not find the symbol. 2) get parameters from stack (there is a workarround for that, but lets keep it simple). so every function in your lib should load values from stack. 3) save registers that you use, except a0/a1/d0/d1 (which might give you a hint why choosing say a0 to hold the buffer might be better ;-) ) so say this Code:
UByteRep: divu #10,d0 swap d0 clr.l d1 move.b d0,d1 add.b #48,d1 move.b d1,2(a5) Code:
XDEF _UByteRep ; arg in d0 (unsigned byte) (is modified) ; result in (a5) ; -- can probably be optimised.. _UByteRep: move.l 4(sp),d0 move.l 8(sp),a0 divu #10,d0 swap d0 clr.l d1 move.b d0,d1 add.b #48,d1 move.b d1,2(a0) Also, realistically speaking, the call to LVOWrite isn't something that you want to put in a lib. Even macro is kind of stretching it. In real world senarios, you make the call in your source code. But macro I guess could be ok. Not in a lib. Lastly, some conventions for the Makefile. AS is what is generally used to hold the assembler. ASFLAGS for asm options LD for the linker LDFLAGS for the linker options all: is used when you have defined multiple targets and you pull them all together in all in your case instead of all should be "PrintDecimal.exe:" (without the quotes) |
16 July 2017, 19:54 | #53 | |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
|
Quote:
Code:
jsr _LVOAllocate(a6) Code:
jsr -186(a6) |
|
16 July 2017, 20:16 | #54 | |||
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
Quote:
Quote:
Quote:
|
|||
16 July 2017, 20:19 | #55 |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
|
16 July 2017, 20:32 | #56 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
Cause there is no point. _LVOWrite needs to load 3 register and call the OS. What exactly would you gain from a subroutine? You can't gain anything. Only lose.
|
16 July 2017, 20:39 | #57 |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
I'd hoped to gain the ease of use. What do I lose when doing it from a lib? Doesn't that go through the same 3 registers and OS call?
|
16 July 2017, 22:18 | #58 | |
Banned
Join Date: Jan 2010
Location: Kansas
Posts: 1,284
|
Quote:
Code:
INCLUDE "exec/macros.i" ... JSRLIB OpenLibrary Code:
INCLUDE "LVOs.i" ... jsr (_LVOOpenLibrary,a6) You would be calling a function in the lib which calls an OS library function when just calling the OS library function would suffice. A function is called with a bsr or jsr and end with a rts. The bsr and jsr write a return address to the stack and jump to a different PC (Program Counter) location in memory where program execution continues. The rts removes the return address from the stack and jumps to it. Then there is the issue of passing arguments which may need to be moved or placed on the stack to comply with standards/conventions. Using a function is fairly slow, especially on these old processors. The C language will inline functions for you (fold small functions into other functions removing the bsr/jsr and rts) but assembler is all manual control. It is faster to write longer functions or inline code usually with macros (too much macro use can be difficult to read though). Reusing functions, including short functions, allows for smaller code and better use of caches though. Smaller code and more efficient cache use is faster also so best performance is finding a good balance between reusing code and inlining code. Efficient hardware should make function calling as cheap as possible but the 68k was a little before CPUs made function calling as efficient as possible so best performance is going to be more inlining and fewer function calls. Last edited by matthey; 17 July 2017 at 12:51. |
|
17 July 2017, 01:26 | #59 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
|
17 July 2017, 09:21 | #60 |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
AmiDevCpp and Floats | AmigaEd | Coders. General | 0 | 18 January 2006 03:16 |
|
|