In: Computer Science
Computer Science (C and Assembly Languages)
• Assume there are two 32-bit variables in RAM memory called In and Out. Write C code that sets Out equal to In plus 2.
• Assume there are two 32-bit variables in RAM memory called In and Out. Write assembly code that sets Out equal to In plus 2.
• What are the three stack rules?
• Assume B1 is a 32-bit unsigned global variable. We wish to write code that decrements B1 with the exception that it will not decrement if B1 is already 0. Draw a flowchart of the process. Write the code in both C and assembly.
• Assume G1 is a 32-bit unsigned global
variable. We wish to write code that increments G1 if G1 is less
than 20. Draw a flowchart of the process. Write the code in both C
and assembly.
• Develop the pseudocode and the flowchart for a program that finds the sum of 5 numbers.
• Comment each line of the ARM Assembly
language to explain what the code does. [4 pts]
start
MOV r0, #15
MOV r1, #8
ADD r0, r0, r1
MOV r4, #0x300
• Comment each line of the C language
to explain what the code does. [4 pts]
#include <stdio.h>
int main()
{
int number;
printf("Enter an integer: ");
scanf("%d", &number);
if (number < 0)
{
printf("You entered %d.\n", number);
}
printf("The if statement is easy.");
return 0;
}
**********************************************************************************************************************************************
#include <stdio.h>
int main()
{
int number; //initilalizing variable number
printf("Enter an integer: "); //display message enter a
number
scanf("%d", &number); //inputs number
if (number < 0) //check whether value in variable number less
than 0
{
printf("You entered %d.\n", number); // if true enters into this
code block and prints the message in printf
}
printf("The if statement is easy."); // if false enters into this code block and prints the message in printf
return 0; //returns success
}
***********************************************************************************************************************************************
MOV r0, #15 //register r0 is loaded with value #15
MOV r1, #8 ///register r1 is loaded with value #8
ADD r0, r0, r1 //add values in r0 and r1 and store it in r0
MOV r4, #0x300 //register r4 is loaded with value #0x300