Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
Colafornia committed Aug 18, 2019
1 parent f37df33 commit 25712a9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 36 deletions.
39 changes: 19 additions & 20 deletions Computer_Composition_PekingUniversity/assignment1.1.asm
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,32 @@ exit_str: .asciiz "#Program is stopped#"

.text
.globl main
main: li $v0, 12 # read input
main: li $v0, 12 # read input
syscall
sub $t1, $v0, 63 # '?' assic is 63
sub $t1, $v0, 63 # '?' assic is 63
beqz $t1, exit
sub $t1, $v0, 48 # '0'
slt $s0, $t1, $0 # if t1 < 0 then s0 = 1
sub $t1, $v0, 48 # '0'
slt $s0, $t1, $0 # if t1 < 0 then s0 = 1
bnez $s0, others

# is number?
sub $t2, $t1, 10 # number
slt $s1, $t2, $0 # if t2 < 0 then s1 = 1
sub $t2, $t1, 10 # number
slt $s1, $t2, $0 # if t2 < 0 then s1 = 1
bnez $s1, getnumber

# is capital?
sub $t2, $v0, 91
slt $s3, $t2, $0 # if v0 <= 'Z' then s3 = 1
sub $t3, $v0, 64
sgt $s4, $t3, $0 # if v0 >='A' then s4 = 1
and $s0, $s3, $s4 # if s3 == 1 && s4 == 1
slt $s3, $t2, $0 # if v0 <= 'Z' then s3 = 1
sub $t3, $v0, 64
sgt $s4, $t3, $0 # if v0 >='A' then s4 = 1
and $s0, $s3, $s4 # if s3 == 1 && s4 == 1
bnez $s0, getupperword

# is lower case?
sub $t2, $v0, 123
slt $s3, $t2, $0 # if v0 <= 'z' then s3 = 1
sub $t3, $v0, 96
sgt $s4, $t3, $0 # if v0 >= 'a' then s4 = 1
slt $s3, $t2, $0 # if v0 <= 'z' then s3 = 1
sub $t3, $v0, 96
sgt $s4, $t3, $0 # if v0 >= 'a' then s4 = 1
and $s0, $s3, $s4
bnez $s0, getlowerword
j others
Expand Down Expand Up @@ -94,15 +94,14 @@ getlowerword: sub $t3, $t3, 1
j main

others: and $a0, $0, $0
add $a0, $a0, 42 # '*'
li $v0, 11 # print result
add $a0, $a0, 42 # '*'
li $v0, 11 # print result
syscall
j main

exit:
add $a0, $0, '\n'
li $v0, 11
syscall
exit: add $a0, $0, '\n'
li $v0, 11
syscall
la $a0, exit_str
li $v0, 4 # exit
li $v0, 4 # print exit info
syscall
30 changes: 14 additions & 16 deletions Computer_Composition_PekingUniversity/assignment1.2.asm
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,36 @@ buf: .space 100

.text
.globl main
main: la $a0, buf # address of input buffer la: Load Address
la $a1, 100 # maximum number of characters to read
li $v0, 8 # read string li: Load Immediate
main: la $a0, buf # address of input buffer la: Load Address
la $a1, 100 # set maximum number of characters to read
li $v0, 8 # read string li: Load Immediate
syscall

get_input: li $v0, 12 # read character
get_input: li $v0, 12 # read character
syscall
addi $t7, $0, 63 # '?' => exit
addi $t7, $0, 63 # '?' => exit
sub $t6, $t7, $v0
beq $t6, $0, exit
add $t0, $0, $0
la $s1, buf

find_loop: lb $s0, 0($s1) # sign-extends the byte into a 32-bit value
find_loop: lb $s0, 0($s1) # sign-extends the byte into a 32-bit value
sub $t1, $v0, $s0
beq $t1, $0, success # t0 is answer to print
addi $t0, $t0, 1
slt $t3, $t0, $a1 # t0 < a1 then t3 = 1 else t3 = 0 ( a1 is maximum number of characters to read
beq $t3, $0, fail # already reach the end of characters
addi $s1 $s1, 1 # ++
slt $t3, $t0, $a1 # t0 < a1 then t3 = 1 else t3 = 0 ( a1 is maximum number of characters to read
beq $t3, $0, fail # already reach the end of characters
addi $s1 $s1, 1 # ++
j find_loop

success: la $a0, msg_success
li $v0, 4 # print msg_success
li $v0, 4 # print msg_success
syscall
addi $a0, $t0, 1
li $v0, 1 # print result integer
li $v0, 1 # print result integer
syscall
la $a0, string_end
li $v0, 4 # print new line
li $v0, 4 # print new line
syscall
j get_input

Expand All @@ -45,8 +45,6 @@ fail: la $a0, msg_fail
syscall
j get_input

exit:
la $a0, msg_exit
li $v0, 4

exit: la $a0, msg_exit
li $v0, 4
syscall

0 comments on commit 25712a9

Please sign in to comment.