Skip to main content

8086 Assembly Program to Compute the Power of a Number Using Exponentiation by Squaring

This blog post details an 8086-assembly program that computes the power of a number using the Exponentiation by Squaring algorithm (O(log n) efficiency). While a standard iterative approach multiplies the base n times (taking O(n) time), exponentiation by squaring—also known as binary exponentiation—works by breaking the exponent down into its binary components. By squaring the base in each step and only multiplying it into the result when a bit in the exponent is set, we drastically reduce the computational load. For example, calculating x32 requires only 5 multiplications instead of 31. This example demonstrates advanced assembly concepts like bitwise manipulation, conditional branching, and efficient arithmetic optimization. Let’s get started! Logic Breakdown: The algorithm follows the mathematical identity of Binary Exponentiation: Check Exponent: If it's zero, stop. Odd Case: If the current exponent is odd, multiply the running result by the current base. Square and Halve: Regardless of odd/even, square the base and divide the exponent by 2. Loop: Continue until the exponent is exhausted. Let's visualize it's working for 53. StepBase ExponentResult ActionInitial531Start loopIter 153 (Odd)51 X 5 = 5Square251552 = 25, 3/2 = 1Iter 2251 (Odd)1255 X 25 = 125Square6250125252 = 625,1/2 = 0Exit-0125Loop terminates

JUnit @RepeatedTest in JUnit 6: RepetitionInfo, failureThreshold, and Real Flaky-Test Detection

JUnit's @RepeatedTest runs the same method N times, each with its own pass/fail result. Rebuilt here against real JUnit 6.1.3 on JDK 25: all four RepetitionInfo accessors (not just two), RepetitionInfo injected into @BeforeEach/@AfterEach, what failureThreshold actually does when it fires (skips, not stops), a real flaky-test detection demo, and a placeholder the original version of this post claimed existed but never did.

8086 Assembly Program to Compute the Power of a Number

This blog post details an 8086-assembly program that computes the power of a number, specifically baseexponent. This example demonstrates fundamental assembly concepts like loops, multiplication, and register manipulation to perform iterative arithmetic. Let’s get started! data segment base dw 0003h exponent dw 0004h result dd ? data ends code segment assume cs:code, ds:data start: ; Initialize data segment mov ax, data mov ds, ax ; Initialize result to 1 (R = B^0) mov word ptr result, 0001h mov word ptr result+2, 0000h ; Load base and exponent mov cx, exponent ; CX = exponent (loop counter) mov bx, base ; BX = base cmp cx, 0000h je exit ; If exponent is 0, result is already 1. Jump to exit. power_loop: ; Multiply result by base ; The result is a 32-bit number in result[0] (lower word) and result[2] (upper word) ; Multiplication requires careful handling of the 32-bit result with a 16-bit multiplier. ; 1. Multiply the lower word of result by base mov ax, word ptr result ; AX = result[0] mul bx ; AX * BX -> DX:AX (32-bit product) push dx ; Save the higher word (DX) of the product mov word ptr result, ax ; Store the lower word (AX) of the product as the new result[0] ; 2. Multiply the upper word of result by base mov ax, word ptr result+2 ; AX = result[2] mul bx ; AX * BX -> DX:AX (32-bit product) ; 3. Add the two 16-bit 'carry' terms pop cx ; Retrieve the saved higher word (DX) from step 1 into CX add ax, cx ; AX = AX + CX (Sum of two high words) adc dx, 0000h ; DX = DX + 0 + Carry from the previous ADD (final carry from the 32-bit multiplication) ; 4. Store the final upper word mov word ptr result+2, ax ; Store AX as the new result[2] ; Handle the 32-bit overflow (DX is the final carry from the 32-bit multiplication) ; For a 32-bit result storage, this program assumes the result fits in 32-bits. ; If the power is large, overflow might occur, which is a limitation of this 32-bit storage approach. loop power_loop ; Decrement CX and jump back to power_loop if CX != 0 exit: int 3 ; Program termination code ends end start

TypeScript Arithmetic Operators: The Definitive Guide

TypeScript didn’t reinvent JavaScript’s arithmetic — it just gave you a seatbelt. Under the hood, every +, -, *, /, and ** behaves exactly like in JavaScript, including all the quirky coercion rules that have launched a thousand memes. What TypeScript adds is the ability to catch those bugs at compile time instead of 3 a.m. when a user enters “banana” in a price field. This guide covers every arithmetic operator in TypeScript with modern, real-world examples, in-depth explanations, common pitfalls, performance notes, and a cheat-sheet you’ll actually use. 1. Unary Operators Unary Plus + Purpose: Explicitly converts its operand to a number using the same algorithm as Number() but much faster. +"42"; // 42 +"3.14"; // 3.14 +""; // 0 (empty string → 0) +" 123 "; // 123 (trims whitespace!) +"0xFF"; // 255 (recognizes hex) +"abc"; // NaN +true; // 1 +false; // 0 +null; // 0 +undefined; // NaN (compile error if strictNullChecks is on)

Spring Security Context Propagation: The Complete Guide (With Virtual Threads & Structured Concurrency)

Spring Security's SecurityContext is the cornerstone of authentication and authorization in Spring applications, but propagating it across thread boundaries is a real trap in async, reactive, and now virtual-thread code. This guide covers ThreadLocal strategies, servlet and WebFlux propagation, @Async/ExecutorService/CompletableFuture, and—updated for Boot 4.1—virtual threads, DelegatingSecurityContextExecutor, ContextPropagatingTaskDecorator, and StructuredTaskScope, each verified against real, captured output.

8086 Assembly Program to Compute Factorial of an Integer Using Recursion

This blog post will dive into a more advanced concept in 8086 assembly: computing the factorial of a number using recursion. Unlike iterative approaches using loops, recursion involves a procedure calling itself. This example highlights crucial concepts of stack management (PUSH and POP), procedure calls (CALL and RET), and conditional jumping to handle base cases. Let’s explore how the stack handles the "memory" of recursive calls! ; Program to calculate Factorial of a number using Recursion ; Input: num (e.g., 5) ; Output: result (e.g., 5! = 120 or 78h) data segment num dw 0005h ; The number to calculate factorial for (16-bit word) result dw ? ; Variable to store the final 16-bit result data ends code segment assume cs:code, ds:data start: mov ax, data mov ds, ax ; Initialize Data Segment mov cx, num ; Load the input number into CX register used as counter/argument mov ax, 0001h ; Initialize accumulator AX to 1 (needed for multiplication) call factorial ; Call the recursive procedure mov result, ax ; Store final result from AX into memory variable int 3 ; Breakpoint to halt and check registers ;--- Recursive Procedure Definition --- factorial proc near cmp cx, 1 ; BASE CASE: Check if number in CX is <= 1 jbe base_case ; If CX is 0 or 1, jump to base_case to return push cx ; RECURSIVE STEP: Save current state of CX on STACK dec cx ; Decrement CX to move towards base case (N-1) call factorial ; Recursive Call: factorial(N-1) pop cx ; UNWINDING: Restore the saved value of CX from STACK mul cx ; AX = AX * CX. (Current Result * Current N) ret ; Return to caller base_case: mov ax, 1 ; Base case returns 1 (as 0! = 1 and 1! = 1) ret ; Return to caller factorial endp ;-------------------------------------- code ends end start

Master Custom Authentication Providers in Spring Security 7.1

A from-scratch guide to writing a custom AuthenticationProvider in Spring Security 7.1 (Spring Boot 4.1): what actually wires an AuthenticationProvider bean into the AuthenticationManager, why the old manual ProviderManager pattern was never necessary, and how to run a custom provider alongside a JWT-secured API in the same application without the two colliding.

How to Check if a Number is a Pronic Number in Java

Whether you are preparing for a technical interview or exploring the fascinating world of number theory, encountering Pronic numbers is almost a rite of passage for Java developers. These numbers, often hidden in pattern-matching puzzles, have unique properties that make them a favorite for practicing algorithmic efficiency. In this guide, we will dive deep into what Pronic numbers are and demonstrate two distinct ways to identify them using Java—ranging from a beginner-friendly loop to a high-performance mathematical "trick." What is a Pronic Number? A Pronic number (also known as an oblong or rectangular number) is a number that is the product of two consecutive integers. Mathematically, a number P is pronic if it can be expressed as: P = n X (n + 1) For some integer n. Examples of Pronic Numbers: 0: 0 X 1 = 0 2: 1 X 2 = 2 6: 2 X 3 = 6 12: 3 X 4 = 12 20: 4 X 5 = 20