计算机组成原理作业一 熟悉MIPS指令

第一题
.data
outputd: .asciiz "Alpha","November","First","alpha","november","Bravo","Oscar","Second","bravo","oscar","China","Paper","Third","china","paper","Delta","Quebec","Fourth","delta","quebec","Echo","Research","Fifth","echo","research","Foxtrot","Sierra","Sixth","foxtrot","sierra","Golf","Tango","Seventh","golf","tango","Hotel","Uniform","Eighth","hotel","uniform","India","Victor","Ninth","india","victor","Juliet","Whisky","zero","juliet","whisky","Kilo","X-ray","kilo","x-ray","Lima","Yankee","lima","yankee","Mary","Zulu","mary","zulu","",""
vald: .asciiz "A","N","1","a","n","B","O","2","b","o","C","P","3","c","p","D","Q","4","d","q","E","R","5","e","r","F","S","6","f","s","G","T","7","g","t","H","U","8","h","u","I","V","9","i","v","J","W","0","j","w","K","X","k","x","L","Y","l","y","M","Z","m","z","?"
unvald: .asciiz "*"
offs: .word 0,6,15,21,27,36,42,48,55,61,67,73,79,85,91,97,103,110,117,123,130,135,144,150,155,164,172,179,185,193,200,205,211,219,224,230,236,244,251,257,265,271,278,284,290,297,304,311,316,323,330,335,341,346,352,357,364,369,376,381,386,391,396,398

.text
st: li $v0,0xc
syscall
li $t1,0
ju: mul (t2,)t1,2 #judje the input
la $t4,vald
add (t3,)t2,$t4
lb (t3,0()t3)
beq (v0,)t3,out
bgt $t1,62,out
add (t1,)t1,1
j ju

out: #output seq
beq $t1,62,over
# read the offset
la $t5,offs
mul (t7,)t1,4
add (t6,)t5,$t7
lw (t6,()t6)
#add the offset
la $t4,outputd
add (t3,)t6,$t4
li $v0,4
la (a0,()t3)
syscall
j st

over:

数据是程序跑出来的不贴了

第二题
.data
stringdata: .space 100
h: .byte 10
g: .byte 13
ok: .asciiz "Success! Location: "
no: .asciiz "Fail!"
.text
li $v0 8
la $a0 stringdata
li $a1 100
syscall
st:
li $v0 0xc
syscall
move $v1 $v0
j ln2
st2:
move $v0 $v1
li $t0 0
la $a0 stringdata
la $a1 h
lb (a1 ()a1)
lo:
add $t1 $t0 $a0
lb (t1 ()t1)
beq $t1 $v0 Find
beq $t1 $a1 Fail
add $t0 $t0 1
j lo

Find:
li $v0 4
la $a0 ok
syscall
add $t0 $t0 1
li $v0 1

lw $a0 $t0

move $a0 $t0
syscall
j ln

Fail:
li $v0 4
la $a0 no
syscall
j ln

ln:li $v0,0xb
lb $a0,h
syscall
j st

lb $a0,g

syscall

ln2:li $v0,0xb
lb $a0,h
syscall
j st2

原文地址:https://www.cnblogs.com/sfzyk/p/7441217.html