bit manipulation - MSP430 SWAP bytes explanation assembly -
when have code :
main: mov #sfe(cstack), sp ; set stack ;;; instructions ....... ; load starting address of array1 register r4 mov.w #arr1, r4 ; load starting address of array1 register r5 mov.w #arr2, r5 ; sum arr1 , display clr r7 ; holds sum mov #8, r10 ; number of elements in arr1 lnext1: add @r4+, r7 ; next element dec r10 jnz lnext1 mov.b r7, p1out ; display sum of arr1 swpb r7 mov.b r7, p2out
what reason/meaning behind doing swpb r7 in example? read docs , understand exchanges low/high end bytes; in docs says multiplies 256. reason or missing deeper here? code supposed add elements of register.
mov.b can access lower byte. able copy upper byte somewhere else, must moved lower byte first. (that previous lower byte in upper byte after swap unimportant side effect.)
there other, less efficient mechanisms @ upper byte, such shifting register right 8 times:
mov.b r7, p1out rra r7 rra r7 rra r7 rra r7 rra r7 rra r7 rra r7 rra r7 mov.b r7, p2out
or storing 16-bit value temporary variable, , accessing 2 bytes of variable directly:
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
with newer msp430 families, port registers arranged can access 2 ports single 16-bit access:
mov.w r7, paout
Comments
Post a Comment