CS计算机代考程序代写 mips assembly assembler Karim Ali

Karim Ali
Introduction to Lab #1

In 229, a “lab” is a programming assignment:
Labs are do not count towards your grade, but can be submitted for marking and feedback.
Lab sessions are “consulting hours” when TAs are available to answer questions and to help.
The Labs are designed to help develop your understanding of the material. It is highly recommended that you do the labs.
The lab assignments will be progressively more difficult, and will require more time as the term advances.
General Intro to 229 Labs

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
Part #1

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

Understand data storage in memory.
Question #7: Understand little/big endianness and conversion to/from ASCII.
Question #10: Understand 2’s complement
Question #11: Assembly directives
Part #4

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 it is not working as it should.
Your job is to read and understand the program and report the errors in it.
Part #5: Find bugs in lab1-broken.s

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.
Part #5 Submission

System call table

Patterson and Hennessy pp. A-44

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
Part #6: Write a Simple Program

Example #2
Integer: 1179907

0000 0000

0001 0010

0000 0001

0000 0011
24
31
23
16
15
8
7
0
Byte 3
Byte 2
Byte 1
Byte 0
Your program has to produce the following value:

0000 0011

0000 0001

0001 0010

0000 0000
24
31
23
16
15
8
7
0

Check the grading mark-sheet
Formatting and Style

Assembler Syntax
comments begin with a sharp sign (#) and run to the end of the line.
.data
item: .word 1
.text
.globl main
main: lw $s3, item
Loop: add $t1, $s3, $s3 # $t1 ← 2 * i
add $t1, $t1, $t1 # $t1 ← 4 * i
add $t1, $t1, $s6 # $t1 ← Addr(save[i])
lw $t0, 0($t1) # $t0 ← MEM[save[i]]
bne $t0, $s5, Exit # if save[I] ≠ k goto Exit
add $s3, $s3, $s4 # i ← i + j
j Loop # goto Loop
Exit:

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.

Patterson and Hennessy pp. B-10

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

File lab1-p1.s
# What’s going on here ?
.text
main:
li $a1, 5
la $t0, val
xor $t1, $t1, $t1
xor $t2, $t2, $t2

loop: 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
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

val: .word 12, 34, 56, 78, 90

outputMsg:
.asciiz “\n Result = ”
newln:
.asciiz “\n\n”

OS-style call to obtain
services from SPIM:
$a0-$a3: arguments
$v0: system call code
before the call;
return value
after the call.
(see Patterson and
Hennessy pp. A-43).

pseudo instruction that
loads the immediate value
in the register

pseudo instruction that
loads the address of
specified label into register

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