Question: ; This simple assembly language calculates permutations .586 ;Target processor. Use instructions for Pentium class machines .MODEL FLAT ;Use the flat memory model, standard calling

 ; This simple assembly language calculates permutations .586 ;Target processor. Use

; This simple assembly language calculates permutations

.586 ;Target processor. Use instructions for Pentium class machines

.MODEL FLAT ;Use the flat memory model, standard calling convention

INCLUDE io.h

.STACK 4096 ;Define a stack segment of 4KB

.DATA ;Create a near data segment. Local variables are declared here

labelN BYTE "Calculating permutations and combinations; enter N: ", 0

labelK BYTE "Calculating permutations and combinations; now enter K: ", 0

permLbl BYTE "The number of permutations is ", 0

Nvalue DWORD 0

Kvalue DWORD 0

numPerms DWORD 0

rawstr BYTE 128 DUP (?), 0

outstr BYTE 40 DUP (?), 0

.CODE ;Indicates the start of a code segment.

_MainProc PROC

input labelN, rawstr, 127 ; ask for a user-input string

atod rawstr

mov Nvalue, eax ; save N to memory

input labelK, rawstr, 127 ; ask for a user-input string

atod rawstr

mov Kvalue, eax ; save K to memory

push eax

mov eax, Nvalue ; get N back and pass to the routine

push eax ; pass N to the permutation routine

call permut

mov numPerms, eax ; save permutations

add esp, 8 ; clean up the stack

dtoa outstr, eax ; convert to string and

output permLbl, outstr ; show the permutations value

nop

ret ; go back to Windows?

_MainProc ENDP

; The routine permut accepts two parameters N and K and returns N! / (N-K)!

; only valid for values up to 12 (otherwise factorial is too big)

The number of permutations of N things taken K at a time is given by p(N,K) = (NNK) . I want you to write and test a routine to compute the number of permutations for a given N and K. I have given you the top level code below; all you need to do is to write the routine permut. The number of permutations of N things taken K at a time is given by p(N,K) = (NNK) . I want you to write and test a routine to compute the number of permutations for a given N and K. I have given you the top level code below; all you need to do is to write the routine permut

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!