第一次互評作業:MIPS匯編程序設計
阿新 • • 發佈:2017-07-13
lower mov small search 在屏幕上 orm sof con print
1 .data 2 3 string1: .asciiz "*\n" 4 5 6 bstring: .asciiz 7 "Alpha ","Bravo ","China ","Delta ","Echo ","Foxtrot ", 8 "Golf ","Hotel ","India ","Juliet ","Kilo ","Lima ", 9 "Mary ","November ","Oscar ","Paper ","Quebec ","Research ", 10 "Sierra ","Tango ","Uniform ","Victor ","Whisky ","X-ray ", 11 "Yankee ","Zulu " 12 13 boffset: .word 14 0,7,14,21,28,34,43,49,56,63,71, 15 77,83,89,99,106,113,121,131, 16 139,146,155,163,171,178,186 17 18 19 nstring: .asciiz 20 "zero ", "First ", "Second ", "Third ", "Fourth ", 21 "Fifth ", "Sixth ", "Seventh ","Eighth ","Ninth " 22 23 noffset: .word 24 0,6,13,21,28,36,43,50,59,67 25 26 27 sstring: .asciiz 28 "alpha ","bravo ","china ","delta ","echo ","foxtrot ", 29 "golf ","hotel ","india ","juliet ","kilo ","lima ", 30 "mary ","november ","oscar ","paper ","quebec ","research ", 31 "sierra ","tango ","uniform ","victor ","whisky ","x-ray ", 32 "yankee ","zulu " 33 34 soffset: .word 35 0,7,14,21,28,34,43,49,56,63,71, 36 77,83,89,99,106,113,121,131, 37 139,146,155,163,171,178,186 38 39 40 41 .text 42 43 loop: 44 45 li $v0,12 46 syscall 47 48 move $t2,$v0 49 50 move $t0,$t2 51 li $t1,63 52 beq $t0,$t1,exit 53 54 move $t0,$t2 55 li $t1,122 56 bgt $t0,$t1,other 57 58 move $t0,$t2 59 li $t1,48 60 blt $t0,$t1,other 61 62 move $t0,$t2 63 li $t1,57 64 ble $t0,$t1,number 65 66 move $t0,$t2 67 li $t1,65 68 blt $t0,$t1,other 69 70 move $t0,$t2 71 li $t1,90 72 ble $t0,$t1,big 73 74 move $t0,$t2 75 li $t1,97 76 blt $t0,$t1,other 77 78 #print Lower case letters 79 80 addi $t0,$t0,-97 81 la $t1,soffset 82 sll $t0,$t0,2 83 add $t0,$t0,$t1 84 lw $t1,($t0) 85 la $t0,sstring 86 add $t0,$t0,$t1 87 move $a0,$t0 88 li $v0,4 89 syscall 90 j loop 91 92 other: 93 94 la $a0,string1 95 li $v0,4 96 syscall 97 j loop 98 99 number: 100 101 addi $t0,$t0,-48 102 la $t1,noffset 103 sll $t0,$t0,2 104 add $t0,$t0,$t1 105 lw $t1,($t0) 106 la $t0,nstring 107 add $t0,$t0,$t1 108 move $a0,$t0 109 li $v0,4 110 syscall 111 j loop 112 113 #print Upper case letters 114 big: 115 116 addi $t0,$t0,-65 117 la $t1,boffset 118 sll $t0,$t0,2 119 add $t0,$t0,$t1 120 lw $t1,($t0) 121 la $t0,bstring 122 add $t0,$t0,$t1 123 move $a0,$t0 124 li $v0,4 125 syscall 126 j loop 127 128 exit: 129 130 li $v0,10 131 syscall
第一題的算法文字描述:
調用系統功能輸入數據
轉換數據
(1) 如果輸入的是字母(A~Z,區分大小寫)或數字(0~9),則將其轉換成對應的英文單詞
(2) 若輸入的不是字母或數字,轉換成“*”,
每輸入一個字符,即時轉換並在屏幕上顯示,
支持反復輸入,直到按“?”鍵結束程序。
對應的偽碼:
1 if(n<=122) 2 if(n>=48) 3 if(n<=57) 4 goto number 5 if(n<65) 6 goto ‘*‘ 7 else 8 if(n<=90) 9 goto big 10 if(n<97) 11 goto ‘*‘ 12 if(n>=97) 13 goto small 14 else 15 goto ‘*‘ 16 else 17 goto ‘*‘
第一次互評作業:MIPS匯編程序設計