Amiga.org

Operating System Specific Discussions => Amiga OS => Amiga OS -- Development => Topic started by: Jose on January 13, 2003, 03:09:46 PM

Title: Assembler (68k) help (about dc pseudo op)
Post by: Jose on January 13, 2003, 03:09:46 PM
I got tired and started reading an assembler tutorial I found on Aminet here (http://ftp.plig.org/pub/aminet/dev/asm/AmigaAsm.lha). You know, that's where the fun really begins! :-D  I regret not having done that sooner.
I URGE EVERYONE IN HERE TO START PROGRAMMING :-D

Anyway, either I'm too dumb, or the tutorial is not that well written cause I'm not understanding the dc pseudo operation.
The tutorial is old and assumes that you're using AssemPro.

Anyway my doubt is:
It's said in there that in most cases an address like $1000 (for example) won't be used cause you use a label that point to a cetain address instead.
Something like: move #1,$1000
would, more commonly be written like:
...
move #1,marker
...
marker:dc.w 1

The last instruction is a pseudo instruction for the assembler and defines the marker label.
BUT SHOULDN'T IT BE LIKE:
marker:dc.w $1000
!!!!!!!!!

Another doubt:
after reading the various types of addressing I don't get it what this type could be: #$1234678 (example)
it should be direct addressing (cause it uses a #) but why then in the other examples of this type of addressing they don't use  an hexadecimal number in none of them(I suppose it doesn't matter then)?

Yet another doubt:
So maybe this is what my doubts are surrounding, when using labels, the declarations at the end of the program (marker:dc.w 1 ;example) are just values that substitute the correspondent labels in the program? Something the also confused me in relation to this was the undocumented use of for example: move #marker,d1
 and :      move marker,d1 (examples)
What's the difference after all? If I stand correct the first one copies the value of the label marker defined at the end, wich could be 1 for example (marker:dc.w 1), to the data register d1.
The second example copies the contents of the address $1 to the data register d1?! But the end defines marker as 1 not $1, so I suppose addresses can be refered to as decimal values too?

Resuming either I'm too dumb or this tutorial sucks!! :-x
Must admit I haven't learned other language though, but it seem pretty straightforward until this doubts come up.
I know there are some hardcore Amigans in here so let's do ourselves what we wan instead of just waiting and doing nothing, and one  can help each other. Now help me in this cause I'm starta getting pissed off, andI don't have time to clear these doubts by myself.
Cheers
Title: Re: Assembler (68k) help (about dc pseudo op)
Post by: Kronos on January 13, 2003, 03:20:40 PM
68k-asm ? Long long ago .... but I will give it a try.

marker: dc.w 1
Means you got an variable (16bit) with the value "1" stored into it.

The Assmembler will replace
move #1,marker

with

move value_1 to address marker

You should never (really never) put an fixed number on any address,
because that variable will move with every piece of code you put before it.

Let the assembler sort out that mess  ;-)

"#" is NO addressing, you will use that number, and not the memory-cell
it would point to if used as an address.

move #marker,d1 load the address of you variable into d1
 move marker,d1 loads the contents of your variable into d1.


/me just hopes he hasn't made a complete fool of himself
Title: Re: Assembler (68k) help (about dc pseudo op)
Post by: Jose on January 13, 2003, 03:40:09 PM
Thanks. More or less what I though. I guess what I need is to start practicing cause I'm starting to forget the doubts I had themselves!!
One thing I'd really need cleared would be:
When there's something for example  like
value_1: dc.w 1
value_2: dc.w 1

I know the second value would be at an uneven address so an align would be necessary but, how da hell do I know the address of value_1 is even? Does the compiler give me info about that?
Title: Re: Assembler (68k) help (about dc pseudo op)
Post by: Kronos on January 13, 2003, 03:42:44 PM
double_di_hoop
Title: Re: Assembler (68k) help (about dc pseudo op)
Post by: Kronos on January 13, 2003, 03:42:58 PM
No it's not on an uneven address, it's just not alligned to 4.

AFAIR that is something a bit different on every assembler, so

RTFM ;-)
Title: Re: Assembler (68k) help (about dc pseudo op)
Post by: Jose on January 13, 2003, 03:51:03 PM
"RTFM"...
Yeah, but it should be easier to understand it if the tutorial taugh me it depended on the assembler.
I'm learning it cause from what I've always heard, migrating to ppc assembler is a breeze :-D
Title: Re: Assembler (68k) help (about dc pseudo op)
Post by: Skippy on January 13, 2003, 04:03:39 PM
Hardware reference manual:
http://www.amigarealm.com/computing/nkb12.htm
[not complete but useful]

Programming resources, tutorials etc:
http://www.amigarealm.com/resources/coding.htm

Skippy
Title: Re: Assembler (68k) help (about dc pseudo op)
Post by: Warface on January 13, 2003, 04:04:17 PM
In asmone there is a pseudo instruction called "even" or ".even", I can't remember. (And here's nothing to look up or try it out.)

In the assembler you can use pretty much numeric formats, the assembler will take care of the rest. If you want to use hexadecimal numbers, just use the "$" character, if you want you can use decimal numbers too, then no extra character required.

As Kronos said "#" has not such function, it just indicates that a direct value follows, instead of an address(ing mode).
Title: Re: Assembler (68k) help (about dc pseudo op)
Post by: Jose on January 13, 2003, 04:14:16 PM
I've read parts of Amigarealm various times, specially hardware reference stuff.
Lol. Skippy, you almost got me once, with that blonde girl pic you had before  :-o For some moments I though you were her.   :-D
Title: Re: Assembler (68k) help (about dc pseudo op)
Post by: z5 on January 13, 2003, 04:38:23 PM
it has always been my dream to learn assembler and code an intro or demo. But for some reason, i never got around to it. And it find it a real pity. Even now there still is that dream.

But i think it would cost me too much time learning asm on my own and i don't have that time anymore  :-x

Also, i think there are not a lot of good tutorials. What i was looking for was simple tutorials that i can run on AsmOne on my A1200 and from which i can study the code and mess with it. For example, just a black screen with a scrolltext or just one effect...
Title: Re: Assembler (68k) help (about dc pseudo op)
Post by: xeron on January 13, 2003, 05:25:22 PM
Kronos explained it all quite well, I just wanted to add the following:

If you want to make sure some data is on an even boundary, (ie address ends in 0, 2, 4, 6 etc.) you can do this:

[color=000099]    even
marker:
    dc.l 0
[/color]

And if you want it on a longword boundary (IE ends in 0, 4, 8 or a), you can do this:

[color=000099]    cnop 0,4
marker:
    dc.l 0
[/color]

Also, what I tend to do is pick an address register, and reference all my variable like this:

[color=000099]    lea    my_vars(pc),a4
    move.w #123,my_word(a4)
    move.l #123,my_long(a4)
    rts

               rsreset
my_word        rs.w 1
my_long        rs.l 1
my_vars_length rs.b 0

my_vars        ds.b my_vars_length
[/color]

A little explanation:

"rsreset" resets a pre-processor counter that is supported by PhxAss, AsmOne and AsmPro (I *think* devpac supports it too, but i cant remember).

rs.w sets the label to the current counter value, and adds 2 to the counter (.b adds 1, .l adds 4), so, its the same as:

my_word = 0
my_long = 2
my_vars_length = 6

(the reason we use the rscounter is that we can insert new variables without changing the offsets for all the ones after it).

Finally, we allocate the ram for our variables with the ds.b statement.

There are several reasons for doing this:

1) You can write to and read from bytes, words and longwords all referenced via your variable register (= faster. You can't do as many operations relative to PC)

2) Flexibility. You can assign space in your executable for variable RAM, like above, but you could just as easily allocate my_vars bytes with AllocMem (and your code could become re-entrant with no changes), or even just allocated on the stack with LINK (for subroutines with local variables).

I hope you understood all that... ddd[/color]
Title: Re: Assembler (68k) help (about dc pseudo op)
Post by: Skippy on January 13, 2003, 05:55:53 PM
@Pete,

You do exactly the same as me.

Extracts of my copper:
      Section   Misc,Code_C

gfxlib      dc.b   "graphics.library",0
      even
Doslib      dc.b   "dos.library",0
      even
stsv:      ds.l   1
      even

      rsreset
sysdma:      rs.w   1
sysint:      rs.w   1
sysirq:      rs.w   1
sysadk:      rs.w   1      
coppersave1   rs.l   1
coppersave2   rs.l   1
viewsave   rs.l   1
gfxbase:   rs.l   1
sysautovecs:   rs.l   6   
sysdata:   ds.w   __rs

COUNTER:   dc.B   0      fade one every other frame
      even
-----snipped
      Section   Copper,Data_C

; Long frame copperlist

copper1:dc.l   $01009200
   dc.l   $008e2981,$009029c1
   dc.l   $00920038,$009400d0
   dc.l   $01080000,$010a0000
spts:   dc.l   $01200000,$01220000,$01240000,$01260000,$01280000,$012a0000,$012c0000,$012e0000
   dc.l   $01300000,$01320000,$01340000,$01360000,$01380000,$013a0000,$013c0000,$013e0000
cols:   dc.l   $01800000,$01820fff,$01840000,$01860000,$01880000,$018a0000,$018c0000,$018e0000
   dc.l   $01900000,$01920000,$01940000,$01960000,$01980000,$019a0000,$019c0000,$019e0000
bplane4:dc.l   $00e00000,$00e20000,$00e40000,$00e60000,$00e80000,$00ea0000,$00ec0000,$00ee0000
   dc.l   $fe0ffffe,$01820000
Copper2:dc.l   $fffffffe,$fffffffe

Copper3:dc.w   $0100,%1100001000000100    HiRes, Interlace,1 plane
addr1:   dc.l   $00800000,$00820000
   dc.l   $008e2981,$009029c1
   dc.l   $0092003c,$009400d4
   dc.l   $01080050,$010a0050
   dc.l   $01200000,$01220000,$01240000,$01260000,$01280000,$012a0000,$012c0000,$012e0000
   dc.l   $01300000,$01320000,$01340000,$01360000,$01380000,$013a0000,$013c0000,$013e0000
colsa:   dc.l   $01800000,$01820122,$01840767,$0186058b
   dc.l   $0188069c,$018a08be,$018c0d99,$018e0bce
   dc.l   $01900a98,$01920ba9,$01940caa,$01960cbb
   dc.l   $01980dcc,$019a0ecc,$019c0fee,$019e0fff
bplanea:dc.l   $00e00000,$00e20000,$00e40000,$00e60000
   dc.l   $00e80000,$00ea0000,$00ec0000,$00ee0000
   dc.l   $fffffffe,$fffffffe

Copper4:dc.w   $0100,%1100001000000100    HiRes, Interlace,1 plane
addr2:   dc.l   $00800000,$00820000
   dc.l   $008e2981,$009029c1
   dc.l   $0092003c,$009400d4
   dc.l   $01080050,$010a0050
   dc.l   $01200000,$01220000,$01240000,$01260000,$01280000,$012a0000,$012c0000,$012e0000
   dc.l   $01300000,$01320000,$01340000,$01360000,$01380000,$013a0000,$013c0000,$013e0000
colsb:   dc.l   $01800000,$01820122,$01840767,$0186058b
   dc.l   $0188069c,$018a08be,$018c0d99,$018e0bce
   dc.l   $01900a98,$01920ba9,$01940caa,$01960cbb
   dc.l   $01980dcc,$019a0ecc,$019c0fee,$019e0fff
bplaneb:dc.l   $00e00000,$00e20000,$00e40000,$00e60000,$00e80000,$00ea0000,$00ec0000,$00ee0000
   dc.l   $fffffffe,$fffffffe
;000,122,767,58b,69c,8be,d99,bce,a98,ba9,caa,cbb,dcc,fee,fff

      Section   Picture,Data_C

Screen1:dcb.b   (640*256)/8,$00
   even        
Screen2:incbin   dh0:storage/sc/-data-/start2.raw      960*27
   even        
Blank   dcb.l   16,0
   even
font2:   incbin   dh0:storage/sc/-data-/13*8.raw      960*27
   even
mt_data:incbin   dh0:storage/music/xmas.mod
      END
Title: Re: Assembler (68k) help (about dc pseudo op)
Post by: Lando on January 13, 2003, 06:12:33 PM
Quote

z5 wrote:
it has always been my dream to learn assembler and code an intro or demo. But for some reason, i never got around to it. And it find it a real pity. Even now there still is that dream.

But i think it would cost me too much time learning asm on my own and i don't have that time anymore  :-x

Also, i think there are not a lot of good tutorials. What i was looking for was simple tutorials that i can run on AsmOne on my A1200 and from which i can study the code and mess with it. For example, just a black screen with a scrolltext or just one effect...


Don't give up - assembler is hard to learn to start with but once you grasp the basics its a lot of fun.

I recommend to look at the tutorials by Rombust/Nerve Axis which were in later issues of the "Grapevine" diskmag by LSD.  They should be on the Aminet somewhere.  They are excellent.  

And also get some good startup/shutdown code - hardware-banging is great fun but for some reason people tend to not be so happy these days when they quit out of your game/demo and their Workbench screen doesnt come back :)

Start off with something simple like making some copperbars, then making them move up and down, then displaying a picture, then making a scroller and so on... soon you'll end up with a complete intro that you can release at some party.
Title: Re: Assembler (68k) help (about dc pseudo op)
Post by: Skippy on January 13, 2003, 06:39:45 PM
I've just finished archiving over 125+ floppy disks of mine/friends sourcecode dating back to 1992.

These disks also include tutorial code from big name developers from 1988 =>, ie: bullfrog.

Currently all in .lha format on my a1200s' hard-drive.

When I've got time I'll upload some disks to my website for you.

Skippy
Title: Re: Assembler (68k) help (about dc pseudo op)
Post by: z5 on January 13, 2003, 10:06:54 PM
Quote
Don't give up - assembler is hard to learn to start with but once you grasp the basics its a lot of fun.

I recommend to look at the tutorials by Rombust/Nerve Axis which were in later issues of the "Grapevine" diskmag by LSD. They should be on the Aminet somewhere. They are excellent.

And also get some good startup/shutdown code - hardware-banging is great fun but for some reason people tend to not be so happy these days when they quit out of your game/demo and their Workbench screen doesnt come back :)

Start off with something simple like making some copperbars, then making them move up and down, then displaying a picture, then making a scroller and so on... soon you'll end up with a complete intro that you can release at some party.


Lando, maybe you know that i am webmaster of A.D.A. I've been totally crazy about demos since i saw the first cracktros. So you can imagine that this was a big dream for me. Just being able to make a basic scrolltext would have been cool!

But as said, it's not easy without the right tutorials. I downloaded some sources from internet but they already give an error on assembling in AsmOne  :-(

The code from some very basic intro, with a copperbar and a scrolltext, that would be nice to start. But i think i will give up on that dream.
Title: Re: Assembler (68k) help (about dc pseudo op)
Post by: Jose on January 13, 2003, 10:13:50 PM
Thanks all for the help. I'll have to look more into it when I have time, but I defenitly will. It's great fun and I now think people that don't learn to programm miss all the fun. Much cooler than playing games!
Title: Re: Assembler (68k) help (about dc pseudo op)
Post by: Cymric on January 16, 2003, 07:28:55 PM
Quote
Jose wrote:
snip... I'm learning it cause from what I've always heard, migrating to ppc assembler is a breeze :-D


The question then of course is 'why would you want to code assembly?' Assembly is tough on a programmer because it has you doing everything yourself. Register allocation, memory management, pointer arithmetic. There are little semantic checks. Debugging can be a nightmare, especially if you're writing a demo. Code can be tough to document, and will span many, many lines. Nowadays, only experts (think Real Programmer Mel here) can produce consistently faster assembly code than that of an optimising compiler, and even then the differences are slim.

Of course, there's noone stopping you from learning assembly: by all means, go right ahead, enjoy! Splurge! Smell the bare metal! Bash that blitter! Coerce that Copper! Pounce at Paula :-)! Nevertheless, if you plan to do program development---and that includes demos---on the A1, my advice would be to forget it has a PPC, and just use C or BASIC or any other high(er) level language.
Title: Re: Assembler (68k) help (about dc pseudo op)
Post by: Jose on January 21, 2003, 05:26:16 PM
This is much more fun :-D And you learn a lot of stuff, at I do cause my studies are not computer related.
Later I'll learn C. I allways do the opposite normal people do :-D
Title: Re: Assembler (68k) help (about dc pseudo op)
Post by: Cymric on January 21, 2003, 07:03:03 PM
Well, okay then. But make sure you do all the nasty stuff only assembly allows you do to. Like writing self-modifying code, or creating code that hooks into the illegal PC-exception vector to have 680x0-code execute at odd addresses. Or one of the many other particularly dirty things :-P.