2016-02-28 27 views
0

我有一個68k大會程序,計算3x3陣列的對角線的值的平均值並將其存儲。

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 

我什麼都明白了這個代碼怎麼回事除了行:

org  $2000   ; what does this do? 
store ds.l 1  ; notice its long word 

有人能在簡單的話給我解釋一下,什麼組織「$ 2000」在做什麼,「ds.l 1」 。什麼是DS命令,它後面的數字1代表什麼?

我檢查內存塊d7的值是否存儲在地址0000 2000中,但這又與DS.L前面的數字1有什麼關係,ORG通常做什麼?

回答

0

org $2000只是將當前地址設置爲$2000這意味着以下store標籤將在$2000。無論出於何種原因,這都是預期的結果。在這種情況下,ds.l保留給定數量的長字,1move.l d7,store將在那裏寫入d7。這大概是在這個任務的規範中,就像「在地址$ 2000產生長字的結果」。

1

ORG定義從中下一值開始

ds.l儲量長字而不初始化它們

在這種情況下,一個長字在$ 2000被保留而不分配任何特定值到它的存儲器地址。 store被理解爲指向此位置的指針。

我建議寫68K組織68K ds.l到您最喜愛的搜索引擎,並注意信息快速可用。