In the following code, the first printf() reached produces the output “14,” but the second printf() can cause a bus error or a segmentation fault. Why? main() { int *p; funct(p); printf("%d\n",*p); }
Q: Determine the output generated by the partial C code given. #include void main () { int…
A: Dear Student, In the beginning inside first for loop a value will be 0 and similarly b value will…
Q: Program sine_evalution_series implicit none Integer::n,m,k,i.j,f Real:: x,term,sum Read ",n,X Do…
A: Given code:
Q: Write a complete program in MARS MIPS assembly language that asks the user to enter an unsigned…
A: Let the input number be x 1) Get all even bits of x by doing bitwise and of x with 0xAAAAAAAA. The…
Q: Write a MIPS assembly program that converts a grade letter A, B, C, D or F to its decimal value.…
A: Algorithm: Input grade letter from the user If the grade letter is 'A' then Set the grade to 100…
Q: Implement the following high-level code segments. Assume the integer variables g ,h ,m ,and r are in…
A: The values of integer variables g, h, m and r are are stored in registered in the following manner:…
Q: Translate the following Java code to MIPS. Assume that the variable x is associated with $s0 and y…
A: public class MyClass { public static void main(String args[]) { int x=3,y;if (x < 7)y = 7…
Q: The strlen subroutine reads every character of the string from memory, It either counts the…
A: strlen: The strlen() function calculate the length of the string excluding the ending null…
Q: Write a C++ program to find the power fit y=Bx³ for the following data. Xk Yk 2.0 5.1 2.3 7.5 2.6…
A: According to the Question below the solution: Output:
Q: Write a MIPS program that asks the user to enter an unsigned number and read it. Then swap the bits…
A: MIPS means million instructions per second.
Q: 4. Write a C++ program that reads an integer X, then calculates and outputs the sum of the following…
A: Here is your code
Q: Translate with a three-address statement, the following expression: n = f((x+2), y) – 5
A: Three address code: t1= x+2 param t1 param y call f return t2 n= t2-5
Q: Write three address code, quadruple and triples for following expression : (a +b + c) - (a + b) * (b…
A: Given (a+b+c)-(a+b)*(b+c) Now Address code will be In this the given values will be stored in each…
Q: Write a MIPS assembly program that converts a grade letter A, B, C, D or F to its decimal value.…
A: There were no restriction stated hence made this way. Created a 2 version and both are working fine…
Q: Write a MIPS program (please show the whole code with comments) Given the following data definition…
A: Here is the answer with explanation:-
Q: i] Using a general register computer with three-address instructions. [ii] Using a general register…
A: [i] Using a general register computer with three-address instructions. SUB R1, A, B R1 ←…
Q: Write a code in Assembly language to check AL and do the following: IF AL is an odd value, put ones…
A: Code : Assume CS : CODE, DS: DATA DATA SECMENT DRC 1000H NUM DW " " DISPLAYE DB "EVEN NUMBER$"…
Q: Write a program in C++ to calculate the series (1) + (1+2) + (1+2+3) + (1+2+3+4) + ...+…
A: Please find the answer below :
Q: Write the MIPS assembly code which calculate the grades of student according to the criteria: When…
A: //Code with pseudo instruction-- process## step 1 : ask the user for marks ## step 2 : compare…
Q: Write a MIPS assembly language program to read an integer say n. Calculate and print the average of…
A: Given that Write a MIPS assembly language program to read an integer say n. Calculate and print…
Q: Write a mips code for the function that evaluates and prints the sum of the numbers between two…
A: .datamessage1: .asciiz "enter first number"message2: .asciiz "enter second number"message3:…
Q: Write a C++ program that computes the following summation. Sum = (x-1) 3 +…
A: Program plan: Declare the variables x, n, and sum Prompt for the value of x and n Execute the…
Q: Convert the following function in Python code into MIPS code. Note that 2 integers a and b are…
A: we will solve this question in step No. 2
Q: 8. Given the following if-else statement in java, write the implementation in MIPS using the…
A: Since, there are multiple questions posted, we will answer for the first question. If you want any…
Q: A programmer is asked to translate the following HLL code into MIPS Assembly language int isa() =…
A: code.asm .data isa: .word 10,20,30,-5,-15,40,50,-88,19,-33 hud: .asciiz "***" .text .globl bonus…
Q: Implement the following C code in MIPS assembly. The Fibonacci sequence is a series of numbers,…
A: ANSWER;-
Q: A- Write an assembly code to check if a number is falling within the range j...k (inclusive). Ask…
A: Code: .LC0: .string "Enter J-beginning of the range" .LC1: .string "%d" .LC2:…
Q: Write a function in MIPS assembly that copy the value of the 8th element of a word array to the 5th…
A: NOTE: we are assuming the word size of array is 4 byte. Code: fun: li $t0, 7 sll $t0 ,$t0 ,2 add…
Q: Write a C++ program to find the power fit y=BxM for the following data. Where M = (ID number % 3) +2…
A: Explanation: The following is a code in C++ programming language. #include <iostream>using…
Q: Write a C++ program that computes the following series: .2 x3 x4 x" - - ... 2! 3! 4! n!
A: Given: z= x- x^2/2! + x^3/ 3! - x^4/4! +....x^n/n! if the input is n=3 and x=2 z= 2.66
Q: Write a c++ program function that makes the base conversion. It takes two integers n and b as input…
A: Conversion of Decimal to Binary Algorithm Step 1: First divide the given number by 2 through the…
Q: Write a C++ program for the conversion of a decimal number to a binary, octal and hexadecimal…
A: PROGRAM CODE: #include <iostream>#include <cmath>#include <string>using…
Q: Write a MIPS procedure that takes as its three parameters the starting address of an integer array,…
A: // As you have not mentioned the language, I am writing the code in both java as well as in C. //In…
Q: Write a MIPS assembly code program that asks the user to enter an unsigned number and read it. Then…
A: MIPS: Million Instruction per second.
Q: Identify basic blocks and hence draw control flow graph for the following code. = read () ; b: read…
A: The question is to draw the CFG with respect to the given program.
Q: Write out how to solve the following code using any addressing mode for (3,3) GPR. a[] is address…
A: Answer: I have given answered in the handwritten format in brief explanation.
Q: Write a c++ program that takes 2 hex values and gives back the CRC Checksum. sample output: Enter…
A: A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital communication…
Q: explain this program bus1: mov ax,400 add amount, ax mov dx,0 mov bx,10 mov cx,0 l222: div bx push…
A: mov ax,400 ; move the value(amount) to the AX register add amount, ax ; add the content of…
Q: Write a program in MIPS Assembly language that first prompts the user for a temperature in Celsius.…
A: The solution is as follows
Q: - Write an assembly code to check if a number is falling within the range j...k (inclusive). Ask the…
A: Actually, ASM stands Assembly Language.
Q: Given the following code segment in C++, please write its corresponding 68K assembly code.
A: According to the question we need to write its corresponding 68K assembly code. int sum = 0; int c…
Q: This needs to be done in C Programming. A manufacturing plant has an alarm monitor program that…
A: Answer: code :
Q: Write a C program to implement the multiplication and division by 2 using the shift operators.…
A: #include<stdio.h> // Function for multiplication int multiply(int n, int m) { int ans = 0;…
Q: Write a C++ program that computes the following series: x2 x3 + 2! x4 Z = x -- - 3! 4! n!
A: Required: Required code with comments for explanation and screenshot of both code and output has…
Q: Write a program in C++ to swap two numbers
A: Algorithm Start Var num1, num2, temp Accept num1 Accept num2 temp=num1 num1=num2 num2=temp…
Q: A PL/I program has variables U, V, X, Y, 2 which are declared as follows: DCL U BIT(4) W CHAR(5) Y…
A: a
Q: Implement the following pseudocode in assembly language. Use short-circuit evaluationand assume that…
A: INCLUDE Irvine32.inc. data N DWORD 10A DWORD 9B DWORD 8 .code main proc mov eax, N mov ebx, A mov…
-
In the following code, the first printf() reached produces the output “14,” but the
second printf() can cause a bus error or a segmentation fault. Why?
main()
{
int *p;
funct(p);
printf("%d\n",*p);
}
funct(int *p2)
{
p2=(int *)malloc(4);
*p2=14;
printf("%d\n",*p2);
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
- Instruction: Explain the functions of each code per line to get the desired result. #include <iostream>using namespace std; void reversing(string& n){ int length =n.length(); int b = length-1; int i = 0; while(i<=b){ swap(n[i],n[b]); b= b-1; i= i+1; }} int main(){ int count = 0; string n = ""; cout<<"Enter strings: \t"; getline(cin,n); reversing(n); cout<<"String length: \t"<< n.length(); cout<<"\n"; cout<<n; return 0;}Write the following C code in RISCV without using any opcode and it should be able to run through the Cornell Computer Science interper. int x[100]; for(int i = 0; i < 10; i++) {x[i] = *i; }In C code This is what I have so far #include <stdio.h> int main () { unsigned int x = 0x76543210; char *c = (char*) &x; printf ("*c is: 0x%x\n", *c); if (*c == 0x10) { printf ("Architecture is little endian. \n"); } else { printf ("Architecture is big endian. \n"); } return 0; }
- The C programming language supports left-shift and right-shift operators. This Arduino sketch tests both shift operators: void setup () { Serial.begin (9600); 1 void loop (0 I Serial.println ("Test shift operations byte a = 0xl; Serial.println (a, BIN); a = a > 2; // right shift Serial.print.In (a, BIN); delay (10000); ") ; 6 10 11 12 13 The AVR instruction set supports five shift operations: logical shift left, logical shift right, arithmetic shift right, rotate left, rotate right. 1sl 1sr asr rol rorA c++ program that implements full subtractor using full adder for n bits.(Eg if n=4,the program should subtract two 4 bit numbers and show the output after subtraction as well as borrow)/*N = Number of disks */ T(N, Beg, Aux, End) Вegin if N = 1 then Print: Beg > End; Beg, Aux, End are the pegs What is this step is for? else Call T(N-1, Beg, End, Aux); Call T(1, Beg, Aux, End); Call T(N-1, Aux, Beg, End); endif Why we are using these steps? End
- Note: assembly language(8086 microprocessor) Write a program that takes a number N (2 digit decimal) as input. Then the user will enter that many numeric values ranging from 0 to 9 as input. Here the user may enter a negative number too. The program then finds a pair of values whose summation is closest to zero.Explanation: Here at first the user enters 10, which is a 2 digit decimal number. That means the user now has to enter 10 negative or positive digits ranging from 0 to 9. Then the program will calculate the sum of all possible pairs and find the pair which gives the minimum sum. Here from the given example, we see that the sum of -2 and -4 which is -6 is the least sum.Input:10 -2, 3, 7, 4, -4, 7, -8, 0, 9, 9 Output: Pair of values which has the smallest sum = -4, -2Instruction: Explain the function of the program line by line thoroughly.Program: #include <iostream> using namespace std; //Swap functionvoid swap(int *xp, int *yp){ int temp = *xp; *xp = *yp; *yp = temp;} void selectionSort(int arr[], int n){ int i, j, min_idx; // One by one move boundary of // unsorted subarray for (i = 0; i < n-1; i++) { // Find the minimum element in // unsorted array min_idx = i; for (j = i+1; j < n; j++) if (arr[j] < arr[min_idx]) min_idx = j; // Swap the found minimum element // with the first element if(min_idx!=i) swap(&arr[min_idx], &arr[i]); }} //Function to print an arrayvoid printArray(int arr[], int size){ int i; for (i=0; i < size; i++) cout << arr[i] << " "; cout << endl;} int main(){ int x, n; cout << "Enter number of integers: "; cin >>n; int *arr = new int(n); for (int i = 0; i < n; i++) { cout << " Enter Integer No. " << (i + 1) << ": ";…2. Write a recurrence relation describing the worst case running time of each of the following algorithms and determine the asymptotic complexity of the function defined by the recurrence relation. Justify your solution. You may not use the Master Theorem as justification of your answer. Simplify and express your answer as (nk) or (nk log₂ n) whenever possible. If the algorithm is exponential just give exponential lower bounds. a) function func(A,n) if n ≤ 5 then return A(1) else for i=1 to n for j = i to n-1 A(j) A(j) + A(i) + 3 /* endfor */ /* endfor */ wwwwwwwwww y ← func(A, n-6) return (y)
- State whether the following are valid identifiers (function or variable name) and if so, whether they’re mnemonic names that convey some idea of the function’s purpose. If they are invalid names, state why. (20pts) Power Density m1234 newamp 1234 abcd total tangent absval computed b34a 34ab volts$ a2B3 while minVal sine $sine cosine speed- netdistance sum return stackit is said that it should use POINTER ARITHMETIC SOLUTIONS ONLYUsing the following description, please replace the return line in C code; /* * addOK: determine if x+y succeeds without overflow * Examples: * addOK(0x40000000,0x20000000) = 1 * addOK(0x40000000,0x40000000) = 0 * addOK(0x55555555,0x2AAAAAAA) = 1 * addOK(0x55555555,0x2AAAAAAB) = 0 * addOK(0x80000000,0x40000000) = 1 * addOK(0x80000000,0x80000000) = 0 * Legal ops: ! ~ & ^ | + << >> * Max ops: 20 * */ int addOK(int x, int y) { return 2 } You cannot: 1. Use any control constructs such as if, do, while, for, switch, etc. 2. Define or use any macros. 3. Define any additional functions in this file. 4. Call any functions. 5. Use any other operations, such as &&, ||, -, or ?:, not listed in the the "Legal ops" list for the function. 6. Use any form of casting. 7. Use any data type other than int.