CSE 30 -- Assignment 4 -- Nov 2


Grade distribution:

66 students handed in assignment 4.

assignment 4 as a whole: mean  67.74
                         stdev 28.8871

w/o late adjustment: mean  69.197
                     stdev 28.1975

Excluding all-zero scores:

assignment 4 as a whole: mean  67.74
                         stdev 28.8871

w/o late adjustment: mean  69.197
                     stdev 28.1975

Per-problem statistics:

Num  1:  mean  8.333333
         stdev 2.388948
Num  2:  mean  4.318182
         stdev 1.426578
Num  3:  mean  13.257576
         stdev 7.905331
Num  4:  mean  14.500000
         stdev 6.410810
Num  5:  mean  28.787879
         stdev 21.196423


Per-problem statistics, omitting zero grades:

Num  1:  mean  8.333333
         stdev 2.388948
Num  2:  mean  4.523810
         stdev 1.096273
Num  3:  mean  16.203704
         stdev 5.351980
Num  4:  mean  16.500000
         stdev 3.710423
Num  5:  mean  44.186047
         stdev 3.036643
Due Nov 5, 12:45pm

downloadable version

# CSE 30 F99.  Yee.  Nov 2.
#
# simple MIPS program for assignment 4.
#
# your job is to single-step through this program, note the expanded
# pseudo-instructions, learn to set breakpoints and read the register
# values at various points in the execution of this program.
#

# Assignment 4:
#
# 1) what does this program do?
#
# 2) where is bytebuf located in memory?  give the hexadecimal address
#
# 3) set breakpoints as indicated below.  run the program.  each time the
# program stops at the breakpoints, write down the contents of memory:
# mem[bytebuf] ... mem[bytebuf+2]
#
# 4) modify the program to use the equivalent MIPS assembly instruction
# sequence for the following C code:
#
# char bytebuf[] = "ff ";
# void byteout(char val)
# {
#  int nyb;
#  nyb = (val & 0xf0) >> 4;
#  if (nyb < 10) {
#   bytebuf[0] = '0' + nyb;
#  } else {
#   bytebuf[0] = 'a' + (nyb - 10);
#  }
#  nyb = val & 0xf;
#  if (nyb < 10) {
#   bytebuf[1] = '0' + nyb;
#  } else {
#   bytebuf[1] = 'a' + (nyb - 10);
#  }
#  print_string(bytebuf);
# }
#
# turn in this program along with the answers to the previous questions
# as two files tarred together.  the text answers should be in a file named
# answers.txt, and the program should be in a file named assn4.mips.
#

size=256
		.data
hello:		.asciiz	"Hello world\n"
buf:		.space	size
newline:	.asciiz	"\n"

# void main(void)
# uses $s0; code uses exit system call rather than returning to the
# runtime support code, but we pretend to be a "dumb" compiler and
# save $ra anyway
#
		.text
main:		subu	$sp,$sp,12
		sw	$fp,4($sp)
		addu	$fp,$sp,12
		sw	$ra,0($fp)
		sw	$s0,-4($fp)

		li	$v0,4		# print_string("Hello world\n")
		la	$a0,hello
		syscall

		li	$v0,8		# read_string(buf,size)
		la	$a0,buf
		li	$a1,size
		syscall

		la	$s0,buf		# for (p = buf; *p; p++) byteout(*p);
		b	loop_entry
loop:
		jal	byteout
loop_entry:
		lb	$a0,($s0)
		addu	$s0,1
		bne	$a0,0,loop

		li	$v0,4		# print_string("\n");
		la	$a0,newline
		syscall

		li	$v0,10		# exit()
		syscall

		lw	$s0,-4($fp)
		lw	$ra,0($fp)
		lw	$fp,-8($fp)
		addu	$sp,$sp,12
		jr	$ra

# void byteout(char val)
# prints ASCII value of character.
# 
# leaf subroutine, uses $a0 and $v0 for print_int syscall, $v1 for scratch
# no stack frame needed.
#
# algorithm: we overwrite the first two characters of bytebuf and print it.
# table-lookup is used to obtain the equivalent character for each hex digit.
#
		.data
bytebuf:	.asciiz	"ff "		# at what address is this located?
hextab:		.ascii	"0123456789abcdef"
		.text
byteout:	and	$v0,$a0,0xf0
		srl	$v0,$v0,4
		lb	$v0,hextab($v0)
		sb	$v0,bytebuf
		and	$v0,$a0,0xf	# set breakpoint here, after the sb *
		lb	$v0,hextab($v0)
		sb	$v0,bytebuf+1

		li	$v0,4		# and here *
		la	$a0,bytebuf
		syscall
		jr	$ra

[ search CSE | CSE home | bsy's home page | webster i/f | yahoo | hotbot | lycos | altavista | pgp key svr | spam | commerce ]
picture of bsy

bsy+cse30.f99@cs.ucsd.edu, last updated Tue Dec 14 19:50:01 PST 1999. Copyright 1999 Bennet Yee.
email bsy.


Don't make me hand over my privacy keys!