26 January 2007, 10:01 | #41 |
Global Moderator
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
|
Right seeing as nobody fancied it here is the full code to the previous routine.
Code:
lea TEXT,a0 Address of TEXT into a0 move.b (a0),d0 Copy count into d0 (5) addq.l #1,a0 Increase a0 to point to first char of word lea COPY,a1 address of COPY buffer into a1 LOOP move.b (a0),(a1) Copy contents of address pointed by a0 to address pointed by a1 addq.l #1,a0 Increase address in a0 by 1 addq.l #1,a1 and same for a1 subq.b #1,d0 Decrease loop count by 1 bne LOOP if d0 is unequal to 0 loop move.b #0,(a1) add terminating NULL rts End program TEXT dc.b 5,"HELLO" COPY ds.b 6 With Post Increment the code is copied and then the source address is automatically increased by 1 for byte, 2 for word and 4 for long-word. To achieve this a + is added directly after the address register (a0)+, so the following code Code:
move.b (a0), d0 addq #1,a0 Code:
move.b (a0)+,d0 Auto Decrement works by first decreasing the address and then copying the data. Example: Code:
move.b -(a0),d0 Code:
lea TEXT,a0 Address of TEXT into a0 move.b (a0)+,d0 Copy count into d0 (5) and increase address in a0 lea COPY,a1 address of COPY buffer into a1 LOOP move.b (a0)+,(a1)+ Copy contents of address pointed by a0 to address pointed by a1 and increase both by 1 subq.b #1,d0 Decrease loop count by 1 bne LOOP if d0 is unequal to 0 loop move.b #0,(a1) add terminating NULL rts End program TEXT dc.b 5,"HELLO" COPY ds.b 6 Last edited by BippyM; 26 January 2007 at 10:10. |
28 January 2007, 11:29 | #42 |
Global Moderator
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
|
DBcc loops
To improve our program further we can use a DBcc loop (Test Condition - Decrement and Branch) the cc represents the test and loop type.
The DBcc instructions tests both the status flags and the data registers. There are differences between loops written using dbcc loops and those using conventional loops (bcc (bra, beq, bne etc)). If the condition being tested is satisfied then control passes to the instructions following the dbcc. If it is not satisfied then the low word of the data register is reduced by 1 and the loop is taken. The loop is continued until the result in the data register equals -1. Code:
LOOP move.b (a0)+,(a1)+ Copy characters dbra d0,LOOP deduct 1 off d0 and loop until d0 equals-1 Now because dbcc tests until the result equals -1 we need to reduce the count in d0 by 1 otherwise it'll do 1 too many loops. A subq.b #1,d0 is all that is needed Code:
lea TEXT, a0 address into a0 move.b move.b (a0+), d0 Copy counter into d0 and increase a0 sub.b #1, d0 Decrease d0 by 1 for the dbra loop lea COPY, a1 address of dest into a1 LOOP move.b (a0)+, (a1)+ Copy and increment dbra d0, LOOP Test is d0 =-1 and if not decrease and loop move.b #0, (a1) Add terminating 0 rts TEXT dc.b 5, "HELLO" COPY ds.b 6 |
28 January 2007, 13:15 | #43 |
Registered User
Join Date: Mar 2006
Location: Germany
Posts: 899
|
Maybe d0 should be cleared first, as DBcc operates on word size and if there's something in d0 it may not work as wanted (actually happens when using ASMOne's debugger the second time with this code, because $FFFF is still in d0).
|
28 January 2007, 13:33 | #44 |
Global Moderator
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
|
Hmm it doesn't discuss that in the asm book i'm reading so either
clr.l d0 or move.l #0,d0 |
28 January 2007, 13:34 | #45 |
Registered User
Join Date: Mar 2006
Location: Germany
Posts: 899
|
better moveq #0,d0
|
28 January 2007, 13:40 | #46 |
Global Moderator
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
|
Cool
The next chapter in the book discusses program design and the use of Warnier Diagrams I'm not going to implicitly discuss program design here, I am however going to make a new thread about it so it can be discussed more openely and others can give advice on what they do etc. If anyone wants me to go through program design the book refers to then I will. |
28 January 2007, 19:24 | #47 |
Global Moderator
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
|
From now on we will be doing some amiga specific stuff and starting to delve into amiga libraries etc. As before i'll be taking notes and for the first few posts it is going to be amiga related, starting with some hardware basics. I have not actually started these chapters yet, but i will tonight so expect a post covering this stuff over the next few days.
Has anyone learnt anything yet and are there any questions before I move on? |
28 January 2007, 21:07 | #48 | |
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
|
Quote:
|
|
28 January 2007, 21:08 | #49 | |
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
|
Oh, regarding dbf loops, on 060 it's faster to use the subq/bne combination.
Quote:
|
|
28 January 2007, 22:57 | #50 |
Registered User
Join Date: Jun 2005
Location: US / A
Age: 49
Posts: 134
|
ASM again and again.
Interesting thread bippy. Keep it up please!
|
29 January 2007, 01:04 | #51 |
Going nowhere
Join Date: Oct 2001
Location: United Kingdom
Age: 50
Posts: 8,989
|
Also regarding Dbra routines, they are limited in the size of data for copying, only useful for small copying routines, for something like a screen, you would use a subq.l # in conjunction with a bne.s
|
09 February 2007, 17:35 | #52 |
Global Moderator
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
|
Been busy doing some action replay and hacking about in code, but here is the next part of this
It's not complete yet so this post will be updated when it is I also said we'd be covering amiga specific stuff but I seemed tro have missed a chapter ----- Subroutines & Parameter Addressing There are two methods for transferring program control to a subroutine. There is the Jump to SubRoutine command (JSR), this causes an unconditional jump to a specified memory address. This instruction behaves just like the JMP command only the return address is placed on the stack, so the proggram can return from the subroutine. When the RTS is executed the return address is placed back on the PC and the program continues from the command after the calling routine. Stack The 68k family of processors allow the stack to be placed anywhere in memory. Register a7 is used to hold the address of the top of the stack. Before control is passed to a sub-routine the processor calculates the address of the next command and places the address on the stack. 680x0 stacks then grow downwards in memory, and since the SP always points to the last item added to the stack this means, this means before adding a new item you must first decrease the stack pointer by a number equivilent to the byte-size of the object being stored. This way it properly points to the location to be used next. There are two ways to pass data between subroutines. There is register based parameter passing, this method is both quick and simple, since pointers to larger objects, such as strings and other blocks of data can be passed. The routine is passed the address of the object as opposed to the object itself. Memory based parameter addressing is slower but does offer more flexibility. Register Preservation Normally it is advised to create subroutines that do not alter the contents of any temporary registers that they may use, i.e those that will not be used to return a result. The best way of preserving these registers is to push their contents onto the stack, and restore them just before the subroutine returns. One way to do this is as follows Code:
move.l a6, -(sp) preserve a6 move.l a5, -(sp) preserve a5 <do something> move.l (sp)+, a5 restore a5 move.l (sp)+, a6 restore a6 Movem exists in two forms. The instruction used when moving multiple registers to memory is called move-multiple-registers-to-memory (movem) it can use all absolute and indirect addressing modes except auto-increment modes. This is deliberate because it stops the programmer putting data on the stack, which would cause the stack to grow upwards in memory. Internally the command is built in the following way: The first word contains bit patterns which identify the instruction, the transfer size and the effective destination specification. The second word is a 16bit mask which has been assigned registers in the follwoing fashion Code:
a7 a6 a5 a4 a3 a2 a1 a0 d7 d6 d5 d4 d3 d2 d1 d0 Code:
d0 d1 d2 d3 d4 d5 d6 d7 a0 a1 a2 a3 a4 a5 a6 a7 The equivilent move-multiple-registers-from-memory movem instruction does not use this mask reversal. In fact it always uses the bit mask arrangement described first: a7 to a0 & d7 to d0 and instead allows the auto-increment addressing mode but does not allow auto-decrement. more to come.. keep posted Last edited by BippyM; 09 February 2007 at 17:54. |
13 February 2009, 17:30 | #53 |
... aka Amix73
Join Date: Jan 2009
Location: Austria
Posts: 87
|
Two years have gone by ... I am sure you are an expert by now. Really enjoyed reading it any chance that it will be continued?
|
13 February 2009, 17:56 | #54 |
Global Moderator
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
|
yeah expert if I continued regularly.. I always get distracted and go away from it, then come back again..
Right now I am far too busy to do anything, so it's gonna be a short while |
13 February 2009, 18:47 | #55 |
Moderator
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,604
|
I might translate my asm school from "Svenska Hemdator Hacking" magazine if someone can point me to scans, has scans of it come out of that AMR thread? Clue me in.
|
15 February 2009, 01:58 | #56 |
A1200 040 SAM440EP 667
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
|
|
17 February 2009, 00:38 | #57 |
... aka Amix73
Join Date: Jan 2009
Location: Austria
Posts: 87
|
|
12 April 2009, 09:03 | #58 |
Precious & fragile things
Join Date: Feb 2009
Location: Victoria, Australia
Posts: 1,946
|
Greetings,
I find it both useful and terribly processor specific. Coding for PIC is good, you can define labels for loop points within Microchip's coder, Code:
start2 org 0005 clrf temp0 clrf temp1 clrf temp2 clrf temp3 clrf temp4 clrf temp5 clrf temp6 clrf temp7 clrf temp8 clrf temp9 clrf intcon ;clears intcon register movlw b'00000001' movwf temp7 ;sets temp7 as high bit check movlw b'00000101' ;sets timer 1, no prescale movwf t1con clrw Code:
LDA $08 LDX $08 SBC BNE $03 JMP $FFD2 LDA $40 You can use; LDA $08 LDX $08 SBC BNE JUMP: JUMP: JMP $FFD2 LDA $40 |
06 June 2010, 19:03 | #59 |
A1200 040 SAM440EP 667
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
|
[quote=bippym;296073]Right seeing as nobody fancied it here is the full code to the previous routine.
Code:
lea TEXT,a0 Address of TEXT into a0 move.b (a0),d0 Copy count into d0 (5) addq.l #1,a0 Increase a0 to point to first char of word lea COPY,a1 address of COPY buffer into a1 LOOP move.b (a0),(a1) Copy contents of address pointed by a0 to address pointed by a1 addq.l #1,a0 Increase address in a0 by 1 addq.l #1,a1 and same for a1 subq.b #1,d0 Decrease loop count by 1 bne LOOP if d0 is unequal to 0 loop move.b #0,(a1) add terminating NULL rts End program TEXT dc.b 5,"HELLO" COPY ds.b 6 Tried to assemble this code with devpac and all goes well but when run the code it crash the machine I had to past the last lines: 'TEXT dc.b 5,"HELLO" ' and 'COPY ds.b 6' to first lines in code so devpac can assemble. In debuger the first line appear as: 'TEXT movep.l $454C(a0),d2' and the 2nd line: 'divul.l ??,d0:d0' and in mode: "run a line at once" the debuger didn´t pass the 2nd line. Someone knows why it happens? |
06 June 2010, 20:38 | #60 |
gone
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
|
What version of Devpac are you using AlfaRomeo...?
I put this code into Devpac V3.18 and it assembled and ran with no problems. By the way, code would be shorter like this: Code:
lea TEXT(pc),a0 move.b (a0)+,d0 subq.b #1,d0 lea COPY(pc),a1 loop move.b (a0)+,(a1)+ dbf d0,loop move.b #0,(a1) rts TEXT dc.b 5,"HELLO" COPY ds.b 6 Last edited by pmc; 06 June 2010 at 20:50. Reason: Only just noticed... |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Downfall - diary of a game... | Graham Humphrey | Amiga scene | 505 | 15 March 2015 19:26 |
Uridium 2 : Diary of a Game | silkworm | Amiga scene | 15 | 09 August 2011 09:00 |
19 Part One - Boot Camp | Retro-Nerd | project.aGTW | 2 | 19 February 2008 22:11 |
Help....what is this part 2? | Dizzy | Retrogaming General Discussion | 7 | 05 June 2007 15:27 |
|
|