Multiplying the 16-bit number 90h by 3

In the following program example we will multiply the 16-bit number 90h by 3. This algorithm lets you multiply any numbers.

Program source code

; Author: Evgeny Sergeevich Dovgopolov

main:
    lxi     d, 90h        ; Load the hexadecimal value 90h into the DE register pair
    mvi     a, 03h        ; Copy the multiplier into register A

    lxi     h, 0000h      ; Load the hexadecimal value 0000h into the HL register pair
    mvi     c, 08h        ; Set the loop counter C to 8

MultiplyLoop:
    dad     h             ; Multiply the value in HL by 2
    ral                   ; Rotate the value in register A one bit left through the CY flag
    jnc     Next          ; If C=0, then jump to the label Next

    dad     d             ; Add the contents of the DE register pair to the contents of the HL register pair

Next:
    dcr     c             ; Decrement the C counter register by 1
    jnz     MultiplyLoop  ; Jump to the label MultiplyLoop until C becomes 0

    hlt                   ; Stop program execution

Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".