.data
name1:
.space 16 # how to reserve space inside the data memory region
.asciiz # note that .word means integer values and .asciiz is different
# You can find references of using the data memory region in the texbook appendix
# In the complete code, there should be more than 15 names reserved like this
# or you can insert names directly... methods are inside the textbook and sample codes formerly given
question:
.asciiz "Enter a name : "
result:
.asciiz "The resultn"
result2:
.asciiz "===============================n"
.text
main:
li $v0,4
la $a0,question
syscall
li $v0,8
la $a0,name1
li $a1, 16
syscall
la $a0, name1
li $a1, 15
addi $sp,$sp, -24
sw $ra, 20($sp)
sw $s4, 16($sp)
sw $s3, 12($sp)
sw $s2, 8($sp)
sw $s1, 4($sp)
sw $s0, 0($sp)
#########################################
move $s2, $a0
move $s3, $a1
move $s0, $zero
outerloop:
slt $t0, $s0, $s3
beq $t0, $zero, exit1
addi $s1, $s0, -1
innerloop:
slti $t0, $s1, 0
bne $t0, $zero, exit2
sll $t1, $s1, 4
add $t2, $s2, $t1
sorting:
lw $t3, 0($t2)
lw $t4, 16($t2)
slt $t0, $t4, $t3
beq $t0, $zero, exit2
move $a0, $s2
move $a1, $s1
jal swap
addi $s1, $s1, -1
j innerloop
exit2:
addi $s0, $s0, 1
j outerloop
exit1:
lw $s0, 0($sp)
lw $s1, 4($sp)
lw $s2, 8($sp)
lw $s3, 12($sp)
lw $s4, 16($sp)
lw $ra, 20($sp)
addi $sp,$sp, 24
li $v0,4
la $a0,result
syscall
li $v0,4
la $a0,result2
syscall
li $v0,4
la $a0,name1
syscall
li $v0, 10
syscall
#######################################
swap:
sll $t1, $a1, 4
add $t1, $a0, $t1
lw $t0, 0($t1)
lw $t2, 16($t1)
sw $t2, 0($t1)
sw $t0, 16($t2)
jr $ra
########################################
문자 정렬을 하는 프로그램입니다
실행하면 이상한 글자만 나오네요 ㅠㅠ
TODAY 입력시 YTODA 같이 오름차순으로 나오게끔 되야하는데 도무지 방법을 모르겠네요...