Lab 2 : Pseudo Instructions and Memory Access solved

$30.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (2 votes)

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 accesses memory.
3 Basic Memory Access
1. Type the following program into MARS (save it as lab2a.s) and use it to answer the
questions below

1 . data
2 msg1 : . asciiz ”A 17 by te message ”
3 msg2 : . asciiz ”Another message of 27 bytes”
4 num1 : . by te 45
5 num2 : . h a l f 654
6 num3 : .word 0xcafebabe
7 num4 : .word 0xfeedface
8 . text
9 . globl main
10 main :
11 l i $v0 , 4 #sys tem c a l l f o r p r i n t str
12 la $a0 , msg1 #a d d re s s o f s t r i n g t o p r i n t
13 syscall
14 la $a0 , msg2 #a d d re s s o f s t r i n g t o p r i n t
15 syscall
16 lb $t0 , num1 #l o a d num1 i n t o $t 0
17 l h $t1 , num2 #l o a d num2 i n t o $t 1
18 lw $t2 , num3 #l o a d num3 i n t o $t 2
19 lw $t3 , num4 #l o a d num4 i n t o $t 3
20 l i $v0 , 10 # system call for exit
21 syscall # we are out o f here .
(a) What are the assembly instructions for the pseudo instruction la $a0, msg2?
(b) What is the address for each of the following items?
Object Address
Data Segment
Text Segment
msg1
msg2
num1
num2
num3
num4
(c) Why does msg2 start 18 bytes after msg1 when msg1 is only 17 bytes long?
Computer Architecture and Design, Lab 2 3
(d) Why are there unused bytes between num1, num2, and num3, but num4 start
immediately after num3?
2. Go to the Settings on menu bar and make sure the item Popup dialog for input
syscalls (5,6,7,8,12) is checked. Type the following program into MARS (save as
lab2b.s):
1 . data
2 msg1 : .word 0:24
3 . text
4 . globl main
5 main :
6 l i $v0 , 8 #sy sc all for read str
7 la $a0 , msg1 #l o a d a d d re s s o f msg1 t o s t o r e s t r i n g
8 l i $a1 , 100 #msg1 i s 100 b y t e s
9 syscall
10 lb $t0 , 5( $a0 ) #l o a d t he c h a r a c t e r i n t o $t 0
11 l i $t1 , ’a ’ #ge t value o f ’a ’
12 blt $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 ’
13 l i $t1 , ’z ’ #ge t value o f ’ z ’
14 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 ’
15 addi $t0 , $t0 , 0x20 #encap t h e l e t t e r
16 sb $t0 , 5( $a0 ) #s t o r e the new l e t t e r
17 nomodify :
18 l i $v0 , 4 #sy sc all for p r in t str
19 syscall
20 l i $v0 , 10 # system call for exit
21 syscall # we are out o f here .
Specify the operation performed by the program:
Computer Architecture and Design, Lab 2 4
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 lab2c.s, and run it to make sure it
works correctly. Demonstrate your progress to the TA. .
4. Type the following program into MARS (save your program as lab2d.s):
1 . data
2 hextable : . ascii ”0123456789 abcdef”
3 msg1 : . asciiz ”Your number in Hex i s : ”
4 . text
5 . globl main
6 main :
7 l i $v0 , 5 #sy sc all for read int
8 syscall
9 add $s1 , $v0 , $0
10 l i $v0 , 4 #sy sc all for p r in t str
11 la $a0 , msg1
12 syscall
13 la $a1 , hextable
14 srl $t0 , $s1 , 4 #ge t upper 4 b i t s
15 add $a2 , $a1 , $t0 #ge t address in h e x t a bl e
16 lb $a0 , 0( $a2 ) #ge t c h ar ac ter
17 l i $v0 , 11 #sy sc all for pr int char
18 syscall
19 andi $t0 , $s1 , 0xf #ge t lower 4 b i t s
20 add $a2 , $a1 , $t0 #ge t address in h e x t a bl e
21 lb $a0 , 0( $a2 ) #ge t c h ar ac ter
22 l i $v0 , 11 #sy sc all for p r in t str
23 syscall
24 l i $v0 , 10 # system call for exit
25 syscall # we are out o f here .
Specify the operation performed by the program:
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 lab2f.s, and run it to make sure it works correctly. Demonstrate
your progress to the TA. .
Computer Architecture and Design, Lab 2 5
4 Deliverables
• Submit completed copy of this lab manual.
• Include the following in a compressed file (.zip format) to your TA:
– The source code for all .s files.
– All log files.