Path: utzoo!attcan!uunet!cs.utexas.edu!wuarchive!mit-eddie!bloom-beacon!eru!hagbard!sunic!news.funet.fi!funic!santra!santra!robin From: robin@niksula.hut.fi (Jarto 'Robin' Tarpio) Newsgroups: comp.sys.amiga.tech Subject: Re: Assembly question from turnip Message-ID: Date: 27 Oct 90 17:11:06 GMT References: <2728cc8d-a00comp.sys.amiga.tech@tronsbox.xei.com> <15433@cbmvax.commodore.com> Sender: news@santra.uucp (Cnews - USENET news system) Organization: Helsinki University of Technology, Finland Lines: 75 In-Reply-To: valentin@cbmvax.commodore.com's message of 27 Oct 90 05:56:03 GMT In article <15433@cbmvax.commodore.com> valentin@cbmvax.commodore.com (Valentin Pepelea) writes: In article <2728cc8d-a00comp.sys.amiga.tech@tronsbox.xei.com> dfrancis@tronsbox.xei.com (Dennis Francis Heffernan) writes: > > Well, I've hit a good one. I've finally gotten around to trying to l >learn assembly on this beast, and my first program crashes. > >getvarmem move #4,a6 ;get memory for variables > move.b #60,D0 > move.l #0,D1 > jsr _LVOAllocMem(A6) > bne 1$ > jmp giveup ;didn't get 60 bytes? SHEESH! >1$ move.l D0,vars ;stash the address for variables V: The first problem is with the first instruction. What is the data width of V: that instruction? What data width does your assembler default to? Replace V: that instruction with "move.l #4,a6". The correct one is: move.l 4,a6 Or shorter: move.l 4.w,a6 That #4 moves the value 4 into A6. You have to move the address which is in 4 to A6. V: The second problem is with the test for the return value. Hey, wait a minute, V: you are not testing for the return value at all! Here is what you should do: V: V: jsr _LVOAllocMem(a6) ; Try to allocate memory V: tst.l d0 ; Is the return value zero? V: beq giveup ; Branch if so V: move.l d0,vars ; Stash the address More comments: >getvarmem move #4,a6 ;get memory for variables move.l 4.w,A6 > move.b #60,D0 moveq.l #60,D0 This one cleans the whole registed. If D0 contains "something big" before your move.b, you only change the lowest byte and D0 will contain a big number and you ask for a huge amount of memory. > move.l #0,D1 moveq.l #0,D0 Those "quick" moves produce smaller code and are faster. > jsr _LVOAllocMem(A6) tst.l D0 Just like Valentin wrote... > bne 1$ bne.s 1$ Optimization... > jmp giveup ;didn't get 60 bytes? SHEESH! >1$ move.l D0,vars ;stash the address for variables * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * StarSoft Ky (ECO101) Helsinki University of Technology * * Jarto Tarpio Member of Amiga Developers' Support Program, Europe (ADSPE) * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // robin@niksula.hut.fi robin@otax.tky.hut.fi * * // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \\ // * * \\// Snif. @batcomputer.hut.fi is dead ! @joker.hut.fi won.. :-( * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *