In three segment code an array is defined as like for eg. take b=int a[i] and elements are of 4 bytes
so 3 segment code of above is
t1=&a \\ generates the address of array a where it stored according to datatype for eg. here it will generate address of 4 bytes etc.
t2 = 4 * i \\ tells that element in array are 4 bytes
t3=t1+t2 \\ defines the address of the element in array where that ith element is stored
so to retreive the value from that address we will use pointer that is
t4 = *t3 \\ extracts the value stored at address t3
b = t4
so this way we use arrays
In our above problem the 3 address codes are
s=n*n \\ as given in above code
i=2 \\ i variable is initialised with 2 in loop
l1: if( i > s) goto l2 \\ it is for loop condition above if it is false then program terminates and jumps to l2
t1 = &a \\ extracts the starting address of array a
t2= 8*i \\ as it is written that each element is of array is 8 bytes
t3 = t1+t2 \\ provides the address of the ith element
t4=*t3 \\ extract the ith element value
if(t4==TRUE) goto l4 \\ condition that if t4 that is ith element contains some value and is not empty that is if element is true or false if if conditions fails it will not continue add just increment loop and starts procedure again with incremented value of i
t11=count+1
count=t11
j=2*i \\ intialise the variable j
l2: if( j > n) goto l4 \\ if condition of fails go to first loop
t5=&a \\ address of array a
t6=8*j \\ 8 byte is the length of elements j
t7=t5+t6 \\ address of the element stored in array
t8=*t7 \\ extraction of value of element at t7 address
t8=FALSE \\ value of element set by user for next iteration
t9=j+i
j=t9
goto l2 // loop continue until j satisfies the condition
l4: t10=i+1
i=t10
goto l1
l2: \\ loop terminates here
Quadruples
| Operator | Argument1 | Argument2 | Result |
| * | n | n | s |
| = | 2 | i | |
| > | i | s | |
| & | a | t1 | |
| * | 8 | i | t2 |
| + | t2 | t1 | t3 |
| *,= | t3 | t4 | |
| == | t4 | TRUE | |
| + | count | 1 | t11 |
| = | t11 | count | |
| * | 2 | i | j |
| > | j | n | |
| & | a | t5 | |
| * | 8 | j | t6 |
| + | t5 | t6 | t7 |
| *,= | t7 | t8 | |
| = | FALSE | t8 | |
| + | j | 1 | t9 |
| + | j | 1 | t10 |
| = | t10 | i |
4A. Generate three address code for the following C segment: (consider array elements of 8 5M bytes), Draw the quadrupl...
1. What is the output of the following code segment? int array[] = { 8, 6, 9, 7, 6, 4, 4, 5, 8, 10 }; System.out.println( "Index Value" ); for ( int i = 0; i < array.length; i++ ) System.out.printf( "%d %d\n", i, array[ i ] ); 2. What is the output of the following code segment? char sentence[] = {'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u' }; String output = "The sentence...
Consider the following code. Assume that the array begins at memory address Ox200. What is printed by the following code. Assume sizeof(int) is 4 bytes and sizeof(char) is 1 byte. Do not include the Ox or leading zeros in your answer. Enter -1 if the answer is indeterminate, or -2 if the code generates a compile error, or -3 if the code generates a runtime error. #include <stdio.h> int main() { int a[] {1,2,3}; int *iptr a; printf("%p\n", iptr+1); return...
Consider the following code: *How many elements in the array A are * also in the array B? Assume B is sorted. */ 01: int overlap (int* A, int* B, int N) 02:{ 03: int count = 0; 04: for (int i = 0; i < N; ++i) 05: 06: int x A [i 07: 08 int pos lower_bound (B, B+N, x) - B; if (pos N && B [pos] 09: 10: 11: 12: == x ) { +count; 13:...
Consider the following C++ code segment: for (int i = 0; i <n; ++i) { for (int j = 0; j <m; ++j) if (i != j) cout << "0"; else cout << "1"; } } Which of the options below gives the correct output if the value of nis 2and the value of mis 3? 1. 100010 2. 011101 3. 100100 4. 010001
compiler
problems?thx
7, (10%) Consider the following three-address code. Please draw its control-flow graph a»10 if acb goto goto L3 v=0 goto L1 t1-t2+1 t3-BIti] a-t3 i=0 1.2 ?2: L3: ?1: i=i+1 if i<10 s=1 goto L4
Learn the example C program in Folio consisting of three files (a.c, a.h, main.c) and complete this exercise. You need to understand function, pointer and the selection sort algorithm. Write a C program that consists of three files mysort.h, mysort.c and myMain.c. Below is the mysort.h prototype #include <stdlib.h> #include <stdio.h> void generateNums(int *myarr, int len); void sortNums(int *myarr, int len); mysort.h must contain only the function declarations (prototypes) listed above generateNums function should generate len random integers in the...
Please, explain clearly each line of code with your answers. Question 1 Consider the following code snippet: int ctr = 0; int myarray[3]; for (int i = 0; i < 3; i++) { myarray[i] = ctr; ctr = ctr + i; } cout << myarray[2]; What is the output of the code snippet? Question 2 Consider the following code snippet: int cnt = 0; int numarray[2][3]; for (int i = 0; i < 3; i++) { for (int j =...
please use c++ language 1. Request three different integers from the console. a) Write a swap function that swaps two integer values. b) Write a sort function which accepts three integers as input then sorts them from largest to smallest using the swap function. c) Output the integers before and after sorting. Example 1 Output (input in bold italics) Enter three different integers: 3 2 4 3 2 4 4 3 2 Example 2 Output (input in bold italics) Enter...
Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate the number of test scores the user enters; have scores fall into a normal distribution for grades -Display all of the generated scores - no more than 10 per line -Calculate and display the average of all scores -Find and display the number of scores above the overall average (previous output) -Find and display the letter grade that corresponds to the average above (overall...
Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C - A consecutive group of memory chunks. D - None of the choices. Question 2 How many times is the body of the loop executed? int i=1; while(true) { cout << i; if(++i==5) break; } A - Forever B - 4 C - 5 D - 6 E - 0 Question 3 What is wrong with the following piece of...