English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General > Coders. Tutorials

 
 
Thread Tools
Old 19 January 2007, 18:58   #21
musashi5150
move.w #$4489,$dff07e
 
musashi5150's Avatar
 
Join Date: Sep 2005
Location: Norfolk, UK
Age: 42
Posts: 2,351
Yup, I agree EQU is very useful in making your code both easier to read and manage. If any of you guys know any C/C++ you could say EQU is very much like #define in some respects.

Just as an example when loading a colour register it's much easier to read your code when you are doing something like:

Code:
COLOR        EQU    $dff180
 
 
             move.w d0,COLOR
than

Code:
             move.w d0,$dff180

It's best to bear this stuff in mind NOW so you don't start bad habits.
musashi5150 is offline  
Old 19 January 2007, 19:03   #22
BippyM
Global Moderator
 
BippyM's Avatar
 
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
Everything I've posted thus-far is discussed later in the book i'm reading. I'll naturally cover it when I get that far
BippyM is offline  
Old 19 January 2007, 19:49   #23
pbareges
Registered User
 
pbareges's Avatar
 
Join Date: Feb 2005
Location: montreal / canada
Age: 47
Posts: 722
Quote:
Originally Posted by musashi5150
EQU is used for contants that never change
DS.x is used to Define Storage (uninitialised) - you can change this when running
DC.x is used for Define Constant (initialised) - you can change this when running

Example:
Code:
        ds.b    4    ;Reserves 4 bytes storage (contains random trash data)
        dc.b    4    ;Reserves 1 byte storage and puts the value '4' into it
beefy   equ     4    ;Reserves NO storage, but you can use the word 'beefy' to mean 4 in your program code...
thanks for you clear explanation!! but you should agree thay dc.l 1 does not allocate 1 long variable only (as described in bippym code)..it allocates 1 long variable and puts the value 1 in it ...right? (infact the 1 value is confusing,,)
pbareges is offline  
Old 19 January 2007, 20:43   #24
BippyM
Global Moderator
 
BippyM's Avatar
 
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
ds.b 1 will allocate 1 byte in memory
ds.w 1 will allocate 2 bytes
ds.l 1 will allocate 4 bytes

The allocated memory will be empty and just the address associated with the name
BippyM is offline  
Old 19 January 2007, 21:39   #25
Joe Maroni
Moderator
 
Joe Maroni's Avatar
 
Join Date: Feb 2003
Location: Germany
Age: 44
Posts: 1,303
Send a message via MSN to Joe Maroni
in nearly every assembler command the amount of bytes is stored via:


xxx.b -> 1 byte
xxx.w -> 2 bytes
xxx.l -> 4 bytes


and there is a special "form" of "type" the nibble...

xxx.s -> 1/2 byte -> 4 bits

just to mention it...

and the dc.x "command" (it´s not really a command !!) is neccessary for PC relative coding !!!!
Joe Maroni is offline  
Old 20 January 2007, 00:37   #26
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Quote:
Originally Posted by x_to
and there is a special "form" of "type" the nibble...

xxx.s -> 1/2 byte -> 4 bits
Which assembler would allow that?

Quote:
Originally Posted by x_to
and the dc.x "command" (it´s not really a command !!) is neccessary for PC relative coding !!!!
Could you please explain what you mean here? I don't see why dc.x is necessary for pc relative coding. Because "necessary" means pc-relative coding would not be possible without dc.x which is of course plain wrong. So I guess you meant something like calculating jump distances for some jumptables (dc.w rout1-base, dc.w rout2-base etc) but I am not sure about that. So please explain what you mean here because I think it's a pretty confusing/wrong statement you made.
StingRay is offline  
Old 20 January 2007, 12:53   #27
BippyM
Global Moderator
 
BippyM's Avatar
 
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
This thread is going to get too complex too quickly.

I have not mention (pcP relative coding yet but it will be covered.

I'll also be covering other area's, just give it time and please you seasoned asm guys, if you mention something new explain it!
BippyM is offline  
Old 20 January 2007, 14:32   #28
BippyM
Global Moderator
 
BippyM's Avatar
 
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
Simple arithmetic

Code:
        add.<size> source,destination
Add simply adds the contents of the source to the contents in the destination

an example

Code:
        move.l    NUMBER1,d0        Copy contents of NUMBER1 into d0
        add.l    d0,NUMBER2        Add the contents of d0 to that already in NUMBER2
        rts
NUMBER1    dc.l    3            Set NUMBER1 to 3
NUMBER2    dc.l    4            set NUMBER2 to 4
WHat do you think the value in NUMBER2 will be?


That is pretty much all the book covers on arithmetic, though there will be more i'm sure
BippyM is offline  
Old 20 January 2007, 14:52   #29
BippyM
Global Moderator
 
BippyM's Avatar
 
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
Loops

The following new commands will be used here

Code:
lea source address, register
moveq source, destination
subq source,destination
beq address
bne address
bra address
LEA - load Effective Address allows the programmer to load an address into a specified register

Code:
lea NEW_WINDOW,a0
This will load the location in memory which has been labelled NEW_WINDOW into register a0

Loops

Loops have 4 identifiable sections
  1. Initialisation ; Setup and initialise the loop
  2. Processing ; The main body of the loop
  3. Control ; Decide whether further iterations af the loop are required
  4. Terminal ; Terminates the loop
There are two types of loop post-test and pre-test, the difference is where the exit from the loop is made. In the pre-test the check is made before the loop is executed and if it is satisfied the loop will never run. In the post-test the check is made at the end of the loop, so the main body of the loop is always executed at least once.

Code:
post-test loop

    moveq    #10,d0        put 10 into d0
LOOP    MAIN BODY        ; here is where the main body of the loop would be
    subq    #1,d0        ; Subtract 1 from d0
    bne    LOOP        ; if d0 doesn't equal 0 then loop
to write the exacty same loop in pre-test form the code would look something like

Code:
pre-test loop

	moveq	#10,d0		put 10 into d0
LOOP	beq	LOOP_END	if d0 equals 0 jump past loop

	MAIN BODY		; here is where the main body of the loop would be
	
	subq	#1,d0		; Subtract 1 from d0
	bra	LOOP		; branch back and loop

LOOP_END
More on loops later

Last edited by BippyM; 20 January 2007 at 15:45.
BippyM is offline  
Old 20 January 2007, 20:53   #30
pbareges
Registered User
 
pbareges's Avatar
 
Join Date: Feb 2005
Location: montreal / canada
Age: 47
Posts: 722
thanks bippy ...what would be the difference between moveq and move.l ?
pbareges is offline  
Old 21 January 2007, 01:18   #31
WayneK
Registered User
 
Join Date: May 2004
Location: Somewhere secret
Age: 50
Posts: 364
moveq is the "quick" version, only used for values +/- 128, but it takes less cpu cycles than the normal move...
WayneK is offline  
Old 23 January 2007, 12:26   #32
BippyM
Global Moderator
 
BippyM's Avatar
 
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
Some asm stuff i found on the net

Last edited by BippyM; 10 July 2013 at 23:00.
BippyM is offline  
Old 24 January 2007, 15:20   #33
BippyM
Global Moderator
 
BippyM's Avatar
 
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
String Conversion

One way to store characters in memory would be to store a count of the number of characters in the string.

Code:
TEXT    dc.b    5,"HELLO"
another method could use a NULL (0) terminating charcter

Code:
TEXT    dc.b    "HELLO",0
the 0 (zero) represents the end of the string. This method is better as longer strings don't need to be pre-calculated

We shall program a routine which will convert the pre-calculated method to the 0 terminating method.


We need to start by loading a register with the address of the first character which we can then copy into d0.

Code:
      lea    TEXT,a0    load a0 with start address of TEXT
      move.b (a0),d0    Copy character count into d0
We need to reserve memory space for the string and the terminating character. We know the string is 5 characters and we need a 6th for the terminating 0 so the following is going to be needed

Code:
COPY    ds.b    6    Reserve 6 bytes for the copy and terminating 0
next we put the astart address of COPY into a1 so we know where to start copying to

Code:
    lea    COPY,a1    Address of destination into a1
Now a0 is pointing to the 5 in the source string (which is the start of the string incidentally) and a1 is pointing to the start of the reserved space for the copy to go into.

We need to move the address of a0 to point to the first letter of the string so the following code needs to be included

Code:
    addq.l    #1,a0    ; increas address in a0 by 1
We now have the following basic framework

Code:
        lea        TEXT, a0        Put start address of TEXT into a0
        move.b     (a0), d0        Copy Char count to d0 (5)
        addq.l     #1, a0          Increase a0 address by 1
        lea        COPY, a1        Start address of dest into a1

        <Main Loop, Not Yet written>

        rts

TEXT        dc.b    5,"HELLO"
COPY        ds.b    6
The main loop itself can be written using indirect addressing to copy the string. the first line is saying "Copy the contents of the byte whose address is being pointed to by a0 to the address being pointed to by a1" then reduce the loop counter (d0) by 1

Code:
    move.b (a0),(a1)        copy contents of a0 to a1
    subq.b #1,d0            reduce count by 1
Obviously a0 and a1 need incrementing to point to the next memory location so

Code:
    addq.l    #1,a0        increase a0 by 1
and the same for a1

When d0 equals 0 (zero) then the loop is effectively over so a BNE (Branch Not Equal) loop can be used

our loop now looks like

Code:
LOOP    move.b    (a0),(a1)        Copy contents of a0 to a1
        addq.l    #1,a0            Increase address by 1
        addq.l    #1,a1            and again fore a1
        subq.b    #1,d0            decrease count by 1
        bne       LOOP             if d0<>0 loop
After all that we need to add the terminal 0 (NULL) so the following will do once the loop has exited

Code:
    move.b    #0,(a1)     add termination
Does someone (A newbie) want to write the complete routine?

(and before someone says yes I know there are quicker and better ways of doing this ((a0)+ etc), and that is next so please keep quiet!)
BippyM is offline  
Old 24 January 2007, 16:03   #34
BippyM
Global Moderator
 
BippyM's Avatar
 
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
is anyone finding this useful?
BippyM is offline  
Old 24 January 2007, 16:16   #35
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
I find it interesting to read, even though I know my 68k asm pretty well by now.
StingRay is offline  
Old 24 January 2007, 16:22   #36
BippyM
Global Moderator
 
BippyM's Avatar
 
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
Quote:
Originally Posted by StingRay
I find it interesting to read, even though I know my 68k asm pretty well by now.
Cool, it's pretty simple stuff really, esp to the experts
BippyM is offline  
Old 24 January 2007, 16:24   #37
killergorilla
Lesser Talent
 
killergorilla's Avatar
 
Join Date: Jan 2003
Location: UK
Age: 42
Posts: 7,957
I'm reading every post, makes interesting reading

@Bip: can't remember what I wanted on IRC...
killergorilla is offline  
Old 24 January 2007, 16:58   #38
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Quote:
Originally Posted by bippym
Cool, it's pretty simple stuff really, esp to the experts
Yeah, that's what makes it somehow interesting since it reminds me of the time 17 years ago when I learned 68k asm. When I saw the stringcopy loop the first I wanted to post is how to make it better but then I saw your post and kept quiet. Somehow funny.
StingRay is offline  
Old 24 January 2007, 17:39   #39
pbareges
Registered User
 
pbareges's Avatar
 
Join Date: Feb 2005
Location: montreal / canada
Age: 47
Posts: 722
keep up with your great project! amazing
pbareges is offline  
Old 25 January 2007, 01:49   #40
superBuster
superFreak
 
superBuster's Avatar
 
Join Date: Dec 2006
Location: planet earth
Age: 51
Posts: 157
Send a message via AIM to superBuster
god dang... now I'm gonna have to learn asm..... bastards....
superBuster is offline  
 


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 23:32.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.12563 seconds with 14 queries