whoknows101 0 Newbie Poster

How do I check to see if the posts are the same in the end?


PROGRAM IDENTIFICATION SECTION:
Input : The value of N.
Output : The factorial of N.
Purpose: Computes the factorial of N, after N is input by the user.
PROCEDURES CALLED:
External procedures called:
FROM iofar.lib: PutStr, PutCrLf, GetDec, PutDec
Internal procedures called:
Greet, MoveDisc
|
;****** BEGIN MAIN PROGRAM ************************************
DOSSEG
.186
.model large
.stack 200h
;****** MAIN PROGRAM DATA SEGMENT *****************************
.data
Prompta db 'Enter the number of Disks(3-10): $'
Promptb db 'Enter the starting pole(1-3): $'
Promptc db 'Enter the ending pole(1-3): $'
Announce db 'The number of moves done was: $'
sPole dw ?
ePole dw ?
disk dw ?
COUNT dw ?
;****** MAIN PROGRAM CODE SEGMENT *****************************
.code
extrn PutCrLf: PROC
extrn GetDec: PROC, PutDec: PROC
ProgramStart PROC NEAR
; Initialize ds register to hold data segment address
mov ax,@data
mov ds,ax
; call subroutine to print a greeting to the user
call Greet

PROMA:
; prompt user for an integer and input the integer from keyboard
mov dx,OFFSET Prompta ; point to the Prompt mesg
mov ah,9 ; DOS print string function #
int 21h ; print string
; get input integer from user for which factorial will be computed
call far ptr GetDec ; get integer from keyboard, return in ax
call far ptr PutCrLf
; checks input
cmp ax, 3
jl PROMA
cmp ax, 10
jg PROMA
; store input integer in variable disk
mov disk,ax ; Store in location for variable disk


PROMB:
; prompt user for an integer and input the integer from keyboard
mov dx,OFFSET Promptb ; point to the Prompt mesg
mov ah,9 ; DOS print string function #
int 21h ; print string
; get input integer from user for which factorial will be computed
call far ptr GetDec ; get integer from keyboard, return in ax
call far ptr PutCrLf
; checks input
cmp ax, 1
jl PROMB
cmp ax, 3
jg PROMB
; store input integer in variable sPole
mov sPole,ax ; Store in location for variable sPole


PROMC:
; prompt user for an integer and input the integer from keyboard
mov dx,OFFSET Promptc ; point to the Prompt mesg
mov ah,9 ; DOS print string function #
int 21h ; print string
; get input integer from user for which factorial will be computed
call far ptr GetDec ; get integer from keyboard, return in ax
call far ptr PutCrLf
; checks input
cmp ax, 1
jl PROMC
cmp ax, 3
jg PROMC
; store input integer in variable ePole
mov ePole,ax ; Store in location for variable ePole
; push parameters on stack, call RecFact, pop parameters from stack
push disk ; push onto stack as Value parameter
push sPole ; push onto stack as Value parameter
push ePole ; push onto stack as Value parameter
call MoveDisk ; MoveDisk(disk, sPole, ePole)
; print message announcing factorial result
mov dx,OFFSET Announce ; point to the result message
mov ah,9 ; DOS print string function #
int 21h ; print string
; print the result of computing the factorial
mov ax,COUNT ; prepare parameter for count in ax
call far ptr PutDec ; Print the decimal integer in ax
call far ptr PutCrLf
mov ah,4ch ; DOS terminate program fn #
int 21h
ProgramStart ENDP
comment |
******* PROCEDURE HEADER **************************************
PROCEDURE NAME : Greet
PURPOSE : To print an initial greeting to the user
PROCEDURES CALLED :FROM iofar.lib: PutStr, PutCrLf
CALLED FROM : main program
|
;****** SUBROUTINE DATA SEGMENT ********************************
.data
Msgg1 db ' Welcome to the Towers of Hanoi program $'
Msgg2 db ' Programmer: My Name $'
Msgg3 db ' Date: October 16, 2007 $'
;****** SUBROUTINE CODE SEGMENT ********************************
.code
Greet PROC near
; Save registers on the stack
pusha
pushf
; Print name of program
mov dx,OFFSET Msgg1 ; set pointer to 1st greeting message
mov ah,9 ; DOS print string function #
int 21h ; print string
call PutCrLf
; Print name of programmer
mov dx,OFFSET Msgg2 ; set pointer to 2nd greeting message
mov ah,9 ; DOS print string function #
int 21h ; print string
call PutCrLf
; Print date
mov dx,OFFSET Msgg3 ; set pointer to 3rd greeting message
mov ah,9 ; DOS print string function #
int 21h ; print string
call PutCrLf
call PutCrLf
; Restore registers from stack
popf
popa
; Return to caller module
ret
Greet ENDP
comment |
******* PROCEDURE HEADER **************************************
PROCEDURE NAME : MoveDisk
PURPOSE : moves disks around on poles and calls itself recursivly
INPUT PARAMETERS :Pass by value parameters - N, M, O
OUTPUT PARAMETERS:Pass by reference parameter - Fact, the factorial of N
PROCEDURES CALLED :FROM iofar.lib: PutCrLf, GetDec
CALLED FROM : Main Program and MoveDisk
|
;****** SUBROUTINE DATA SEGMENT ********************************
.data
Msgg4 db '.)Move disk $'
Msgg5 db ' from pole $'
Msgg6 db ' to pole $'

;****** SUBROUTINE CODE SEGMENT ********************************
.code
MoveDisk PROC NEAR
pusha
pushf
; set up bp register to point to parameters
mov bp, sp
; IF01 disk = 1
mov cx,[bp+24]
cmp cx, 1
je ELSE01
; THEN01 disk != 1
mov cx,[bp+24]
dec cx
push cx
push [bp+22]
mov ax, 6
sub ax, [bp+20]
sub ax, [bp+22]
push ax
call MoveDisk

inc COUNT

; print the result of computing the factorial
mov ax,COUNT ; prepare parameter for count in ax
call far ptr PutDec ; Print the decimal integer in ax
; prompt user for an integer and input the integer from keyboard
mov dx,OFFSET Msgg4 ; point to the Prompt mesg
mov ah,9 ; DOS print string function #
int 21h ; print string
; prompt user for an integer and input the integer from keyboard
mov ax, [bp+24] ; point to the Prompt mesg
call PutDec ; print the decimal integer in ax
; prompt user for an integer and input the integer from keyboard
mov dx,OFFSET Msgg5 ; point to the Prompt mesg
mov ah,9 ; DOS print string function #
int 21h ; print string
; prompt user for an integer and input the integer from keyboard
mov ax,[bp+22] ; point to the Prompt mesg
call PutDec ; print the decimal integer in ax
; prompt user for an integer and input the integer from keyboard
mov dx,OFFSET Msgg6 ; point to the Prompt mesg
mov ah,9 ; DOS print string function #
int 21h ; print string
; prompt user for an integer and input the integer from keyboard
mov ax,[bp+20] ; point to the Prompt mesg
call PutDec ; print the decimal integer in ax
call PutCrLf
mov cx, [bp+24]
dec cx
push cx
mov cx, 6
sub cx, [bp+22]
sub cx, [bp+20]
push cx
push [bp+20]
call MoveDisk
jmp ENDIF01
; disk == 1
ELSE01:
inc COUNT
; print the result of computing the factorial
mov ax,COUNT ; prepare parameter for count in ax
call far ptr PutDec ; Print the decimal integer in ax
; prompt user for an integer and input the integer from keyboard
mov dx,OFFSET Msgg4 ; point to the Prompt mesg
mov ah,9 ; DOS print string function #
int 21h ; print string
; prompt user for an integer and input the integer from keyboard
mov ax, [bp+24] ; point to the Prompt mesg
call PutDec ; print the decimal integer in ax
; prompt user for an integer and input the integer from keyboard
mov dx,OFFSET Msgg5 ; point to the Prompt mesg
mov ah,9 ; DOS print string function #
int 21h ; print string
; prompt user for an integer and input the integer from keyboard
mov ax,[bp+22] ; point to the Prompt mesg
call PutDec ; print the decimal integer in ax
; prompt user for an integer and input the integer from keyboard
mov dx,OFFSET Msgg6 ; point to the Prompt mesg
mov ah,9 ; DOS print string function #
int 21h ; print string
; prompt user for an integer and input the integer from keyboard
mov ax,[bp+20] ; point to the Prompt mesg
call PutDec ; print the decimal integer in ax
call PutCrLf
jmp ENDIF01

ENDIF01:
; restore registers and return having passed the result back

popf
popa

ret 6
MoveDisk ENDP
end ProgramStart

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.