68k 大会:ORG 2000 美元和 DS.L 功能
68k Assembly: ORG $2000 and DS.L functionality
我有一个 68k 汇编程序,它计算 3x3 数组对角线中值的平均值并存储它。
ORG 00
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 00 ; what does this do?
store ds.l 1 ; notice its long word
END START ; last line of source
我理解这段代码中发生的一切,除了以下几行:
org 00 ; 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 通常做什么?
ORG
定义下一个值开始的内存地址
ds.l
保留长字而不初始化它们
在这种情况下,一个长字以 $2000 的价格保留,没有为其指定任何特定值。 store
被理解为指向该位置的指针。
我确实建议将 68k org 或 68k ds.l 写入您最喜欢的搜索引擎,注意信息很快可用。
org 00
只是将当前地址设置为 00
,这意味着接下来的 store
标签将位于 00
。无论出于何种原因,这就是预期的结果。 ds.l
保留给定数量的长字,在本例中为 1
。 move.l d7,store
将在那里写入 d7
。这大概是在这个任务的规范中,类似于“在地址 $2000 处产生一个长字结果”。
我有一个 68k 汇编程序,它计算 3x3 数组对角线中值的平均值并存储它。
ORG 00
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 00 ; what does this do?
store ds.l 1 ; notice its long word
END START ; last line of source
我理解这段代码中发生的一切,除了以下几行:
org 00 ; 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 通常做什么?
ORG
定义下一个值开始的内存地址
ds.l
保留长字而不初始化它们
在这种情况下,一个长字以 $2000 的价格保留,没有为其指定任何特定值。 store
被理解为指向该位置的指针。
我确实建议将 68k org 或 68k ds.l 写入您最喜欢的搜索引擎,注意信息很快可用。
org 00
只是将当前地址设置为 00
,这意味着接下来的 store
标签将位于 00
。无论出于何种原因,这就是预期的结果。 ds.l
保留给定数量的长字,在本例中为 1
。 move.l d7,store
将在那里写入 d7
。这大概是在这个任务的规范中,类似于“在地址 $2000 处产生一个长字结果”。