Using Microsoft Visual Studio.
1) Complete the following C++ program by adding more line of code for 8-bit signed array, 16-bit unsigned array, 16-bit signed array, 32-bit signed array and 32-bit signed array.
2) Fill in all the blanks in Table 1 using your completed code, following the hints provided within the table.
3) Fill in all the blanks in Table 2 using your completed code, following the hints provided within the table.
C++ Program
#include <stdio.h>
#include <iostream>
int main()
{
unsigned char uc8_arr[3] = { 0x80, 0x40, 0xFF };
unsigned char uc0, uc1, uc2;
unsigned char *ucPtr0, *ucPtr1, *ucPtr2;
signed char sc8_arr[3];
signed char *scPtr0, *scPtr1, *scPtr2;
short sh16_arr[3];
short *svPtr0, *svPtr1, *svPtr2;
int i32_arr[3] = {0x80, -660, 6600000};
int *ivPtr0, *ivPtr1, *ivPtr2;
ucPtr0 = &uc8_arr[0];
ucPtr1 = &uc8_arr[1];
ucPtr2 = &uc8_arr[2];
_asm
{
mov EAX, ucPtr0;
mov BL, [EAX];
mov uc0, BL;
mov EAX, ucPtr1;
mov CL, [EAX];
mov uc1, CL;
mov EAX, ucPtr2;
mov CL, [EAX];
mov uc2, CL;
}
printf("------------------------8-bit unsigned array--------------------------\n");
printf("The first element in the array in hex is 0x%x, in decimal is %u, %u\n", uc8_arr[0], uc8_arr[0], uc0);
printf("The address for memory at the first element in the array is %x H \n", ucPtr0);
printf("---\n");
printf("The second element in the array in hex is 0x%x, in decimal is %u, %u\n", uc8_arr[1], uc8_arr[1], uc1);
printf("The address for memory at the second element in the array is %x H \n", ucPtr1);
printf("--- \n");
printf("The third element in the array in hex is 0x%x, in decimal is %u, %u\n", uc8_arr[2], uc8_arr[2], uc2);
printf("The address for memory at the third element in the array is %x H\n", ucPtr2);
printf("----\n");
}
Table 1.
DATA TYPE |
VARIABLE NAME |
HEX |
DECIMAL |
ADDRESS |
signed char (array with 3 elements) |
sc8_arr[0] |
0x80 |
||
signed char (array with 3 elements) |
sc8_arr[1] |
|||
signed char (array with 3 elements) |
sc8_arr[2] |
0xFF |
-1 |
|
unsigned char (array with 3 elements) |
uc8_arr[0] |
0x80 |
||
unsigned char (array with 3 elements) |
uc8_arr[1] |
0x40 |
||
unsigned char (array with 3 elements) |
uc8_arr[2] |
0xFF |
255 |
|
short (signed array with 3 elements) |
sh16_arr[0] |
0x8000 |
||
short (signed array with 3 elements) |
sh16_arr[1] |
400 |
||
short (signed array with 3 elements) |
sh16_arr[2] |
-400 |
||
short (unsigned array with 3 elements) |
||||
short (unsigned array with 3 elements) |
||||
short (unsigned array with 3 elements) |
||||
int (signed array with 3 elements) |
i32_arr[0] |
0x80000000 |
||
int (signed array with 3 elements) |
i32_arr[1] |
-330 |
||
int (signed array with 3 elements) |
i32_arr[2] |
3300000 |
||
int (unsigned array with 3 elements) |
||||
int (unsigned array with 3 elements) |
||||
int (unsigned array with 3 elements) |
TABLE 2
Content in memory (the number of bits, the value in hex, the value in decimal |
ADDRESS FOR MEMORY IN HEX |
Identify the number of bytes used for each type of variable |
(8 bits unsigned) (0x80) (128) |
18fc00 H |
|
(8 bits unsigned) (0x80) (64) |
18fc01 H |
|
(8 bits unsigned) (0x80) (256) |
18fc02 H |
|
(32 bits signed) (0x8000 0000) (? decimal) |
18fbdc (real address) |
4 bytes, need 4 addresses |
(18fbdd H) |
||
(18fbde H) |
||
(18fbdf H) |
||
(32 bits signed) (? hexadecimal) (-6600000) |
(18fbe0 H) |
|
Using Microsoft Visual Studio. 1) Complete the following C++ program by adding more line of code...
Write a program that allows the user to enter an unsigned integer (the maximum value of an unsigned 4-byte int is 232 = 4,294,967,296) and reverses its format (from little to big endian, or vice versa). Print out the user-entered number in hexadecimal and binary, reverse the endianness, and print the reverse in hexadecimal and binary. Integers in most machine architectures are represented in little endian format: the least significant byte is stored in the smallest address; for instance, the...
using visual studio 2) For each of the following, write C++ statements that perform the specified task.. (Ref: classwork named pointer2) a) Declare a built-in array of type unsigned int called values with five elements, and initialize the elements to the even integers from 2 to 10. b) Declare a pointer vPtr that points to a variable of type unsigned int. c) Write two separate statements that assign the starting address of array values to pointer variable vPtr. d) Use...
C PROGRAM When you print out the old and new bitsets, which are of type unsigned char, please use the %p control character in the printff statement rather than %x or %d or %c. The compiler will complain, but we don't always listen to them anyway. The difference is it will print the bitset out in hex with a preceeding %0x. unsigned char bitset = 0x14 ; printf("Bitsrt is %p\n", bitset) ; results in Bitset is 0x14, which is what...
The following problem concerns the following, low-quality code: void foo(int x) { int a[3]; char buf[1]; a[1] = x; a[2] = 0xA0B1C2D3; gets(buf); printf("a[0] = 0x%x, a[2] = 0x%x, buf = %s\n", a[0], a[2], buf); } In a program containing this code, procedure foo has the following disassembled form on an x86/64 machine: 000000000040057d <foo>: 40057d: push %rbp 40057e: mov %rsp,%rbp 400581: sub $0x30,%rsp 400585: mov %edi,-0x24(%rbp) 400588: mov -0x24(%rbp),%eax 40058b: mov %eax,-0xc(%rbp) 40058e: movl $0xa0b1c2d3,-0x8(%rbp) 400595: lea -0x11(%rbp),%rax 400599:...
devmem2.c #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <errno.h> #include <signal.h> #include <fcntl.h> #include <ctype.h> #include <termios.h> #include <sys/types.h> #include <sys/mman.h> #define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", \ __LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0) #define MAP_SIZE 4096UL #define MAP_MASK (MAP_SIZE - 1) int main(int argc, char **argv) { int fd; void *map_base = NULL, *virt_addr = NULL; unsigned long read_result, writeval; off_t target; int access_type = 'w'; if(argc...
C PROGRAM The following is code prints the current activation record number, the memory address of the current array, followed by the estimated size of the current activation record as a distance between the current array address and the array address from the previous activation record. I need it to run until a segmentation fault occurs and also it must print the estimated size of the runtime stack as a product of the size of current activation record and the...
In this exercise we “reverse-engineer” some code to try to determine how the heap in a C program is managed. Consider the following C program (compiled as an executable called memory): #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { int chunk_sizes[4]; if ((argc != 2) || (sscanf(argv[1], "%d,%d,%d,%d", &chunk_sizes[0], &chunk_sizes[1], &chunk_sizes[2], &chunk_sizes[3]) != 4) || (chunk_sizes[0] < 0) || (chunk_sizes[1] < 0) || (chunk_sizes[2] < 0) || (chunk_sizes[3] < 0) ) { fprintf(stderr,"Usage: %s a,b,c,d\n", argv[0]); fprintf(stderr," where...
***The following is to be written in C:**** ****The following is the sizeof.c program that needs to be modified:**** ****Section B11 the question asks to refer to:**** Modify the sizeof.c program (in the sizeof folder on github) and show the data range (min and max) in addition to the size of the data types in a nice table (print one line for each data type). Refer to section B11 in your textbook (page 257) for getting min and max values...
Implement a rabin_hash method to make the following code work: int rabin_karp_batchmatch(int bsz, /* size of bitmap (in bits) to be used */ int k, /* chunk length to be matched */ const char *qs, /* query docoument (X)*/ int m, /* query document length */ const char *ts, /* to-be-matched document (Y) */ int n /* to-be-matched document length*/) { /*if the to-be-matched document is less than k length, return false*/ if (n < k) return 0; /*start our...
Please write below code in C++ using Visual Studio. Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) • Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 • Hint: Use vectors and vector functions to store the set of items 2. Get the number of items in the...