Programming Programming Programming Programming Programming Programming EEL 3801
ID: 3881607 • Letter: P
Question
Programming
Programming
Programming
Programming
Programming
Programming
EEL 3801: Computer Organization, Spring 18.
Due Date (2/8/2018)
Literature
• Computer Organization and Design - The Hardware / Software Interface, David A. Patterson
& John L. Hennessy, Morgan Kaufmann, 5th Edition.
• Lectures’ handouts.
Software
• MARS, MIPS Assembly and Runtime Simulator
http://courses.missouristate.edu/KenVollmar/MARS
• PCSpim, MIPS-32 simulator
http://www.cs.wisc.edu/~larus/spim.html
Project Description
A. Write a MIPS-32 assembly language program that enables the user to enter four integer
numbers using the keyboard, your program should add them and writes their sum to the console
preceded by an appropriate message. Simulate your program using MARS or PCSpim to test its
operation using the following sets of integers: (2, 5, 23, 15), (16, -55, 100, -25), (22, -55, 5, 6),
and (0, 23, -13, -10).
B. Write a MIPS-32 assembly language program that prompts the user to enter his/her name. The
program should convert the entered name to upper case letters and writes it to the console
preceded by the output message “your name in capital letters is:”. Simulate your program using
MARS or PCSpim to test it.
Deliverables
Explanation / Answer
Answer 1: MIPS Program for adding 4 numbers
====================================
.data
prompt: .asciiz "Enter a number: "
msg: .asciiz "The sum of the numbers is "
.text
li $t0, 0 #counter intialized to 0
li $t1, 0 #sum initialized to 0
loop:
beq $t0, 4, end_loop #if counter more than 4 , we are done
li $v0, 4
la $a0, prompt
syscall
#read int and store in $t2
li $v0, 5
syscall
move $t2, $v0
add $t1, $t1, $t2 #add the number to sum
#increment counter
add $t0, $t0, 1
b loop
end_loop:
li $v0, 4
la $a0, msg
syscall
li $v0, 1
move $a0, $t1
syscall
#exit
li $v0, 10
syscall
output
======
Enter a number: 2
Enter a number: 5
Enter a number: 23
Enter a number: 15
The sum of the numbers is 45
-- program is finished running --
-----------------------------------------------------------------------------------
Answer 2: MIPS Program to convert name to upper case
.data
prompt: .asciiz "Enter your name: "
msg: .asciiz "Your name in upper case is "
name: .space 30
.text
#prompt and read string
li $v0, 4
la $a0, prompt
syscall
#read string
li $v0, 8
la $a0, name
li $a1, 30
syscall
#string loop
la $t0, name #string address
loop:
lb $t1, ($t0)
beq $t1, '', end_loop
beq $t1, ' ', end_loop
#if the character is anything out the range a-z, goto next
blt $t1, 'a', next
bgt $t1, 'z', next
sub $t1, $t1, 'a' #subtract ascii value of 'a'
add $t1, $t1, 'A' #add ascii value of 'A' i.e convert to upper case
sb $t1, ($t0) #store back the converted char to same location
next:
add $t0, $t0, 1 #next string location
b loop
end_loop:
#display the results
li $v0, 4
la $a0, msg
syscall
li $v0, 4
la $a0, name
syscall
#exit
li $v0, 10
syscall
output
======
Enter your name: john smith
Your name in upper case is JOHN SMITH
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.