0% found this document useful (0 votes)
10 views

4x4 by addition

This assembly language program multiplies 4 by 4 using an addition loop and outputs the result in ASCII format. It initializes the multiplicand and multiplier, accumulates the result, converts it to ASCII, and prints it to the screen. The program concludes by exiting cleanly after displaying the result.

Uploaded by

kentrollins5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

4x4 by addition

This assembly language program multiplies 4 by 4 using an addition loop and outputs the result in ASCII format. It initializes the multiplicand and multiplier, accumulates the result, converts it to ASCII, and prints it to the screen. The program concludes by exiting cleanly after displaying the result.

Uploaded by

kentrollins5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

; Multiplication of 4 * 4 using addition loop and print the answer in ASCII

.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

mov si, offset result ; Load address of result buffer


mov di, cx ; Move CX to DI for indexing result buffer

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

mov ah, 9 ; Function to print string


lea dx, result ; Load address of result buffer
int 21h ; DOS interrupt

mov ah, 9 ; Function to print newline


lea dx, newline ; Load address of newline characters
int 21h ; DOS interrupt

mov ah, 4ch ; Exit program


int 21h ; DOS interrupt

end main

You might also like