系统功能调用实现简单输入输出(mips)

原创
2014/03/30 11:59
阅读数 2.8K

系统功能调用实现简单输入输出

实验目的:熟悉MIPS的指令,掌握简单的汇编程序结构。

实验内容:利用系统功能调用从键盘输入,转换后在屏幕上显示,具体要求如下:

(1) 如果输入的是字母(A~Z,不区分大小写)或数字(0~9),则将其转换成对应的英文单词后在屏幕上显示,对应关系见下表

(2) 若输入的不是字母或数字,则在屏幕上输出字符“*

(3) 每输入一个字符,即时转换并在屏幕上显示,需考虑显示结果的清晰美观

(4) 支持反复输入,直到按?键结束程序

(5) 程序结束时,在屏幕上显示本人的姓名全拼和学号

例:在键盘上输入“U2011/”,对应输出内容为“Uniform two zero one one *

A

Alpha

N

November

1

one

B

Bravo

O

Oscar

2

two

C

Charlie

P

Papa

3

three

D

Delta

Q

Quebec

4

four

E

Echo

R

Romeo

5

five

F

Foxtrot

S

Sierra

6

six

G

Golf

T

Tango

7

seven

H

Hotel

U

Uniform

8

eight

I

India

V

Victor

9

nine

J

Juliet

W

Whisky

0

zero

K

Kilo

X

X-ray

 

 

L

Lima

Y

Yankee

 

 

M

Mike

Z

Zulu

 

.data
myname:.asciiz "\r\nNAME:locusxt\r\n"
id:	.asciiz "ID:locusxt\r\n"
aa:	.asciiz "Alpha " #以下是字母对应的字符串
bb:	.asciiz "Bravo "
cc:	.asciiz "Charlie "
dd:	.asciiz "Delta "
ee:	.asciiz "Echo "
ff:	.asciiz "Foxtrot "
gg:	.asciiz "Golf "
hh:	.asciiz "Hotel "
ii:	.asciiz "India "
jj:	.asciiz "Juliet "
kk:	.asciiz "Kilo "
lll:	.asciiz "Lima "
mm:	.asciiz "Mike "
nn:	.asciiz "November "
oo:	.asciiz "Oscar "
pp:	.asciiz "Papa "
qq:	.asciiz "Quebec "
rr:	.asciiz "Romeo "
ss:	.asciiz "Sierra "
tt:	.asciiz "Tango "
uu:	.asciiz "Uniform "
vv:	.asciiz "Victor "
ww:	.asciiz "Whisky "
xx:	.asciiz "X-ray "
yy:	.asciiz "Yankee "
zz:	.asciiz "Zulu "
zero:	.asciiz "zero "    #以下是数字对应的单词
one:	.asciiz "one "
two:	.asciiz "two "
three:	.asciiz "three "
four:	.asciiz "four "
five:	.asciiz "five "
six:	.asciiz "six "
seven:	.asciiz "seven "
eight:	.asciiz "eight "
nine:	.asciiz "nine "
star:	.asciiz "* "
alphabet: .word aa, bb, cc, dd, ee, ff, gg, hh, ii, jj, kk, lll, mm, nn, oo, pp ,qq, rr, ss, tt, uu, vv, ww, xx, yy, zz
num:	 .word zero, one, two, three, four, five, six, seven, eight, nine

backspace:	.asciiz "\b"

	.text
        .globl main
main:	
	li $s0, 'z'
	li $s1, 'a'
	li $s2, 'Z'
	li $s3, 'A'
	li $s4, '9'
	li $s5, '0'
	
	
getKey:
	li $v0, 12
	syscall
	
	#addi $t0, $v0, 0
	
	#la $a0, backspace
	#li $v0, 4
	#syscall
	
	#addi $v0, $t0, 0
	
compare:
	
	li $t0, '?'
	beq $v0, $t0, deal
	
	#判断是不是小写字母
	slt $t0, $s0, $v0 #s0 < v0 ?
	bne $t0, $0, dispstar
	slt $t0, $v0, $s1 #v0 < s1 ?
	beq $t0, $0, dispalph
	
	#判断是不是大写字母
	slt $t0, $s2, $v0
	bne $t0, $0, dispstar
	slt $t0, $v0, $s3
	beq $t0, $0, dispalphc
	
	#判断是不是数字
	slt $t0, $s4, $v0
	bne $t0, $0, dispstar
	slt $t0, $v0, $s5
	beq $t0, $0, dispnum
	
	j dispstar

dispalphc:#大写字母+32变小写
	addi $v0, $v0, 32
dispalph:#处理字母
	sub $v0, $v0, $s1 #v0 -= 'a'
	sll $v0, $v0, 2
	la $t0, alphabet
	add $t0, $t0, $v0
	lw $a0, ($t0)
	li $v0, 4
	syscall
	j getKey
dispnum:#处理数字
	sub $v0, $v0, $s5 #v0 -= '0'
	sll $v0, $v0, 2
	la $t0, num
	add $t0, $t0, $v0
	lw $a0, ($t0)
	li $v0, 4
	syscall
	j getKey
	
dispstar:
	la $a0, star
	li $v0, 4
	syscall
	j getKey

deal:#处理问号
	la $a0, myname
	li $v0, 4
	syscall
	la $a0, id
	li $v0, 4
	syscall



==================
syscall 里好像没有不回显的从键盘读
输出"退格"也是不行的,好像直接输出了个空格.
也有可能是mars模拟器太弱了.
这里以及另外一道的esc结束,都替换成了'?'结束
展开阅读全文
打赏
0
1 收藏
分享
加载中
locusxt博主

引用来自“leo_xiaofeixia”的评论

这是大几的课程内容啊?

计算机系大二

2014/03/31 19:00
回复
举报
这是大几的课程内容啊?
2014/03/31 17:01
回复
举报
更多评论
打赏
2 评论
1 收藏
0
分享
返回顶部
顶部