In: Computer Science
Translate the following C program to PEP/9 assembly language.
#include <stdio.h>
Int main (){
int number;
Scanf (“%d”, & number);
if (number % 2 ==0) {
printf (“Even\n”);
}
else {
printf(“Odd\n”);
}
Return 0;
}
Step(1)
The Pep/9 Computer Simulation (also known as Pep9) is a virtual machine that is used by professors of schools and colleges to explain and simplify the lowest level of computing.
The Pep/9 is a direct descendant of the Pep/6 virtual machine, the only major difference is that it has been expanded from 4KiB to 32KiB of system RAM. The machine code format remains the same.
Step(2)
The gcc provides a great feature to get all intermediate outputs from a source code while executing. To get the assembler output we can use the option ‘-S’ for the gcc. This option shows the output after compiling, but before sending to the assembler. The syntax of this command is like below.
gcc –S program.c
Step(3)
CODE-
BR main
number: .EQUATE int number ;local variable #2d
main :
SUBSP 2,i ;push #number
DECI number,s ;scanf("%d", &number) (get number)
LDWA number,s ; if (number %2 == 0) (check if number %2 is zero)
BRGE elseIf
STRO print1,d ;printf("Even\n")
BR endIf
elseif:
STRO print2 , d ;printf("Odd\n")
endIf:
ADDSP 2,i
STOP
print1 : .
.ASCII "Even\n\x00"
Print1:
.ASCII "Odd\n\x00"
.END
IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I
WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK
YOU!!!!!!!!----------