Advertisement
LshySVK

MSP430 Babylonian square root

May 4th, 2023 (edited)
675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | Source Code | 0 0
  1. #include <msp430.h>
  2. #include <stdint.h>
  3.  
  4. uint16_t WhatAmIDoing (uint16_t E) {
  5.  
  6.     volatile uint16_t F;
  7.     volatile uint16_t G;
  8.     volatile int16_t counter = 0;
  9.     F = E;
  10.     G = (F + (E / F)) / 2;
  11.     while ((F - G) >= 1) {
  12.         counter = counter + 1;
  13.         F = G;
  14.         G = (F + (E / F)) / 2;
  15.     }
  16.     return G;
  17. }
  18.  
  19.  
  20. void main(void) {
  21.     WDTCTL = WDTPW | WDTHOLD;
  22.     volatile uint16_t in = 65000;
  23.     volatile uint16_t out = 0;
  24.  
  25.     while(1){
  26.         out = WhatAmIDoing (in);
  27.     }
  28. }
  29.  
  30. https://cs.wikipedia.org/wiki/Babyl%C3%B3nsk%C3%A1_metoda
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement