Доброго, всем Котам!
Объясните плиз, не могу разобраться.
Фрагмент кода......Коментарии мои
P_ROG
CLRF VAR_2F ;
CLRF VAR_2E ;
P_PROG_1
MOVLW H'10'
MOVWF VAR_32 ;
L_22C
RLF VAR_27,W ; Вход - VAR_27 VAR_26 - Делимое
RLF VAR_2E,F ;
RLF VAR_2F,F ; VAR_2B VAR_2A - Делитель
MOVF VAR_2A,W ;
SUBWF VAR_2E,F ; Выход - VAR_27 VAR_26 (W) VAR_26=W
MOVF VAR_2B,W ;
BTFSS STATUS,C ;
INCFSZ VAR_2B,W ;
SUBWF VAR_2F,F ;
BTFSC STATUS,C ;
GOTO L_23E ;
MOVF VAR_2A,W ;
ADDWF VAR_2E,F ;
MOVF VAR_2B,W ;
BTFSC STATUS,C ;
INCFSZ VAR_2B,W ;
ADDWF VAR_2F,F ;
BCF STATUS,C ;
L_23E
RLF VAR_26,F
RLF VAR_27,F
DECFSZ VAR_32,F
GOTO L_22C
MOVF VAR_26,W
RETURN
-------------------------------
Вопросы .....
1. Какое это деление - целочисленное ?
2. числа только положительные ?
3. Что дает анализ флага С после вызова этой подпрограммы ?
4. Назначение переменных VAR_2F и VAR_2E ?
5. Что произойдет если вызвать CALL P_PROG_1 при условии, что VAR_2F=0 VAR_2E=0Fh ?
Заранее спасибо, откликнувшимся.
Вопрос по коду для PIC
- Реклама
Re: Вопрос по коду для PIC
А что мешает прогнать пошагово всю программу в MPLAB и самому разобраться ?
Re: Вопрос по коду для PIC
Гонял в MPLAB. Что понял в комментариях, а остальное нет.
64Н / 01Н = 64Н С=0
65Н / 01Н = 64Н С=1
Как это понять? Вот и спрашиваю у ГУРУ.
64Н / 01Н = 64Н С=0
65Н / 01Н = 64Н С=1
Как это понять? Вот и спрашиваю у ГУРУ.
Re: Вопрос по коду для PIC
Может єто проще будет:
Спойлер
Код: Выделить всё
;***********************************************************
;Unsigned 24 bit by 8 bit divide routine
;
; Inputs:
; Dividend - x,x+1,x+2 (x+2 - most significant!)
; Divisor - y
; Temporary:
; Counter - counter
; Output:
; Quotient - x,x+1,x+2 (x+2 - most significant!)
; Remainder - x+3
;
; Size: 17
; Timing: 342 cycles (including call and return)
;
; This is basically Nikolai Golovchenko's 24 by 16 bit
; divide routine, with some instructions removed to
; optimise it for an 8 bit divide.
; Thanks to Nikolai for the original post.
;
; James Hillman, 2 December 2005
;***********************************************************
FXD248U:
CLRF Summ3 ;remainder
MOVLW d'24'
MOVWF counter
LOOPU248
RLF Summ0,W ;shift dividend left to move next bit to remainder
RLF Summ1,F ;
RLF Summ2,F ;
RLF Summ3,F ;shift carry (next dividend bit) into remainder
RLF Summ0,F ;finish shifting the dividend and save carry in x.0,
;since remainder can be 9 bit long in some cases
;This bit will also serve as the next result bit.
MOVF j,W ;substract divisor from 8-bit remainder
SUBWF Summ3,F
;here we also need to take into account the 9th bit of remainder, which
;is in x.0. If we don't have a borrow after subtracting from
;8 bits of remainder, then there is no borrow regardless of 9th bit
;value. But, if we have the borrow, then that will depend on 9th bit
;value. If it is 1, then no final borrow will occur. If it is 0, borrow
;will occur. These values match the borrow flag polarity.
BTFSC STATUS,0 ;if no borrow after 8 bit subtraction
BSF Summ0,0 ;then there is no borrow in result. Overwrite
;x.0 with 1 to indicate no borrow.
;if borrow did occur, x.0 already
;holds the final borrow value (0-borrow,
;1-no borrow)
BTFSS Summ0,0 ;if no borrow after 9-bit subtraction
ADDWF Summ3,F ;restore remainder. (w contains the value
;subtracted from it previously)
DECFSZ counter,F
GOTO LOOPU248
RETURN
Re: Вопрос по коду для PIC
korsaj Спасибо, код похожий, может есть у Вас
Unsigned 24 bit by 16 bit divide routine или
Unsigned 24 bit by 24 bit divide routine
Вообщем нормальные библиотеки, чтобы покопаться,
а то есть еще куча вопросов по другим мат. функциям?
Unsigned 24 bit by 16 bit divide routine или
Unsigned 24 bit by 24 bit divide routine
Вообщем нормальные библиотеки, чтобы покопаться,
а то есть еще куча вопросов по другим мат. функциям?
- Реклама
Re: Вопрос по коду для PIC
Спасибо буду разбираться.korsaj писал(а):Все тут http://www.piclist.com/techref/microchi ... /index.htm


