Multiplication table
A program that prints the multiplication table for a given number from 1 to 9.
Program source code
title .model small .stack 100h data segment public askUser db "Enter a positive number: \0" output db "\n%d * %d = %d\0" fmtinput db "%d" number dw ? data ends code segment public ; Start of the code segment assume ds:data, cs:code include Handyfar.inc ; Include the file with functions main proc ; Start of the main procedure call SetDataSegment ; Call the SetDataSegment procedure lea ax, ds:[askUser] ; Load the address of the askUser variable into ax call WriteString ; Call the WriteString procedure lea ax, ds:[number] ; Load the address of the number variable into the ax register push ax ; 2nd: save the ax register value on the stack lea ax, ds:[fmtinput] ; 1st: load the address of the fmtinput format string into ax call ScanFormatString ; Call the ScanFormatString procedure add sp, 2 ; Align the stack mov cx, 1 ; Set the counter to 1 MulitplyLoop: mov ax, number ; Copy the value of the number variable into the ax register mul cx ; Multiply the value in the ax register by the value in cx push ax ; 4th: save the ax register value (the multiplication result) on the stack push cx ; 3rd: save the value of the cx counter register on the stack push number ; 2nd: save the value of the number variable on the stack lea ax, ds:[output] ; 1st: load the address of the output format string into ax call PrintFormatString ; Call the PrintFormatString procedure add sp, 6 ; Align the stack inc cx ; Increment the value of the cx counter register by 1 cmp cx, 9 ; Compare the value of cx with the number 9 jbe MulitplyLoop ; If CX is less than or equal to 9, jump to MulitplyLoop xor al, al ; Clear the al register call ExitProcess ; Call the ExitProcess procedure main endp ; End of the main procedure code ends ; End of the code segment end main ; End of file. The main procedure is the entry point
Enter a positive number: 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".