English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 12 May 2007, 04:36   #1
bLAZER
Awesome to the max
 
bLAZER's Avatar
 
Join Date: Mar 2007
Location: Gothenburg / Sweden
Age: 48
Posts: 1,006
Learning assembler

Just started to learn myself assembler, I'm pretty good at c++, java and some other languages, however I want to learn Amiga assembler now. Tried it about 15 years ago, but I found it too hard then...

Ok, so I did a little program, it should find the biggest number in the list and save it in D1. Every time a run the progam D1 contains F00 though, I did some debuggin and it looks like A0 gets incremented by 2 every time, instead of 1. So where did I f-ed up? (And please don't laugh)
Code:
        clr.l   d0          ;clear registers
        clr.l   d1
        move.w  amount,d0   ;assign size of list to d0
        lea.l   list,a0     ;point to beginning of list
    
loop    cmp(a0)+,d1         ;is current number bigger than the one in d1?
        bls save            ;if so, go to save
cont    sub.w   #1,d0       ;decrement list counter
        bne.s   loop        ;go back and check next number
        rts                 ;no more numbers in list
    
save    move.w  -1(a0),d1   ;save current number-1 to d1
        bra cont            ;go back


amount  dc.w    5
list    dc.w    15,2,23,4,3
bLAZER is offline  
Old 12 May 2007, 05:00   #2
Codetapper
2 contact me: email only!
 
Codetapper's Avatar
 
Join Date: May 2001
Location: Auckland / New Zealand
Posts: 3,187
The main problem is you have move.w -1(a0),d1 in the save part. This is an illegal operation on a 68000 as you are moving a word but it is not word aligned, so it will crash. On a 68020+ that code will work.

To fix it, you need it to be move.w -2(a0),d1

If you are serious about learning, you should start with good habits as you will keep them as you learn:

cmp.w (a0)+,d1 instead of cmp (a0)+,d1
moveq #0,d0 instead of clr.l d0
lea list(pc),a0 instead of lea.l list,a0

Instead of hardwiring the amount as 5, calculate the length etc:

Code:
        lea     list(pc),a0
        move.w  #(listend-list)>>1,d0
        ...
list    dc.w    15,2,23,4,3
listend
Codetapper 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
Learning AMOS - Beginners Guide Disks Peter Retrogaming General Discussion 15 28 October 2015 17:17
DiskImage: When learning to read proves futile. XDelusion support.Apps 19 20 October 2012 23:57
Wanting to start learning to code amiga in asm fishyfish Coders. Asm / Hardware 5 03 March 2012 06:11
Suggestions for learning pmc Coders. Tutorials 248 20 October 2010 21:42
Playpower - 8 bit learning games for the developing world girv Retrogaming General Discussion 5 24 March 2009 22:00

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 01:09.

Top

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