English Amiga Board

English Amiga Board (http://eab.abime.net/index.php)
-   Coders. Asm / Hardware (http://eab.abime.net/forumdisplay.php?f=112)
-   -   Help with badly breaking line of code (http://eab.abime.net/showthread.php?t=100403)

KONEY 13 January 2020 13:26

Help with badly breaking line of code
 
I'm stuck with a small piece of code which breaks badly on 16 bit machines. With "badly" I mean that it will compile but once executed everything would stuck and needs a reboot.

The code works OK on my A600 with Vampire and on an emulated A3000 but breaks on a real A500 or an emulated one therefore I think it's a problem with 16 bit machines.

the line of code is MOVE.L (A2)+,(A3) so nothing strange, I've been asking to some demoscene guy who told me there should be no problem executing this on any Amiga. :banghead

Here the complete routine:

Code:

PRINT:
        LEA        BITPLANE,A3        ; Indirizzo del bitplane destinazione in a3
        MOVE.L        #KONEY,A2
        CLR        D6
        MOVE.B        #4,D6                ; RESET D6
        ADD.W        #40*115,A3        ; POSITIONING

LOOP:                                ; LOOP KE CICLA LA BITMAP
        ADD.W        #15,A3
        MOVE.L        (A2)+,(A3)       
        ADD.W        #25,A3
        DBRA        D6,LOOP
        RTS

And here the complete source:
https://github.com/KONEY/asm68k-test...OGOBPM_ANIM2.s

Any hint would be appreciated!!

KONEY 13 January 2020 13:29

forgot to say this is just an ASM exercise which I'm slowly learning :)

Hedeon 13 January 2020 13:31

Not entirely sure, but doesn't the 68000 need 16 bit alignment when writing 32 bits? And seeing you are adding uneven numbers to A3 it fails on that?

sparhawk 13 January 2020 13:35

The problem is this line!
Code:

ADD.W        #15,A3
On 68000 (10/20 as well?) the data needs to be on an even address for word or longword access, so this will cause a guru. On higher CPUs this will work, but causes a speed penality.

Another thing that I find strange is that you do
Code:

LEA        BITPLANE,A3
This means that your "bitplane" is defined in your source, right? But the bitplane must be located in chipmem, so if this is just a buffer, this is fine. If this is really a bitplane to be displayed, you must make sure that it is in chipmem.

Hedeon 13 January 2020 13:37

020 should be fine. Not sure about the 010.

Hedeon 13 January 2020 13:44

Quote:

Originally Posted by sparhawk (Post 1371279)
This means that your "bitplane" is defined in your source, right? But the bitplane must be located in chipmem, so if this is just a buffer, this is fine. If this is really a bitplane to be displayed, you must make sure that it is in chipmem.

He defines BSS_C for the bitplane

KONEY 13 January 2020 13:57

YES that was the problem!!! Actually you can do the addition with odd values but further operations on the A register would make everything crash... I was focusing on the wrong line but I definitely learnt a lesson today. Thanks Hedeon and thanks to everyone!

Quote:

Originally Posted by Hedeon (Post 1371277)
Not entirely sure, but doesn't the 68000 need 16 bit alignment when writing 32 bits? And seeing you are adding uneven numbers to A3 it fails on that?


roondar 13 January 2020 13:58

Simple code like that* which works for the 68020/68030 but fails on the 68000 almost always means using odd addresses somewhere in the code. The 68000 can only read or write bytes to and from odd addresses. For all other operand sizes addresses need to be even.

... And now I see that someone already wrote that... Should've read the thread first. Anyway, sparhawk is correct - you can't add an odd number of bytes to an address in a loop when using move.w or move.l to or from that address.

*) as in code that does not use any instruction that only works on the 68010+.

sparhawk 13 January 2020 14:02

Quote:

Originally Posted by KONEY (Post 1371286)
YES that was the problem!!! Actually you can do the addition with odd values but further operations on the A register would make everything crash...


Yes. of course. You can have an address register with an odd value. You just can't use this address to access word or longs.


so this is fine:

Code:

move.l #1,a0
.loop:
  move.b (a0)+,d0
  bne .loop


But this would crash:

Code:

move.l #1,a0
.loop:
  move.w/l (a0)+,d0
  bne .loop

Actually, thereotically you could write a trap handler, which catches this, and fixes the access, but that would not be a good idea in the usual case. :)

Hedeon 13 January 2020 14:42

Quote:

Originally Posted by KONEY (Post 1371286)
Actually you can do the addition with odd values but further operations on the A register would make everything crash...

That's what I meant :-) Adding an uneven number to A3 would lead to 32 bit access to a non-16 bit alligned address. Glad to have been of some help.


All times are GMT +2. The time now is 17:09.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.

Page generated in 0.04303 seconds with 11 queries