CS 216, Lab #5

Submit within a week of the lab date

x2go troubles?, such as tab key not working, or frozen window

Bit Manipulation

  1. logic7.a   - Boolean operations.
    Get the file, design your code, and type it in before the lab period.
    The problem is to determine what the rightmost bit in a word is, and then make the next 3 bits (going "left") the same.
    ## Question:
    ## "number" is a word.
    ## If bit 0 is set then set bits 1, 2 
    ## and 3 and print out the result.
    ## If bit 0 is cleared then clear bits 1, 2 
    ## and 3 and print out the result.
    ##
    #/*# Output format must be:             */
    #/*# "result is = 1088"         */
    
    
    Note that bits are numbered from right to left, the least significant bit is bit 0
    "set" means 1   and "clear" means 0.

  2. Write and compile a C program to modify a string (next week, bits.a -- you will do something similar in assembly language):

changecase.c -- change case of letters in a string.

A sentence normally starts with the first letter a capital (upper case), and then the remaining letters are small (lower case) -- just like this sentence.

  bUt sUppOsing YoU hAVE ONe LIKE thIS, PLEASE FIX it.

There will be a main program that calls a function named sentenceCase. It will be passed a string (pointer to an array of characters). You will fix up that string please. The main program will then print the result.
(Ignore the possibility of a proper name, like Frodo or Los Gatos)

Bitwise operators in C - Please use

	&  AND
| Inclusive OR
^ Exclusive OR (XOR)
~ NOT (note use for AND mask, flipping all bits)
See example bitwise.c of using all these to change around case bits.
The way you declare a function with arguments, in this case, is:
	void sentenceCase(char* s) { /* body of function */ }
Once it works for the test case, test it with mipsmark and submit with submit cs216.

Instructions:

May I remind you that ALL programs MUST be well commented!!!!

Follow the instructions for Lab 2. You must test your code using mipsmark, be sure your name is included as a comment, and submit a copy of the file using submit cs216.

For both programs, Check with mipsmark and Submit with submit cs216. (mipsmark will also check C programming questions.)
mipsmark logic6.a
submit cs216 logic6.a

mipsmark changecase.c
submit cs216 changecase.c

mipsmark also includes the line
#include <stdio.h> at the top of the test file. (Above the cut line).
If you have trouble with mipsmark, check the validity of your calculations.
Then see common reasons mipsmark may fail.


To compile and run a C program

compile with gcc
gcc changecase.c
there will be either syntax errors, or
The executable file a.out
Run it with the command
./a.out

A classic C tutorial

Only note that the syntax for declaring argument types for functions is archaic.