You are given the task of writing a procedure int_size_is_32() that yields 1 when run on a machine for which an into is 32 bits and yields 0 otherwise. You are not allowed to use the size of operator. Here is a first attempt:
When compiled and run on a 32-bit SUN SPARC, however, this procedure returns 0. The following compiler message gives us an indication of the problem:
Warning: left shift count >= width of type
- A. In what way does our code fail to comply with the C standard?
- B. Modify the code to run properly on any machine for which data type int is at least 32 bits.
- C. Modify the code to run properly on any machine for which data type int is at least 16 bits.
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Additional Engineering Textbook Solutions
Modern Database Management (12th Edition)
Introduction to Programming Using Visual Basic (10th Edition)
Database Concepts (8th Edition)
Starting Out with Java: From Control Structures through Objects (6th Edition)
Starting out with Visual C# (4th Edition)
Database Concepts (7th Edition)
- Implement nibble_swap() function. Take in 4 byte integer and returns integer with swapped nibbles in first two bytes. Use a 3 bit register. The template below is for your reference. The code in the Assembly code portion needs to be completed in Assembly x86-64 #include extern "C" int nibble_swap(int var); int main(int avgc, char** avgs) { int v = nibble_swap(0xCAFEBABA); //answer: 0xACEFABAB printf("Swapped Variable is : 0%X \n", v); return 0; } ----------------Assembly Code --------------------------- ;yasm -f elf64 var.asm section .text global start : ;put ur code here retarrow_forwardPlease help with the following in regards to Nand2Tetris, and hack code, so hack assembly and hack vm. There can be more that one answer to a question if so please explain why. 1d. Given a function called foo() that calls another external function bar() which in turn calls a second function called additup(). Indicate the VM line of code indicating the location in the program that control should be return to: a.@Foo.$bar. b. @Foo$bar$additup.ret.1 c. @Foo.bar.additup.ret.1 d. @Foo$bar$additup&return e. @Foo return,bar return.additup 1e. The return value of a function when it is completed is stored, in: a. calling Frame Arg[?] b. calling Frame LCL c. calling Frame SP d. working Frame Arg[?] e. working Frame LCL f. working Frame SP g. none of the above 1f. Every boolean expression of N inputs and one output can be implemented Circle the letter for ALL that apply. a. using a combination of D flip-flops, multiplexors and registers. b. by connecting the output directly to all…arrow_forwardWrite a MIPS program that will handle calculating minifloat addition for two numbers using the rules discussed in class and storing each of the parts as a binary integer. To do this, each ‘minifloat’ number will need to be represented (I suggest hard coded) as one register for the sign, one for the exponent part, one for the ‘significand’ (which you then convert to the fraction part). Hard coding means here that you don’t need to read in the 6 parts as user input, just have something like li $s0, 0 li $s1, 12 li $s2, 5 which is equivalent to a minifloat of 0 1101 101 = 1.101 * 2^(12-7) = 1.101*2^5 This means your program will be work with at least 6 registers as variables. For testing, show that your program can correctly calculate the Lab 5 X+Y and A+B and then one other example of your choosing. Don’t worry about special cases of 0 0000 000 or 1 1111 111 or similar, but your program should detect overflow. This will involve a lot of (in your head) jumping back and forth between…arrow_forward
- Write programs that will accomplish the desired tasks listed below, using as few lines of code as possible e) Divide the data in RAM location 3EH by the number 12H ; put the quotient in R4 and the remainderin R5.f) Divide the data in RAM location 15H by the data in RAM location 16H ; put the quotient inexternal RAM location 7CH and the remainder in in external RAM location 7DH.g) Double the number in register R2, and put the result in register R3 (high byte) and R4 (low byte).Use logic operations.h) OR the contents of ports 1 and 2 ; put the result in external RAM location 0100Hi) Set Port 0, bits 1, 3, 5 and 7 to one, set the rest to zero.j) Clear bit 3 of RAM location 22H without affecting any other bit.k) Invert the data on the port 0 pins and write the data to port 1.arrow_forwardYou must complete this in Python and the programs should not take any command-line arguments. You also need to make sure your programs will compile and run in at least a Linux environment. In this problem, you must implement a tokenizer for the Assembly instruction format: an operation type (e.g. SUBI) followed by a comma-separated list of parameters (e.g. R0, R1, 6). If a line has an invalid syntax, it should be skipped in the output. You do not need to check whether the operations and arguments are valid Assembly instructions: you just need to separate them into tokens. Input Format The input to the program will consist of some number of lines. Each line is of the following form: "op arg1, arg2, ..., argn". Your program should terminate upon receiving a blank line or EOF. Constraints There are no specific constraints on the length or number of lines. They will be in a reasonable limit, as demonstrated by the included test cases, all of which are public. This is not a…arrow_forwardThe following code attempts to find all the prime numbers between 2 and n. 1. When compiled, why is the following error produced?: Undefined symbols for architecture x86_64: "_main", referenced from: implicit entry/start for main executableld: symbol(s) not found for architecture x86_64 2. Fix code so that it compiles with no errors #include <stdio.h> #include <stdlib.h> #include <math.h> #include <sys/time.h> //helper function: computes wall clock time double getTime(struct timeval ts, struct timeval te){ doubletime = te.tv_sec - ts.tv_sec + (te.tv_usec - ts.tv_usec)/1.e6; returntime; } //helper function: allocates an array of a specified length and returns a pointer int * allocateArray(int len) { int * result = malloc(len * sizeof(int)); returnresult; } //helper function: prints out elements of array separated by spaces void printArray(int * arr, int len) { inti; for (i = 0; i < len; i++) { printf("%d ", arr[i]); } printf("\n"); } //helper…arrow_forward
- Modify the following program in lc-3 to get the input(numbers) from the keyboard and print the result to console. .ORIG x3000Loop LD R0, number1 ; load number1 into R0LDR R1, number2 ; load number2 into R1ST R2, SaveR2 ; save register R2LD R5, goSUB ; load address of SUB into R4JSRR R5 ; go to subroutine whose address in R5STR R3, result ; store resultLD R2, SaveR2 ; restore old value R2HALTnumber1 .FILL #10number2 .FILL # -8goSUB .FILL SUB ; initialize goSUB to address of SUBSaveR2 .BLKW #1; reserve space SaveR2 and SaveR3result .BLKW #1SUB NOT R1, R1ADD R2, R1, #1ADD R3, R0, R2RET.ENDarrow_forwardWrite a MIPS procedure that takes as its three parameters the address of a zero-terminated string, a character c, and an integer n, and returns the number of distinct runs of consecutive instances of c in the string that are of length at least n. Also, write a simple main program to test your procedure. Your main program should input a string from the user (you may assume that the string has at most 20 characters), input the character and the integer, invoke your procedure, output the return value, and then terminate. For example, given the inputs “bbabbbbagbgbb”, “b”, and 2, the output should be 3. Your code must use the “standard” conventions covered in class for passing parameters and returning results. code in mipsarrow_forwardI need help with the following assembly code and get it to work properly on the Arduino uno: int __attribute__ ((noinline)) greaterOrEqual(int a, int b){int result;// if (a >= b){// result = 1;// }else{// result = 0;// }asm volatile("cp %A2, %A1 \n\t" //b - a"cpc %B2, %B1 \n\t" // the high bytes"brge zero%= \n\t""ldi %A0, 1 \n\t" //pass back true"rjmp over%= \n\t" //over the else"zero%=: ldi %A0, 1 \n\t""over%=: ldi %B0, 0 \n\t": "=r"(result) //ouput list: "d" (a), "d" (b) //input list:); return result;}arrow_forward
- Write a code in sim8085 for the following problem: The pressure of two boilers is monitored and controlled by a microcomputer works based on microprocessor programming. A set of 6 readings of first boiler, recorded by six pressure sensors, which are stored in the memory location starting from 2050H. A corresponding set of 6 reading from the second boiler is stored at the memory location starting from 2060H. Each reading from the first set is expected to be higher than the corresponding position in the second set of readings. Write an 8085 sequence to check whether the first set of reading is higher than the second one or not. If all the readings of first set is higher than the second set, store 00 in the ‘D’ register. If any one of the readings is lower than the corresponding reading of second set, stop the process and store FF in the register ‘D’. Data (H): First set: 78, 89, 6A, 80, 90, 85 Second Set:71, 78, 65, 89, 56, 75arrow_forwardWrite a parallel program using MPI (and not OpeMP) to accomplish the same as the following serial program. For the following serial program the user enters a line and the program outputs the number of occurrences of each printable character (but not the space or tab character). For the parallel program if we have p processes we should divide the line into p segments and let each process counts the characters of its segment#include<stdio.h>#include<stdlib.h>#include <string.h>#define ASCIIs 127 //ASCII characters from 0 to 127define atmost 1000char letters[atmost + 1]; //Extra location for the string terminator '\0'int total_count[ASCIIs];void find(int count[],int start, int end);int main(){ int i, processes, n, start, end; int count[ASCIIs], my_rank, segment, p;printf("Enter a line not larger than 1000 characters.\n");fgets(letters, atmost,stdin);printf("How many segments?: ");scanf("%d", &processes);//To make the length of the divisible by…arrow_forwardI cant debug the code sucessfully there was a problem in the div ebx line please change the code to make it work, Im not sure what to do anymore the goal is to make a GCD greatest common divisor algorithm please rewrite it in following assembly coding INCLUDE Irvine32.inc .datamsg1 BYTE "Enter two integers: ",0msg2 BYTE "The GCD is ",0numberOne SDWORD ?numberTwo SDWORD ?remainder DWORD ? .codemain PROCcall Clrscrmov ecx,5 L1:call Integerscall GCDcall Displayloop L1 exitmain ENDP Integers PROCmov edx, OFFSET msg1call WriteString call readIntmov numberOne, eax call readIntmov numberTwo, eax call Crlfret Integers ENDP GCD PROCmov eax,numberOnemov ebx,eaxsar ebx,31add eax, ebxxor eax, ebxmov numberOne,eax mov eax,numberTwomov ebx,31add eax, ebx mov numberTwo,eax L2:mov eax,numberOnemov edx,0mov ebx,numberTwodiv ebx mov edi,numberTwomov numberOne,edi mov edi,remaindermov numberTwo,edi cmp numberTwo,0 jb L3loop L2 L3:mov eax,numberOneret GCD ENDP Display PROCcall WriteStringcall…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education