hb@pbhya.PacBell.COM (Henry Bitter) (04/20/88)
I am trying to get started doing some assembler programming and need some help. I need to know how you get the command line information using assembler. In particular, the program I'm writing needs the name of a file which will be opened and closed. Is there a ARGV[n] type arguement in assembler ? If so, how does it work ? Thanks for your help; Henry Bitter * Pacific Bell * (415) 823-2836 San Ramon, Calif. { }!pacbell!pbhya!hb If I had a disclaimer I wouldn't give it away !
steveb@cbmvax.UUCP (Steve Beats) (04/21/88)
In article <12542@pbhya.PacBell.COM> hb@pbhya.PacBell.COM (Henry Bitter) writes: > >I am trying to get started doing some assembler programming and need some >help. I need to know how you get the command line information using >assembler. In particular, the program I'm writing needs the name of a file >which will be opened and closed. Is there a ARGV[n] type arguement in >assembler ? If so, how does it work ? > When you start up an assembler program (that has not been linked with any special startup code) it is entered with a0 pointing to the command line arguments and d0 containing the number of characters in the command. Note, the name of the program is NOT included in the command line you are passed, only the arguments. D0 is the number of characters including the terminating newline character ($0a). The command line is not a null terminated string and you'll have to parse it yourself to break up the separate arguments. If you need to access the name of the program (equivalent to argv[0] in 'C') you will have to open DOS library, find your task with FindTask(0) and fish the pointer to the command name out of the CLI struct in your process header. It would go something like this in assembler (assuming the task pointer is already in a0). movea.l pr_CLI(a0),a0 adda.l a0,a0 BPTR to CLI struct adda.l a0,a0 movea.l cli_CommandName(a0),a0 adda.l a0,a0 BPTR to command name adda.l a0,a0 a0 now points to a BCPL string containing the name of the program. This is a string where the first byte (n) contains the length of the string followed by n characters. Hope this helps. VERY IMPORTANT: The above will only work for a program started from CLI (which can be tested for quite easily because pr_CLI is zero if the program was started from WorkBench). You need a completely different startup for WorkBench launched programs. Steve
mills-c@pike.cis.ohio-state.edu (Christopher Mills) (04/21/88)
In article <3664@cbmvax.UUCP> steveb@cbmvax.UUCP (Steve Beats) writes: >In article <12542@pbhya.PacBell.COM> hb@pbhya.PacBell.COM (Henry Bitter) writes: >>... I need to know how you get the command line information using >>assembler.... > > >If you need to access the name of the program (equivalent to argv[0] in 'C') >you will have to open DOS library, find your task with FindTask(0) and fish >the pointer to the command name out of the CLI struct in your process header. Or you could just link in c.o or astartup.obj and name the entry point to your program __main. Then it does all the workbench/CLI startup for you. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- _____________________ | Christopher Mills. (_)________________ \ | mills@baloo.eng.ohio-state.edu ________________|\ \ | mills-c@pike.cis.ohio-state.edu (_)______________\_\ \ | Current Thought: I really should be ______________________\ | doing my thesis now... (_)____________________| | DISCLAMER: I really wish I could blame | my thoughts on someone else... -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bruce_Eric_Bowers@cup.portal.com (07/05/89)
For the first time, I'm writing an entire program in assembly language. I've written a number of assembler subroutines before, but this is the first time I've written all the startup and interface code in assembler. I'm having a small problem cleaning up. What am I doing wrong? I'm including below a small assembly program which simply opens, then closes, the intuition library the same way I do it in my program. This small program exhibits the same problem as my program: it gurus when closing the intuition library. Note that the library is opened successfully, as I can open and play with windows. I've stepped through this code with the MetaScope debugger. What happens is that the code executes as it should, and calls CloseLibrary. However, the call to CloseLibrary does NOT return to the next instruction; it sometimes returns several words back up into the program, and sometimes returns to an address which is not even in my load module. Either of these events causes a Guru. I realize I could bypass this whole problem by simply not closing the library, but I'd prefer to find out why the close is acting so oddly. What mistake am I making? I may be blind to my own mistakes, but I think the code should work as written. Any chance an old Amiga.lib could cause this kind of problem? My CloseLibrary is resolving to -$19E(A6). By the way, this is executing under 1.3, on a 2500, if that makes any difference. Any help or advice would be appreciated! --------------------------------------------------------------------------- * External References XREF _AbsExecBase XREF _LVOOpenLibrary XREF _LVOCloseLibrary * Processing Begins Test MOVE.L A6,-(SP) ;Store A6 On The Stack * Open the Intuition Library MOVEA.L _AbsExecBase,A6 ;Load A6 With Address Of LVO Table LEA IntuitLibName(PC),A1 ;Set A1 To Point To Library Name CLR.L D0 ;Set Library Version to "Any" JSR _LVOOpenLibrary(A6) ;Open The Intuition Library MOVEA.L D0,A6 ;Move Library Address to A6 BEQ Exit ;If Addr Was 0, OpenLibrary Failed * Close The Intuition Library MOVEA.L _AbsExecBase,A6 ;Load A6 With Address Of LVO Table LEA IntuitLibName(PC),A1 ;Set A1 To Point To Library Name JSR _LVOCloseLibrary(A6) ;Close The Intuition Library * Restore Registers And Exit Exit MOVE.L (SP)+,A6 ;Restore A6 From Stack RTS IntuitLibName DC.B 'intuition.library' DC.B 0 END --------------------------------------------------------------------------- Thanks! Bruce Bowers
brett@umd5.umd.edu (Brett Bourbin) (07/05/89)
In article <20123@cup.portal.com> Bruce_Eric_Bowers@cup.portal.com writes: >... it gurus when closing the intuition library. >* Open the Intuition Library > MOVEA.L _AbsExecBase,A6 ;Load A6 With Address Of LVO Table > LEA IntuitLibName(PC),A1 ;Set A1 To Point To Library Name > CLR.L D0 ;Set Library Version to "Any" > JSR _LVOOpenLibrary(A6) ;Open The Intuition Library > MOVEA.L D0,A6 ;Move Library Address to A6 First, I don't know if you are aware, but moving a value into a address register _DOESN'T_ set the condition codes. I think you are safe right now, with the current OS, since I seem to remember that the status is loaded into D0 right before returning. To be safe and nice to people, put a TST.L D0 or some move to a data register before the BEQ Exit. > BEQ Exit ;If Addr Was 0, OpenLibrary Failed >* Close The Intuition Library > MOVEA.L _AbsExecBase,A6 ;Load A6 With Address Of LVO Table > LEA IntuitLibName(PC),A1 ;Set A1 To Point To Library Name ACK! or should I say NAK! 8^) When you close a library, you load _AbsExecBase into register A6 like you did, but you pass it the library base that you received when opening the library. (What was passed in D0.) You are trying to close a library thats base address is IntuitLibName, a nono. > JSR _LVOCloseLibrary(A6) ;Close The Intuition Library >IntuitLibName DC.B 'intuition.library' > DC.B 0 Fix that and I think you will be alright. Good luck. >Thanks! Bruce Bowers -- --Brett S Bourbin, Instructional Computing Programs -- Univ of Maryland Computer Science Center, College Park, MD 20742 INTERNET: brett@umd5.umd.edu BIX: brettb DELPHI: brettb
rickf@pnet02.cts.com (Rick Flower) (07/06/89)
Bruce_Eric_Bowers@cup.portal.com writes: >For the first time, I'm writing an entire program in assembly language. I've >written a number of assembler subroutines before, but this is the first >time I've written all the startup and interface code in assembler. I'm >having a small problem cleaning up. What am I doing wrong? > >I'm including below a small assembly program which simply opens, then closes, >the intuition library the same way I do it in my program. This small program >exhibits the same problem as my program: it gurus when closing the intuition >library... <Chunk-O-Message Removed> > >--------------------------------------------------------------------------- >* External References > > XREF _AbsExecBase > XREF _LVOOpenLibrary > XREF _LVOCloseLibrary > >* Processing Begins > >Test MOVE.L A6,-(SP) ;Store A6 On The Stack > >* Open the Intuition Library > > MOVEA.L _AbsExecBase,A6 ;Load A6 With Address Of LVO Table > LEA IntuitLibName(PC),A1 ;Set A1 To Point To Library Name > CLR.L D0 ;Set Library Version to "Any" > JSR _LVOOpenLibrary(A6) ;Open The Intuition Library > MOVEA.L D0,A6 ;Move Library Address to A6 > BEQ Exit ;If Addr Was 0, OpenLibrary Failed > >* Close The Intuition Library > > MOVEA.L _AbsExecBase,A6 ;Load A6 With Address Of LVO Table > LEA IntuitLibName(PC),A1 ;Set A1 To Point To Library Name > JSR _LVOCloseLibrary(A6) ;Close The Intuition Library > Well, it looks like the above code that you've got to close your Intuition library is the suspect! In order to close a library, you need to pass a pointer to the CloseLibrary function that was originally given to you by the OpenLibrary function, NOT a library name.. >* Restore Registers And Exit > >Exit MOVE.L (SP)+,A6 ;Restore A6 From Stack > RTS > >IntuitLibName DC.B 'intuition.library' > DC.B 0 > > END >--------------------------------------------------------------------------- >Thanks! Bruce Bowers No Problem! +-----------------------------------------------------------------------------+ | Caution, Assembly Language Programmer at Play! | | | | UUCP: {ames!elroy, <backbone>}!gryphon!pnet02!rickf | | INET: rickf@pnet02.cts.com | +=============================================================================+
nop@cup.portal.com (Randy G Jouett) (07/06/89)
It is also important to note that moving data address register direct will not set the condition codes of that status register. That is: lea DosName(pc),a1 moveq #33,d0 ;The next instruction will not set the condition codes. move.l _AbsExecBase,a6 jsr _LVOOpenLibrary(a6) ;the following line won't set them either. move.l d0,a0 beq NoDos ;wud never be taken if d0 is NULL. Here is how the code should look: lea DosName(pc),a1 moveq #33,d0 move.l _AbsExecBase,a6 jsr _LVOOpenLibrary(a6) move.l d0,DBase(a4) ;base relative addressing via geta4(), ;_LinkerDB, etc. beq NoDos ;no dos around these parts. move.l d0,An ;if you want to put DosBase in an ;address register. Hope all this helps..................... -- Randy Jouett sun!portal!cup.portal.com!nop or nop@cup.portal.com