I have a 68k Assembly program that calculate the average of values in a 3x3 array's diagonal and stores it.
ORG $1000
START: ; first instruction of program
* Put program code here
move.w n,d6 ; d6 = 0000 0003
clr.l d7 ; sum = 0
move.w #2,d4 ; size of element 0000 0002
mulu.w d6,d4 ; n times size of element
; d4 0000 0006
movea.l #A,a0 ; address of the array
loop tst.w d6 ; if (n == 0)
beq done ; go to done else go to next instruction
subq.w #1,d6 ; 3 - 1, 2 - 1, 1 - 1, done
add.w (a0)+,d7 ; a0 address is incremented 2 bytes since its word length
; content of address a0 is stored in d7
; d7 = 0000 0001, 0000 0005, 0000 0009
add.l d4,a0 ; increment for diagonals which in 3x3 = 3 position = 6 bytes
; a0 = 02 + 06 = 08, 08 + 06 = 10 hex = 16 decimal
bra loop ; restart loop until condition is met
done divu.w n,d7 ; now d7 has the sume of diagonals
; d7 = 1 + 5 + 9 = 15
; 15 / 3 = 5
; result is stored in d7 = 5
move.l d7,store ; d7 is stored in
SIMHALT ; halt simulator
* Put variables and constants here
A dc.w 1,2,3,4,5,6,7,8,9
n dc.w 3
org $2000 ; what does this do?
store ds.l 1 ; notice its long word
END START ; last line of source
I understand everything going on in this code except for the lines:
org $2000 ; what does this do?
store ds.l 1 ; notice its long word
Can someone explain to me in simple words, what org "$2000" is doing and "ds.l 1". What is the DS command doing and what does the number 1 after it, represents?
I check the memory block d7 value is stored in address 0000 2000 but again what does this have to do with the number 1 in front of DS.L and what does ORG do in general?
org $2000
just sets the current address to $2000
meaning the following store
label will be at $2000
. For whatever reason, that's where the result is expected. ds.l
reserves the given number of longwords, 1
in this case. The move.l d7,store
will write d7
there. This is presumably in the specification for this task, that is something like "produce a longword result at address $2000".