计组作业一QWQ

# 石宇堃 1600012967
	.data  
alphabet: .asciiz "Alpha ","Bravo ","China ","Delta ","Echo ","Foxtrot ","Golf ","Hotel ","India ","Juliet ", "Kilo ","Lima ","Mary ","November ","Oscar ","Paper ","Quebec ","Research ","Sierra ","Tango ", "Uniform ","Victor ","Whisky ","X-ray ","Yankee ","Zulu "
alpha:     .asciiz "alpha ","bravo ","china ","delta ","echo ","foxtrot ","golf ","hotel ","india ","juliet ","kilo ","lima ","mary ","november ","oscar ","paper ","quebec ","research ","sierra ","tango ","uniform ","victor ","whisky ","x-ray ","yankee ","zulu "
al_offset: .word 0,7,14,21,28,34,43,49,56,63,71,77,83,89,99,106,113,121,131,139,146,155,163,171,178,186
number: .asciiz "zero ","First ","Second ","Third ","Fourth ","Fifth ","Sixth ","Seventh ","Eighth ","Ninth "  
n_offset: .word  0,6,13,21,28,36,43,50,59,67


	.text
	.globl main
main:   li $v0, 12
	syscall
	sub $t1, $v0, 63 # 63 == '?'
	beqz $t1, end
	sub $t1, $v0, 48  # 48 == '0' t1 == v0 - '0'
	slt $s0, $t1, $0 # if t1 < 0 then s1 = 1
	bnez $s0, others
	
	sub $t2, $t1, 10 # t2 = t1 - 10
	slt $s1, $t2, $0
	bnez $s1, getd
	
	sub $t2, $v0, 91 # 90 == 'Z'
	slt $s3, $t2, $0 # v0 <= 'Z'
	sub $t3, $v0, 64 # 65 == 'A'
	sgt $s4, $t3, $0 # v0 >= 'A'
	and $s0, $s3, $s4
	bnez $s0, getc
	
	sub $t2, $v0, 123 # 122 == 'z'
	slt $s3, $t2, $0 # v0 <= 'z'
	sub $t3, $v0, 96 # 97 == 'a'
	sgt $s4, $t3, $0 # v0 >= 'a'
	and $s0, $s3, $s4
	bnez $s0, getcc
	
	j others
getd:   sll $t1, $t1, 2
	la, $s0, n_offset
	add $s0, $s0, $t1
	lw $s1, ($s0)
	la $a0, number
	add $a0, $a0, $s1
	li $v0, 4
	syscall
	j main
	
getc:   sub $t3, $t3, 1
	sll $t3, $t3, 2
	la, $s0, al_offset
	add $s0, $s0, $t3
	lw $s1, ($s0)
	la $a0, alphabet
	add $a0, $a0, $s1
	li $v0, 4
	syscall
	j main
getcc:  sub $t3, $t3, 1
	sll $t3, $t3, 2
	la, $s0, al_offset
	add $s0, $s0, $t3
	lw $s1, ($s0)
	la $a0, alpha
	add $a0, $a0, $s1
	li $v0, 4
	syscall
	j main
others: li $a0, 42
	li $v0, 11
	syscall
	j main
end:    li $v0, 10
	syscall
	

你可能感兴趣的:(计组作业一QWQ)