Categories
- 4th semester (27)
- 5th semester (3)
- ADA (13)
- Assembly Level Language (12)
- BE (45)
- C Language Programming (5)
- C language (20)
- C++ Language (5)
- CCP Lab programing (3)
- Computer Programming Lab (3)
- DAA Lab Programming (13)
- Data Structure and C++ laboratory Program (6)
- Data Structure and C++ labotary Program (5)
- Design and Analysis of algorithm (14)
- First Year (5)
- MASM (12)
- Microprocessor (12)
- Microprocessor lab program (12)
- System Software & OS Laboratory (5)
- Unix program (4)
- bachelor of engineering (30)
- basic (1)
- basic mathematics (2)
- beginners (10)
- c++ program (9)
- calculations (7)
- computer science (30)
- downloadable (5)
- engineering syllabus (4)
- simple program (6)
Trend Posts
Blogger news
Author
Followers
Blog Archive
-
▼
2014
(37)
-
▼
February
(12)
- a program to create a file (input file) and to del...
- Read a pair of input co-ordinates in BCD and move ...
- Write a program to simulate a Decimal Up-counter t...
- Read the current time from the system and display ...
- Compute nCr using recursive procedure. Assume that...
- Read your name from the keyboard and display it at...
- Read two strings, store them in locations STR1 and...
- Reverse a given string and check whether it is a p...
- Read an alphanumeric character and display its equ...
- Sort a given set of ‘n’ numbers in ascending order...
- Write two ALP modules stored in two different file...
- Search a key element in a list of ‘n’ 16-bit numbe...
-
▼
February
(12)
Friday, February 21, 2014
ASSUME
DS: DATA,
CS: CODE
DATA SEGMENT ; start of data segment
N DB 07H ; initialize the N value
R DB 05H ; R value
RESULT DB ? ; Variable to
store the result
MSG1 DB 0DH, 0AH,"NCR IS :
","$"
MSG2 DB 0DH, 0AH,"
NCR COMPUTATION IS NOT POSSIBLE (VALUE OF N< R)","$"
DATA ENDS ; end of data
segment
DISP MACRO MSG
MOV DX, OFFSET MSG ; DISP macro
definition, to display the message whose offset is in DX using
MOV AH, 09H ; 09H with DOS 21H interrupt.
INT 21H
ENDM ; end of macro definition.
CODE SEGMENT
START: MOV AX, DATA ; data segment initialization
MOV
DS, AX
MOV
AL, N ; store the N value in AL
MOV
BL, R ; store the R value in BL
CMP
AL, BL ; compare N and R value
JB STOP ; if N value is < than R value, then
jump to label STOP
MOV
RESULT, 0 ; otherwise
perform ncr computation, initialize RESULT variable to 0
CALL
FNCR ; call FNCR
procedure, to perform ncr computation.
DISP
MSG1 ; invoke the macro to display MSG1
MOV AL, RESULT ; ncr value (Hex) stored in RESULT is copied to AL.
AAM ; convert the 2 digit result in AL to unpacked BCD.
ADD AX, 3030H ; add
3030H to AX
PUSH
AX ; store in stack memory
MOV DL, AH ; display the upper digit of the result
on the screen using 02H with
MOV AH,
02H ; DOS 21H interrupt.
INT
21H
POP AX ; retrieve the original AX content from
stack
MOV DL, AL
MOV AH, 02H ; display the upper digit of the result on the screen using 02H
with
INT 21H ;DOS
21H interrupt.
JMP EXIT ; jump to label EXIT and terminate
STOP : DISP MSG2 ; invoke
the macro to display MSG2 (ncr is not possible)
EXIT : MOV AH, 4CH ; terminate the
program
INT 21H
FNCR PROC NEAR ; start of FNCR procedure
CMP AL, BL ;
compare N and R value
JE
NCR1 ;
if n = r then jump to label NCR1
to store the value 1 in RESULT variable.
CMP BL, 00 ; otherwise compare r value with 0
JE NCR1 ;
if r = 0, then jump to label NCR1
to store the value 1 in RESULT variable.
CMP BL, 01 ; otherwise compare r value with 01
JE NCRN ;
if r = 1, then jump to label NCRN
to store the ‘n’
value in RESULT variable.
DEC AL ;
decrement n by 1, so that n = n-1
CMP AL, BL ; then compare r value with n-1
JE ADD1 ;
if r = n-1, then jump to label ADD1, to
increment the ‘n’ value by 1.
; to get the n value which is already decremented by 1(n = n-1+1 = n)
PUSH AX ; push n-1 to stack
PUSH BX ; push ‘r’ to stack
CALL
FNCR ;
call FNCR procedure (recursive) to perform n-1Cr
POP BX ;
pop r
POP
AX ;
pop n-1
DEC BL ; decrement r
PUSH AX ; push
n-1
PUSH BX ;
push r-1
CALL
FNCR ;
call FNCR procedure to compute n-1C r-1
POP BX ;
pop r-1
POP AX ; pop n-1
RET ; return from
procedure
NCR1: INC RESULT ; increment result by 1
RET ; return
ADD1: INC AL ; increment n value by 1 ( since n
is decremented )
NCRN: ADD RESULT, AL ;
add result and n
RET ; return to main
program
FNCR ENDP ;end
of procedure
CODE ENDS ;
end of code segment
END START ; end of program
Output:
For
sample input N = 07H and R = 05H
D:\MASM>
Masm 8a.asm;
D:\MASM>
Link 8a.obj;
Subscribe to:
Post Comments (Atom)
2 comments:
wow !!!!! cool man.... i could understand something at least because of the clear comments on the right side ...
Great stuff! Thanks
Post a Comment
You are very Important to Us...
STAY TUNE...