16-bit addition

Purpose:

To add the contents of the 16-bit variable value1 and location $6000 to the contents of the 16-bit variable value2 at location 6002 and place the result in the 16 bit variable result at location $6004.

Sample Test Data:

input:

value1: (6000) = 10F5
value2: (6002) = 2621

output:

result: (6004) = 3716

Recall that ( ) means "contents of". Also when we write (6000) = 10F5 we in fact mean (6000) = 10 and (6001) = F5.

 

Source Code:

Version 1

data equ $6000  
program equ $4000  
       
  org data  
value1 ds.w 1 ;first value
value2 ds.w 1 ;second value
result ds.w 1 ;to contain result
       
       
  org program  
  move.w value1, d0 ;get first value
  add.w value2, d0 ;add numbers together
  move.w d0, result ;store result

 

Source Code:

Version 2

This way of doing it is wasteful of time and effort on the both the programmer's and the computer's part.
It is provided as a way of introducing indexed addressing in an easy way. Normally such addressing
is used in the context of a loop where, on each pass through the loop, access is made to the next element in
a list.

equ and ds operations as for version 1

     
  org program  
  movea.l #value1, a0 ;make a0 point to value1
  move.w (a0), d0 ;first value to d0
  adda.l #2, a0 ;make a0 point to value2
  add.w (a0), d0 ;add numbers together
  adda.l #2, a0 ;make a0 point to result
  move.w d0, (a0) ;store contents of d0 in wherever a0 is pointing to, i.e. into the variable result

Back to 68000 program contents page