Lab2 - Lab 2(Sections 500 and 501 PCSPIM to understand the MIPS architecture Name Venkat Mukku Sign the following statement On my honor as an Aggie

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Lab 2 (Sections 500 and 501) : PCSPIM to understand the MIPS architecture Name: Venkat Mukku Sign the following statement: On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work Venkat Mukku 1 Objective The objective of this lab is to make you more familiar with MIPS pseudo instructions as well as using memory. 2 Pre-requisite Before starting with this lab, you are required to know what pseudo instructions are as well as how MIPS access memory. 3 Basic Memory Access 1. Load the following program into SPIM and use it to answer the questions below 1 2 3 4 5 6 7 . data msg1 : msg2 : num1 : num2 : num3 : num4 : . a s c i i z ”A 17 byte message ” . a s c i i z ” Another message o f 27 b y t e s ” . byte 45 . h a l f 654 . word 0 x c a f e b a b e . word 0 x f e e d f a c e 1 Computer Architecture and Design, InLab 2 2 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 . text . globl main main : addu $s0 , $ra , $0 l i $v0 , 4 l a $a0 , msg1 syscall l a $a0 , msg2 syscall lb $t0 , num1 l h $t1 , num2 lw $t2 , num3 lw $t3 , num4 addu $ra , $s0 , $0 jr $ra #s a v e t h e r e t u r n a d d r e s s #s y s t e m c a l l f o r p r i n t s t r #a d d r e s s o f s t r i n g t o p r i n t #a d d r e s s o f s t r i n g t o p r i n t #l o a d num1 i n t o $ t 0 #l o a d num2 i n t o $ t 1 #l o a d num3 i n t o $ t 2 #l o a d num4 i n t o $ t 3 #r e s t o r e t h e r e t u r n a d d r e s s #r e t u r n from main (a) What are the machine instructions for the pseudo instruction la $a0, msg2? lui $1, 4097 [msg2] ori $4, $1, 19 [msg2] # Copy RAM address of msg2 into $1 (b) What is the address for each of the following items? Object Data Segment Text Segment msg1 msg2 num1 num2 num3 num4 0x10000000 Address 0x00400000 0x10010000 0x10010012 0x1001002e 0x10010030 \\\ 0x10010034 0x10010038 (c) Why does msg2 start 18 bytes after msg1 when msg1 is only 17 bytes long? I believe it is because of the null character. Computer Architecture and Design, InLab 2 3 (d) Why are there unused bytes between num1, num2, and num3, but num4 start immediately after num3? MIPS can manipulate unaligned data. 2. Load the following program into SPIM: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 . data msg1 : . word 0 : 2 4 . text . globl main main : addu $s0 , $0 , $ r a #s a v e t h e r e t u r n a d d r e s s l i $v0 , 8 #s y s c a l l f o r r e a d s t r l a $a0 , msg1 #l o a d a d d r e s s o f msg1 t o s t o r e s t r i n g l i $a1 , 100 #msg1 i s 100 b y t e s syscall lb $t0 , 5 ( $a0 ) #l o a d t h e c h a r a c t e r i n t o $ t 0 l i $t1 , ’ a ’ #g e t v a l u e o f ’ a ’ b l t $t0 , $t1 , nomodify #do n o t h i n g i f l e t t e r i s l e s s than ’ a ’ l i $t1 , ’ z ’ #g e t v a l u e o f ’ z ’ bgt $t0 , $t1 , nomodify #do n o t h i n g i f l e t t e r i s g r e a t e r than ’ z ’ addi $t0 , $t0 , −0x20 #encap t h e l e t t e r sb $t0 , 5 ( $a0 ) #s t o r e t h e new l e t t e r nomodify : l i $v0 , 4 #s y s c a l l f o r p r i n t s t r syscall addu $ra , $s0 , $0 #r e s t o r e r e t u r n a d d r e s s jr $ra #r e t u r n from main Specify the operation performed by the program: It converts lower case letters to upper case. 3. Write a program that reads a string from the user and outputs the number of lowercase letters in the string. Save your program as lab2-3.s, and run it to make sure it works correctly. Computer Architecture and Design, InLab 2 4 4. Load the following program into SPIM: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 . data hextable : . a s c i i ” 0123456789 a b c d e f ” msg1 : . a s c i i z ”Your number i n Hex i s : ” . text . globl main main : addu $s0 , $0 , $ r a #s a v e t h e r e t u r n a d d r e s s l i $v0 , 5 #s y s c a l l f o r r e a d i n t syscall add $s1 , $v0 , $0 l i $v0 , 4 #s y s c a l l f o r p r i n t s t r l a $a0 , msg1 syscall l a $a1 , h e x t a b l e srl $t0 , $s1 , 4 #g e t upper 4 b i t s add $a2 , $a1 , $ t 0 #g e t a d d r e s s i n h e x t a b l e lb $a0 , 0 ( $a2 ) #g e t c h a r a c t e r l i $v0 , 11 #s y s c a l l f o r p r i n t c h a r syscall andi $t0 , $s1 , 0 x f #g e t l o w e r 4 b i t s add $a2 , $a1 , $ t 0 #g e t a d d r e s s i n h e x t a b l e lb $a0 , 0 ( $a2 ) #g e t c h a r a c t e r l i $v0 , 11 #s y s c a l l f o r p r i n t s t r syscall addu $ra , $s0 , $0 #r e s t o r e r e t u r n a d d r e s s jr $ra #r e t u r n from main Specify the operation performed by the program: It converts decimal numbers into hexadecimal numbers. 5. Write a program that reads a number x from the user, and prints the first x letters of the alphabet (in lower case). You do not need to check whether the number is positive. Save your program as lab2-5.s, and run it to make sure it works correctly. ...
View Full Document

This note was uploaded on 03/20/2010 for the course ECEN 350 taught by Professor Sprintston during the Spring '09 term at Texas A&M.

Ask a homework question - tutors are online