I am coding this in Motorola68k simulator. I want my program to execute this task:
- (Address of first element of linked list is saved on address $6000 (longword) followed by length of the list (word) and final result (word))
- Go through linked list (every element of list is containing address of next element (longword) followed by BCD number (byte))
- Sum all BCD numbers of linked list and save the sum in RESULT.
I understand how to go through each element of the list but I'm struggling to add BCD numbers. I want to add in each iteration to numbers and store them in D6, then at the end put D6 in RESULT. Here is my code:
DATA: EQU $1500
PROG: EQU $1000
LIST: EQU $6000
LEN: EQU $1500 ;lenght of BCD numbers (all are .B)
NUM1: EQU $1510
NUM2: EQu $1520
ORG LISTA
FIRST DS.L 1
LENGHT DS.W 1
RESULT DS.W 1
ORG PROG
START:
MOVE.L FIRST, A0
MOVE.W LENGHT, D1
MOVEQ #0, D2
MOVEQ #0, D6
CLR.W RESULT
SUM_LOOP:
CMP.W #0, D1
BEQ DONE
MOVEQ #0, D3
MOVE.L (A0)+, A1
MOVE.B (A0), D3
MOVE.B D3, NUM1
MOVE.L A1, A0
MOVE.L (A1)+, A1
MOVE.B (A1), D5
MOVE.B D5, NUM2
CLR.W D4
MOVE.B #1, LEN
MOVE.B LEN, D4
MOVE.W D4, A5
LEA NUM1(A5), A3
LEA NUM2(A5), A4
SUBQ #1, D4
MOVE #0, CCR
LOOP:
ABCD.B -(A4), -(A3)
DBRA D4, LOOP
ADD.L NUM1, D6
SUBQ.W #1, D1
BRA SUM_LOOP
DONE:
MOVE.W D6, RESULT
MOVE.B #9,D0
TRAP #15 ; halt simulator
END START