当我们有这样的代码时:
main: MOV #SFE(CSTACK), SP ; set up stack
;;; some instructions .......
; load the starting address of the array1 into the register R4
MOV.W #arr1, R4
; load the starting address of the array1 into the register R5
MOV.W #arr2, R5
; Sum arr1 and display
CLR R7 ; Holds the sum
MOV #8, R10 ; number of elements in arr1
lnext1: ADD @R4+, R7 ; get next element
DEC R10
JNZ lnext1
MOV.B R7, P1OUT ; display sum of arr1
SWPB R7
MOV.B R7, P2OUT在这个例子中,做SWPB R7的原因/意义是什么?我阅读了这些文档,并了解到它可以交换低端/高端字节;在一些文档中,它说它会乘以256。这是唯一的原因还是我错过了更深层次的东西?应该添加寄存器元素的代码。
发布于 2017-09-11 07:43:13
只能访问较低的字节。因此,为了能够将上字节复制到其他地方,必须先将其移动到较低的字节。(上一个下字节在交换后位于上字节,这是一个不重要的副作用。)
还会有其他效率较低的机制来获取较高的字节,例如将寄存器右移8次:
MOV.B R7, P1OUT
RRA R7
RRA R7
RRA R7
RRA R7
RRA R7
RRA R7
RRA R7
RRA R7
MOV.B R7, P2OUT或者将16位值存储到临时变量中,然后直接访问该变量的两个字节:
MOV.W R7, temp_low ; writes both bytes
MOV.B temp_low, P1OUT
MOV.B temp_high, P2OUT
.bss
.align 2
temp_low: .space 1
temp_high: .space 1对于较新的MSP430家族,端口寄存器的排列使您可以使用单个16位访问访问两个端口:
MOV.W R7, PAOUThttps://stackoverflow.com/questions/46147548
复制相似问题