CS计算机代考程序代写 mips assembly assembler Introduction to Lab #1

Introduction to Lab #1
José Nelson Amaral

General Intro to 229 Labs
• In 229, a “lab” is a programming assignment:
• A lab requires many more hours of work than the time allocated for lab sessions.
• Lab sessions are “consulting hours” when TAs are available to answer questions and to help.
• Reading/work prior to the lab date/time is essential.
• The lab assignments will be progressively more difficult,
and will require more time as the term advances.
• ACMPUT229labisnota“lab”inthesenseof a chemistry lab.

Part #1
• Read Appendix titled “Assemblers, Linkers, and the SPIM Simulator” (specially section 9):
– In the 4th edition of the book, this is appendix B – In the 5th edition of the book, this is appendix A
• Read the SPIM tutorial in the Tutorials section of the CD that comes with the book.

Part #2
• Self-guided tutorial-style introduction to usage of XSPIM.
Part #3
• Simple exercise to illustrate use of SPIM.

Part #4
• Understand data storage in memory.
• Question #7: Understand little/big endianess and conversion to/from ASCII.
• Question #10: Understand 2-complement integers
• Question 11: Assembly directives

Part #5: Find bugs in lab1-broken.s
The program lab1-broken.s was written to replace characters in a string.
It should convert
“Cmput 229 is the absolute bomb.”
Into “Cmput-229-is-the-absolute-bomb.”
But lab1-broken.s is not working as it should. Your job is to read and understand the program and to report what are the errors in this program.

Part #5 submission
• You will describe the bugs in a text file called bugs.txt and submit this file.
• The solution for parts 1-5 are answers to the questions in the lab assignment.
– There is no specified format for these answers. Just use a reasonable formatting and provide clear and concise answers.

Chapter 2 — Instructions: Language of the Computer —8
P-H pp. A-44
System call table

Part #6: Write a Simple Program
Write a MIPS assembly language program to: • read an integer from the terminal;
• invert the byte order of the integer;
• print out the new value of the integer.

Example #2 Integer: 1179907
31 24 23
Byte 3
16 15
8 7 0
Byte 0
0000 0000
0001 0010
0000 0001
0000 0011
Byte 2
Byte 1
Your program has to produce the following value: 31 24 23 16 15 8 7 0
0000 0011
0000 0001
0001 0010
0000 0000

Formatting and Style • Check the grading lab marksheet

Assembler Syntax
comments begin with a sharp sign (#) and run to the end of the line. identifiers are alphanumeric sequences, underbars (_), and dots (.)
that do not begin with a number.
labels are identifiers placed at the beginning of a line, and followed by a colon.
item:
main: lw Loop: add add add
lw
bne
add
Chapter 2 — Instructions:
Language of the Computer
— 12
.data
.word 1
.text
.globl main
$s3, item $t1,$s3,$s3 $t1, $t1, $t1 $t1, $t1, $s6 $t0, 0($t1) $t0, $s5, Exit $s3, $s3, $s4 Loop
# $t1←2*i
# $t1←4*i
# $t1←Addr(save[i])
# $t0 ← MEM[save[i]] # if save[I] ≠ k goto Exit # i←i+j
# goto Loop
j
Exit:
P-H. p. B-10

.data
.word 1 .text
.globl
item:
main: lw Loop: add add add
lw
bne
add
Chapter 2 — Instructions:
Language of the Computer
— 13
# $t1←2*i
# $t1←4*i
# $t1←Addr(save[i])
# $t0 ← MEM[save[i]] # if save[I] ≠ k goto Exit # i←i+j
# goto Loop
Exit:
Assembler Directives
identifies the beginning of the data segment
(in this example this segment contains a single word).
stores the decimal number 1 in 32-bits (4 bytes)
identifies the beginning of the text segment (where the instructions of the program are stored).
main declares the label main global
(so that it can be accessed from other files).
.data
.word 1
.text
.globl main
$s3, item
$t1, $s3, $s3 $t1, $t1, $t1 $t1, $t1, $s6 $t0, 0($t1) $t0, $s5, Exit $s3, $s3, $s4 Loop
j

pseudo instruction thatFile lab1-p1.s loads the immediate value
in the register
exit:
div $t5, $t1, $a1 li $v0, 4
la $a0, outputMsg syscall
li $v0, 1
add $a0, $0, $t5 syscall
li $v0, 4
la $a0, newln syscall
jr $ra .data
.word 12, 34, 56, 78, 90
val:
outputMsg:
.asciiz “\n Result = ”
newln:
.asciiz “\n\n”
# What’s going on here ? .text
main:
li $a1, 5
loop:
la $t0, val
xor $t1, $t1, $t1 xor $t2, $t2, $t2
sub $t3, $a1, $t2 blez $t3, exit
lw $t4, 0($t0)
add $t1, $t1, $t4 add $t2, $t2, 1 addu $t0, $t0, 4
j loop
pseudo instruction that
loads the address of
specified label into register
Chapter 2 — Instructions: Language of the Computer — 14
OS-style call to obtain services from SPIM: $a0-$a3: arguments $v0: system call code
before the call; return value after the call.
(see page A-43).

Files to Submit
• There are three files to submit: – lab1.txt
– lab1.s
– bugs.txt