Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;A way to calculate the approximate square root of a int number is to count the amount of odd numbers that can be subtracted from starting number.
- ;The proposed solution in C language is:
- ; main()
- ; {
- ; int num, sqr=0, disp=1;
- ; ...
- ; num--;
- ; while (num >= 0)
- ; { sqr++;
- ; disp += 2;
- ; num -= disp; }
- ; ...
- ; }
- ;Realize a program that computes the approximate square root of a positive int (16 bit)
- .MODEL small
- .STACK
- .DATA
- NUM DW 121 ;Number of which I would compute square root
- disp DW 1
- SQRT DW 0
- .CODE
- .STARTUP
- MOV CX,2
- DEC NUM
- ciclo:
- INC SQRT ;In the end, the square root is stored in SQRT
- ADD disp,CX
- MOV AX,disp
- SUB num,AX
- JNS ciclo ;I use JNS, that is: if the number is unsigned, then continue to cycle
- .EXIT
- END
- ;I simply translated in Assembly the C code given above
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement