4x4 by addition
4x4 by addition
.model small
.stack 100h
.data
result db 6 dup(?) ; Buffer to store ASCII representation of result
newline db 0ah, 0dh, '$' ; Newline characters for printing
.code
main:
mov ax, 4 ; Initialize multiplicand
mov bx, 4 ; Initialize multiplier
xor cx, cx ; Clear CX register (for loop counter)
xor dx, dx ; Clear DX register (for carry)
multiply_loop:
add dx, ax ; Add multiplicand to DX (accumulate result)
jnc no_carry ; If no carry, skip
inc cx ; Increment CX if carry occurs
no_carry:
dec bx ; Decrement multiplier
jnz multiply_loop ; Jump to multiply_loop if multiplier is not zero
store_result:
mov ax, dx ; Move accumulated result to AX
div byte ptr 10 ; Divide by 10 to get ASCII digit
add dl, '0' ; Convert remainder to ASCII digit
mov [si+di], dl ; Store ASCII digit in result buffer
dec di ; Decrement DI for moving to next position in result buffer
test ax, ax ; Check if quotient is zero
jnz store_result ; If not zero, continue storing ASCII digits
end main