100x100个整数数组A,每个字节一个字节,位于A。编写一个程序段来计算小对角线的和,即
SUM =ΣAi,99-i,其中Σ
到目前为止,这就是我所拥有的:
LEA A, A0
CLR.B D0
CLR.B D1
ADDA.L #99, D0
ADD.B (A0), D1
ADD.B #1, D0
BEQ Done
ADDA.L #99,A0
BRA loop发布于 2013-05-06 11:23:28
这段代码中存在很多问题,包括(但不限于):
在表演方面:
考虑到代码与解决方案的距离足够近,这里有一个变体(我没有测试,希望它能工作)
lea A+99*100,a0 ; Points to the first column of the last row
moveq #0,d0 ; Start with Sum=0
moveq #100-1,d1 ; 100 iterations
Loop
moveq #0,d2 ; Clear register long
move.b (a0),d2 ; Read the byte
add.l d2,d0 ; Long add
lea -99(a0),a0 ; Move one row up and one column right
dbra d1,Loop ; Decrement d1 and branch to Loop until d1 gets negative
Done
; d0 now contains the sumhttps://stackoverflow.com/questions/15469109
复制相似问题