PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > RTOS và Thuật toán với PIC

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Bài Trong Ngày Vi điều khiển

RTOS và Thuật toán với PIC RTOS và Các thuật toán dùng cho PIC/dsPIC/PIC32
Mod: phamminhtuan

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 02-11-2006, 08:55 PM   #3
anhquangngai
Đệ tử 2 túi
 
Tham gia ngày: Sep 2006
Bài gửi: 33
:
Trích:
Nguyên văn bởi falleaf View Post
Code:
#define bf_carry 3, 0
#define bf_zero 3, 2

#define same 1
#define wreg 0

#define stc bsf bf_carry
#define clc bcf bf_carry

;-[ Div ]--------------------------------------------------------------
; Call w/: Number in f_divhi:f_divlo, divisor in W.
; Returns: Quotient in f_divlo, remainder in f_divhi. W preserved.
;          Carry set if error. Z if divide by zero, NZ if divide overflow.
; Notes:   Works by left shifted subtraction.
;          Size = 29, Speed(w/ call&ret) = 7 cycles if div by zero
;          Speed = 94 minimum, 129 maximum cycles

Div;
    addlw 0          ; w+=0 (to test for div by zero)
    stc              ; set carry in case of error
    btfsc bf_zero    ; if zero
     return          ;   return (error C,Z)

    call DivSkipHiShift
iDivRepeat = 8
while iDivRepeat

    call DivCode

iDivRepeat--
endw

    rlf f_divlo, same ; C << lo << C

    ; If the first subtract didn't underflow, and the carry was shifted
    ; into the quotient, then it will be shifted back off the end by this
    ; last RLF. This will automatically raise carry to indicate an error.
    ; The divide will be accurate to quotients of 9-bits, but past that
    ; the quotient and remainder will be bogus and carry will be set.

    bcf bf_zero  ; NZ (in case of overflow error)
    return       ; we are done!

DivCode
    rlf f_divlo, same    ; C << lo << C
    rlf f_divhi, same    ; C << hi << C
    btfss bf_carry       ; if Carry
     goto DivSkipHiShift ;
    subwf f_divhi, same  ;   hi-=w
    stc                  ;   ignore carry
    return               ;   done
                         ; endif
DivSkipHiShift
    subwf f_divhi, same  ; hi-=w
    btfsc bf_carry       ; if carry set
     return              ;   done
    addwf f_divhi, same  ; hi+=w
    clc                  ; clear carry
    return               ; done
Đây là thuật toán chia 16bit cho 8bit. Bạn tìm hiểu và phân tích thêm nhé, có lẽ mafd_47a sẽ giúp bạn phân tích source code này thêm.

Chúc vui.
vậy thì khi muốn chia thì làm như thế nào?
Anh có thể chỉ cụ thể hơn dc ko?
anhquangngai vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 


Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến

Similar Threads
Ðề tài Người gửi Chuyên mục Trả lời Bài mới
Thảo luân: Vấn đề download, chia sẻ và dịch tài liệu odense Đóng góp ý kiến 19 02-11-2018 03:16 PM
Tạo thư viện tài liệu riêng và chia sẻ falleaf Đóng góp ý kiến 4 29-03-2018 03:12 PM
Dự án chia sẻ thư viện ORCAD/PROTEL falleaf Thực hành 88 05-11-2014 10:58 PM
Chiều gắn LED vào mạch linhbx PIC - Thiết kế và Ứng dụng 36 24-10-2013 06:19 PM
Ngành điện tử VN được ưu tiên nhưng không có chiến lược falleaf Trao đổi ngoài luồng 0 17-06-2006 07:39 PM


Múi giờ GMT. Hiện tại là 10:10 PM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam