ceibawx
Junior Member level 2
- Joined
- Oct 13, 2008
- Messages
- 24
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- chongqing,China
- Activity points
- 1,606
assembly subtract
subtract in assembly code in pic16f628a
I need subtract for three times in assembly code in pic16f628a. I wrote a stupid code, it is too long. and I am wondering whether I can use a loop to do it.
1) the data is saved in 0x40~0x51.The data is from 8channels, every channel is 12bits. so two channels occupy three bytes in memory. for example channel 1 and channel 2 occupy 0x40,0x41,0x42.
2) channel 2 - channel 8;
channel 4 - channel 6;
channel 3 - channel 7;
I choose this group, because I think channel2 has the same structure to channel8. it is easier to subtract than channel2-channel3.
3) before subtract, ANDLW is used to get the four bits from a byte register.
4) first subtract the lower bits, then subtract the higher bits according judging the value of STATUS, C of lower bits.
5) lower bits are stored firstly in memory register, then high bits are stored in latter memory place. for example, one subtract result, higher bits is stored in 0x60, while lower bits are stored in 0x61.
so all subtraction result are stored in 0x60 0x61 0x62 0x63 0x64 0x65.
Anybody can help me?
Code:
subtract in assembly code in pic16f628a
I need subtract for three times in assembly code in pic16f628a. I wrote a stupid code, it is too long. and I am wondering whether I can use a loop to do it.
1) the data is saved in 0x40~0x51.The data is from 8channels, every channel is 12bits. so two channels occupy three bytes in memory. for example channel 1 and channel 2 occupy 0x40,0x41,0x42.
2) channel 2 - channel 8;
channel 4 - channel 6;
channel 3 - channel 7;
I choose this group, because I think channel2 has the same structure to channel8. it is easier to subtract than channel2-channel3.
3) before subtract, ANDLW is used to get the four bits from a byte register.
4) first subtract the lower bits, then subtract the higher bits according judging the value of STATUS, C of lower bits.
5) lower bits are stored firstly in memory register, then high bits are stored in latter memory place. for example, one subtract result, higher bits is stored in 0x60, while lower bits are stored in 0x61.
so all subtraction result are stored in 0x60 0x61 0x62 0x63 0x64 0x65.
Anybody can help me?
Code:
Code:
list P=16f628a
#include <p16f628a.inc>
ByteCounter EQU 0x39
goto Main
Main:
BCF STATUS,RP0 ;bank 0
BCF STATUS,RP1
MOVLW 0x07
MOVWF CMCON
BSF STATUS,RP0 ;bank 1
BCF TRISB,2 ;output
;uart setting
MOVLW 0x15
MOVWF SPBRG
BCF TXSTA,TX9
BSF TXSTA,TXEN
BCF TXSTA,SYNC
BSF TXSTA,BRGH
BCF STATUS,RP0 ; bank 0
BSF RCSTA,SPEN
BCF RCSTA,RX9
BSF RCSTA,CREN
Save:
;f>w
MOVLW 0x31
MOVWF 0x40
MOVLW 0x32
MOVWF 0x41 ;0x50 for diff
MOVLW 0x33
MOVWF 0x42
MOVLW 0x34
MOVWF 0x43 ;0x51 for diff
MOVLW 0x48
MOVWF 0x44
MOVLW 0x47
MOVWF 0x45 ;0x52 for diff
MOVLW 0x46
MOVWF 0x46
MOVLW 0x45
MOVWF 0x47 ;0x53 for diff
MOVLW 0x44
MOVWF 0x48
MOVLW 0x43
MOVWF 0x49
MOVLW 0x42
MOVWF 0x50
MOVLW 0x41
MOVWF 0x51
;*******Subtraction*************
BCF STATUS,RP0 ;bank0
;**********the first substraction*************
Ch2_8:
;****get the 5-8bits of 0x41 0x50******
MOVLW 0x0F
ANDWF 0x41,0
MOVWF 0x6A ; 0x41' address
MOVLW 0x0F
ANDWF 0x50,0
MOVWF 0x6B; 0x50' address
;*******(0x42)-(0x51) save to 0x61******
BCF STATUS,C
MOVF 0x51,0
SUBWF 0x42,0
MOVWF 0x61;
;*******substract according to C value*****
BTFSS STATUS,C
GOTO Ch28_value0;C=0
BCF STATUS,C;C=1
;(0x6A)-(0x6B) to 0x60
MOVF 0x6B,0
SUBWF 0x6A,0
MOVWF 0x60;
goto Ch4_6
Ch28_value0: ;C=0,(0x6A)-1-(0x6B) to 0x60
BCF STATUS,C
MOVF 0x6B,0
SUBWF 0x6A,0
MOVWF 0x60;
;-1 check C???
MOVLW 0x01;
SUBWF 0x60,1
goto Ch4_6
;*********the second*****************************
Ch4_6:
MOVLW 0x0F
ANDWF 0x44,0
MOVWF 0x6C ; 0x44' address
MOVLW 0x0F
ANDWF 0x47,0
MOVWF 0x6D; 0x47' address
;(0x45)-(0x48) to 0x63
BCF STATUS,C
MOVF 0x48,0
SUBWF 0x45,0
MOVWF 0x63;
BTFSS STATUS,C
GOTO Ch46_value0;C=0
BCF STATUS,C;C=1
;(0x6C)-(0x6D) to 0x62
MOVF 0x6D,0
SUBWF 0x6C,0
MOVWF 0x62;
goto Ch3_7
Ch46_value0: ;C=0,(0x6C)-1-(0x6D) to 0x63
BCF STATUS,C
MOVF 0x6D,0
SUBWF 0x6C,0
MOVWF 0x62;
;-1 check C??? C ??,??????
MOVLW 0x01;
SUBWF 0x62,1
goto Ch3_7
;*************the third*******************************
Ch3_7:
movlw 0xF0;
andwf 0x44,0
movwf 0x6E; 44'' in 6E
movlw 0xF0;
andwf 0x50,0
movwf 0x6F; 50'' IN 6F
;*****substract************
BCF STATUS,C ;(6E)-(6F) to (65)
MOVF 0x6F,0
SUBWF 0x6E,0
MOVWF 0x65;
btfss STATUS,C
GOTO Ch37_value0; C=0
;C=1 (43)-(49) TO (64)
bcf STATUS,C
movf 0x49,0
subwf 0x43,0
movwf 0x64;
goto Stop
Ch37_value0: ;C=0 (43)-1-(49) TO (64)
bcf STATUS,C
movf 0x49,0
subwf 0x43,0
movwf 0x64;
;-1
movlw 0x01;
subwf 0x64,1
;60 61 62 63 64 65
GOTO Stop
Stop:
GOTO Stop
END