Saturday, November 8, 2008

Multiplication Table Program

A multiplication table program that accepts up to 10 as n value

Source Code:

jmp start

newLine db 10,13,"$"
space db " $"
cont_mess db 10,13," Do you want to continue (y/n) :$"
msg1 db 10,13," Enter number: $"
mulframe1 db 10,13," ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
db 10,13," º Multiplcation Table º"
db 10,13," ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ$"
cnt_num db 0
num1 db 0
num2 db 0
num_final db 0
product db 0
temp1 db 0
temp2 db 0
temp3 db 0

start:

mov ax,3
int 10h
mov product,0
mov num1,0
mov num2,0


lea dx,mulframe1
mov ah,9
int 21h

call new_Line

lea dx,msg1
mov ah,9
int 21h

mov ah,1
int 21h
sub al,30h

mov num1,al

mov ah,1
int 21h
cmp al,13
je execute

sub al,30h
mov num2,al

mov al,num1
mov bl,10

mul bl
mov num1,al

execute:

mov al,num1
mov bl,num2
add al,bl

cmp al,1
jl start
cmp al,10
jg start

mov num_final,al

call clear


call new_Line

mov al,num_final
mov ah,0
mov si,ax

mov cnt_num,1
mov di,0
outerloop:
call new_Line
mov product,0

mov al,num_final
mov ah,0

mov cx,ax

mov al,0
innerloop:
mov al,product
mov bl,cnt_num
add al,bl
mov product,al
mov product,al

call spacer
call spacer
call spacer2
call mul_display

loop innerloop

inc cnt_num
inc di
cmp di,si
jne outerloop

call continue



new_Line:
lea dx,newLine
mov ah,9
int 21h
ret
clear:
xor ax,ax
xor bx,bx
ret

mul_display:
call clear

mov al,product

mov bl,10

div bl
mov temp1,ah
mov temp2,al

call clear
mov bl,10
mov al,temp2

div bl
mov temp3,al
mov temp2,ah

call clear

cmp temp3,0
je tens

mov al,temp3

hundred:

mov dl,al
or dl,30h
mov ah,2
int 21h

tens:

mov al,temp2
mov bl,temp3

add al,bl
cmp al,0
je ones
mov al,temp2

mov dl,al
or dl,30h
mov ah,2
int 21h

ones:
mov al,temp1
mov dl,al
or dl,30h
mov ah,2
int 21h
ret
spacer:
lea dx,space
mov ah,9
int 21h

ret
spacer2:
mov al,product
cmp al,9
jg return

lea dx,space
mov ah,9
int 21h
return:
ret

continue:
call new_Line
xor dx,dx

lea dx,cont_mess
mov ah,9
int 21h

mov ah,1
int 21h

cmp al,'y'
je start_bridge
cmp al,'n'
je con_quit

jmp continue

start_bridge:
call start
con_quit:
int 20h
fullclear:
xor ax,ax
xor bx,bx
xor cx,cx
xor dx,dx
ret

2 comments:

Arun Prabhakar said...

Hey I have used 8086 assembly programming, how do you use the CALL ?

For now I am doing things with MACRO's.

Check out my factorial program for finding upto 255!

http://digitalpbk.blogspot.com/2008/11/masm-assembly-factorial-program-big.html

syue said...

i am taking this 8086 as 1 of my subject,,my lecturer ask me to solve this question,,can you help me by give the answers of this questions?
calculate and displays the 3xN multiplication table for N = (0->12) using a loop structure .the output should show the results in both HEX and DECIMAL numbers and be formatted as follows:
N 3xN(decimal) 3xN(hex)
1 3 3
2 6 6
3 9 9
.
.
.
12 36 24