Write an assembly language program, Assembly Language

Assignment Help:

You are to write an assembly language program called subfaq.s that computes the generalized subfactorial function of nonnegative integer inputs i0 and n. The generalized subfactorial function is defined by the following recursion.

gs(0) = 1
inc(0) = i0

gs(n) = n gs(n-1) - inc(n-1)
inc(n) = -inc(n-1)

The generalized subfactorial function is closely related to the factorial function:
Factorial(n) can be written n! and is equal to gs(n) when i0 = 0.
Subfactorial(n) can be written !n and is equal to gs(n) when i0 = 1.

The values of both factorial and subfactorial get large very rapidly as n increases, so your program should return a 64-bit number representing gs(n) mod 264. In other words, just let your 64-bit register overflow. Try to make your code as short and efficient as possible. I recommend not using recursion, but rather writing a loop that starts from 0 and increments up to n. Write your assembly code from scratch rather than writing C and compiling to assembly. It takes only 10 to 20 instructions, and this will be your only assignment to write code in assembly. Don't miss out on the experience. You may copy your procedure entry and exit code from the textbook or the gcc compiler output without citing the source. Try to get your assembly code for subfac.s to occupy at most 50 bytes (30 is possible). To see your machine code, use
gcc64 -c subfaq.s

to produce object file subfaq.o , then use
objdump64 -d subfaq.o .

The following C program (called run_subfaq.c ) can be used to test your subfaq function. Do not include it with your submission; I already have it.

lli subfaq(int n, lli i0);

int main(int argc, char* argv[])
{
int i = 1, n;
lli i0, ans;
if(argc < 3) {printf("Usage: gs i0 n1 n2 n3 ... (list of non-negative integers)"); return -1;}
sscanf(argv[i++], "%lld", &i0);
while (i < argc) {
sscanf(argv[i], "%d", &n);
if(n < 0) printf("%d out of range\n", n);
else {
ans = subfaq(n, i0);
printf("gs(%d, %lld) = %lld\n", n, i0, ans);
}
i++;
}
return(0);
}

The compile command to test your programs will look like this:
gcc64 -Wall -std=gnu99 -o gs run_subfaq.c subfaq.s .
Here are two sample outputs to use in testing your programs.
C:>gs 0 0 1 2 3 4 5 6 13
gs(0, 0) = 1
gs(1, 0) = 1
gs(2, 0) = 2
gs(3, 0) = 6
gs(4, 0) = 24
gs(5, 0) = 120
gs(6, 0) = 720
gs(20, 0) = 2432902008176640000
gs(21, 0) = -4249290049419214848
gs(
C:>gs 1 0 1 2 3 4 5 6 13
gs(0, 1) = 1
gs(1, 1) = 0
gs(2, 1) = 1
gs(3, 1) = 2
gs(4, 1) = 9
gs(5, 1) = 44
gs(6, 1) = 265
gs(20, 1) = 895014631192902121
gs(21, 1) = 348563181341392924

(The outputs for n = 21 have overflowed the 64-bit word size.)


Related Discussions:- Write an assembly language program

Mlil-arithmetic instruction-microprocessor, MLIL: Unsigned Multiplication ...

MLIL: Unsigned Multiplication Byte or Word: This instruction multiplies an unsigned byte or word by the contents of the AL. The unsigned byte or word can be in any one of the gene

The alpha, The Alpha : The development of the Alpha chip start in the y...

The Alpha : The development of the Alpha chip start in the year 1988 The new chip used 64 bit technology, let users to pack  more  complexity  into  their  programs  than  exis

Boolean and comparison instructions, what will be the value of EAX after fo...

what will be the value of EAX after following instructions execute? mov bx, 0FFFFh and bx, 6Bh

Nible, calculate the number of one bits in bx and complement an equal numbe...

calculate the number of one bits in bx and complement an equal number of least significant bits in ax hint use the xor instruction

Pc bus and interrupt system-microprocessor, PC Bus and Interrupt System ...

PC Bus and Interrupt System The PC Bus utilized a bus controller, address latches, and data transceivers (bidirectional data buffers). 1) Bus controller : ( Intel 8288 Bus

Pin description of 8086-microprocessor,  Pin Description of 8086 The ...

 Pin Description of 8086 The microprocessor 8086 is a 16-bit CPU available in 3 clock rates, for example 5, 8 and 10 MHz, packaged in a40 pin CERDIP or plastic package. The 8

Arm assembly language code, You will need to upload your main.c and factori...

You will need to upload your main.c and factorial.s files and a .jpg photo of the output on your board using the Vista assignment upload features.  It must be submitted by the dead

Memory segmentation-microprocessor, Memory Segmentation : The  memory ...

Memory Segmentation : The  memory in an 8086/8088  based system is organized as segmented memory. In this scheme, the whole physically available memory can be divided into a n

Modes of 8255 a-microprocessor, The modes are determined by the contents of...

The modes are determined by the contents of the control register, whose format is given in Figure These modes are: Mode 0: If a group is in mode 0, it is divided into 2 sets.

Login system, a pseudo-code to add username and password combination up to ...

a pseudo-code to add username and password combination up to a limit of 10

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd