## Start of file stack2.a ## ## MIPSMARK 1.1 21/4/99 Copyright 1998 J. Waldron.
ID: 3679203 • Letter: #
Question
## Start of file stack2.a
##
## MIPSMARK 1.1 21/4/99 Copyright 1998 J. Waldron.
## All Rights Reserved. See the file README for
## a full copyright notice.
##
## Question:
## The program must sum a sequence of numbers
## stored on the stack. The word
## on the top of the stack tells you how
## many numbers are in the sequence.
## Do not include this first word in the sum.
##
## Do not rely on the existence on the "test"
## variable, or the code above the
## dashed line.
##
## Output format must be:
## "sum is = 23"
#################################################
# #
# text segment #
# #
#################################################
.text
.globl main
main: # execution starts here
la $t0,test # This code sets up the stack
lw $t1,($t0) # Do not alter
add $t0,$t0,4
loop: lw $t2,($t0)
sub $sp,$sp,4
sw $t2,($sp)
add $t0,$t0,4
add $t1,$t1,-1
bnez $t1,loop
la $t0,test
lw $t1,($t0)
sub $sp,$sp,4
sw $t1,($sp)
# Stack set up now....
# Any changes above this line will be discarded by
# mipsmark. Put your answer between dashed lines.
#-------------- start cut -----------------------
#-------------- end cut -----------------------
# Any changes below this line will be discarded by
# mipsmark. Put your answer between dashed lines.
#################################################
# #
# data segment #
# #
#################################################
.data
test: .word 4,6,7,8,2
ans: .asciiz "sum is = "
endl: .asciiz " "
##
## End of file stack2.a
Explanation / Answer
/*# Start of file changecase.c */
/* MIPSMARK 1.0 1/5/98 Copyright 1998 J. Waldron. */
/* Question:
write a c function sentenceCase, which takes one argument,
of type char* (pointer to a string) and changes the case
of all letters in the string, so that the first character
is capitalized (UPPERCASE) and all the remaining letters
are lower case.
Do not refer to the variable "teststr"
*/
/*# Output format must be: */
/*# "Look out for capslock!" */
#include <stdio.h> /* for printf in C programs */
#include <string.h>
char teststr[] = "look OUT For CAPSlOCK! ";
/* Any changes above this line will be discarded by
# mipsmark. Put your answer between dashed lines. */
/*-------------- start cut ----------------------- */
/* Student's Name: Account: */
void sentenceCase(char* s)
{
char* temp = s;
int len = strlen(s); //c string.
int counter = 0;
for (; counter < len; counter++, temp++)
{
unsigned char ucCharacter = *(unsigned char*)temp;
if (counter == 0)
{
if (ucCharacter >= 97 && ucCharacter <= 122)
{
*(unsigned char*)temp = ucCharacter - (1<<5);
}
}
else
{
if (ucCharacter >= 65 && ucCharacter <= 90)
{
*(unsigned char*)temp = ucCharacter + (1 << 5);
}
}
}
/* YOUR CODE GOES HERE */
}
/*-------------- end cut -----------------------
# Any changes below this line will be discarded by
# mipsmark. Put your answer between dashed lines.*/
int main()
{
/* --- uncomment this code to read your own test string */
/*
puts("Type your own sentence"); // NEVER use gets!
fgets(teststr, 24, stdin); // reads at most 23 chars, terminates with '' may include a newline
*/
sentenceCase(teststr); /* Calling student function */
puts(teststr); /* print result */
return 0;
}
/*# End of file changecase.c */
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.