Question

IN MIPS ASSEMBLY Macro File: Create macros to print an int, print a char, print a...

IN MIPS ASSEMBLY

Macro File: Create macros to print an int, print a char, print a string, get a string from the user, open file, close file, read file, and allocate heap memory. You can use more macros than these if you like.

Main Program File:

  1. Allocate 1024 bytes of dynamic memory and save the pointer to the area.
  2. The main program is a loop in which you ask the user for a filename. If they enter nothing for the filename, exit the program. Otherwise:
    1. Open the file for reading. If the file does not exist, print an error message and terminate the program.
    2. Read the file into an input buffer space of 1024 bytes.
    3. Close the file.
    4. Invoke the print string macro to output the original data to the console.
    5. Call the compression function. Save the size of the compressed data in memory.
    6. Call a function to print the compressed data.
    7. Call the uncompress function, which uncompresses to the console.
    8. Print the number of bytes in the original and compressed data.
  3. The compression function implements the RLE algorithm above and stores the compressed data in the heap. Before the function call, set $a0 to the address of the input buffer, set $a1 to the address of the compression buffer, set $a2 to the size of the original file. The function should “return” the size of the compressed data in $v0.
  4. The uncompress function will repeat characters as indicated in the compressed file. For example, if the compressed file is ‘A2B3C1’ it will print
  5. ‘AABBBC’. Note that this is different from the print string macro which just uses a syscall to print a string.

Homework Answers

Answer #1

#include<sys/types.h>
#includ<sys/stat.h>
#include <fcntl.h>  
int open (const char* Path, int flags [, int mode ]);
extern int errno;

int main()

{

int fd = open("foo.txt", O_RDONLY | O_CREAT);

printf("fd = %d/n", fd);

if (fd ==-1)

{

printf("Error Number % d\n", errno);

perror("Program");

}

return 0;

}

int main()

{

int fd1 = open("foo.txt", O_RDONLY);

if (fd1 < 0)

{

perror("c1");

exit(1);

}

printf("opened the fd = % d\n", fd1);

if (close(fd1) < 0)

{

perror("c1");

exit(1);

}

printf("closed the fd.\n");

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Implement and demonstrate a disk-based buffer pool class based on the LRU buffer pool replacement strategy....
Implement and demonstrate a disk-based buffer pool class based on the LRU buffer pool replacement strategy. Disk blocks are numbered consecutively from the beginning of the file with the first block numbered as 0. Assume that blocks are 4096 bytes in size. Use the supplied C++ files to implement your LRU Buffer Pool based on the instructions below. • Implement a BufferBlock class using the supplied BufferBlockADT.h o Your Buffer Block must inherit BufferBlockADT or you will not get credit...
In which order the following ‘arguments’ of the foo() function will be put on the stack...
In which order the following ‘arguments’ of the foo() function will be put on the stack (the left-most variable has the highest memory address and the right-most variable has the lowest memory address)? void foo(int d, int s, string x, int e) d, s, x, e. e, x, s, d. x, d, s, e. d, s, e, x. To execute an external command from inside a program, either of the ‘system()’ or ‘execve()’ functions can be used. Select ALL of...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
Create a header file (lastname_employeerec.h) that defines an employee data structure (sEMPLOYEE) that can be linked...
Create a header file (lastname_employeerec.h) that defines an employee data structure (sEMPLOYEE) that can be linked onto a linked list. The data structure should have the following fields: a. First Name (firstName) b. Last Name (lastName) c. Employee ID (id) d. Start Year (startYear) e. Starting Salary (startSalary) f. Current Salary (currentSalary) g. next Create a library of functions that operate on this data structure. The source code for the functions should be in lastname_employeerec.c and the function prototypes should...
In MPLAB XIDE create a program using assembly to produce three different LED combinations using 4...
In MPLAB XIDE create a program using assembly to produce three different LED combinations using 4 LED lights and 4 switches that correspond to each LED. There will be 4 inputs and 4 outputs. The program includes three levels (the three LED combinations). Each level will be a random combination (i.e. red, blue, green, orange). The player will then repeat the combinations as accurately as possible. If the player repeats the led sequence correctly, the code will branch to the...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 565 Error 2 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 761 I need this code to COMPILE and RUN, but I cannot get rid of this error. Please Help!! #include #include #include #include using namespace std; enum contactGroupType {// used in extPersonType FAMILY, FRIEND, BUSINESS, UNFILLED }; class addressType { private:...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the following subsections can all go in one big file called pointerpractice.cpp. 1.1     Basics Write a function, int square 1(int∗ p), that takes a pointer to an int and returns the square of the int that it points to. Write a function, void square 2(int∗ p), that takes a pointer to an int and replaces that int (the one pointed to by p) with its...