MIPS 어셈블리어 질문있습니다.

juhyun16의 이미지

사용자로 부터 값을 입력받아서 오름차순 정렬시키는 함수를 MIPS 어셈블리로 구현하고 있습니다. 지금 현재 구현된 것은 숫자 0이 나올 때까지 값을 입력 받고 숫자들을 정렬 시킵니다. 즉, 숫자 0은 정렬될 수가 없어요. 그리고 숫자를 입력할 때도 매번 엔터를 치도록 구현되었는데요 이것을 좀 수정하고자 합니다.

스페이스로 숫자를 구별하고요 일렬로 나열하면 숫자를 하나하나 읽어들입니다. 엔터를 입력하는 순간 숫자들을 정렬해주는 식으로 구현하고 싶습니다. 그리고 정렬 후에 또 다시 숫자를 입력받도록 자동으로 입력모드로 넘어가고 또 숫자를 새로 입력하면 새로 입력된 숫자에 대해 정렬을 하구요....

함수에 대한 종료는 Ctrl + Z 값을 입력하면 종료! 시키고 싶은데요 이걸 어떻게 수정해야할지 잘 모르겠습니다.

  .text
main :                      # main function
  la $s0, array             # put array address at $s0
 
  la $a0, inputmsg
  li $v0, 4
  syscall                   # print message
 
  li $t0, 0                 # initial i to 0
  li $t2, 0                 # initial N to 0
 
Input :                     # loop of input, $t0 = i
  li $v0, 5
  syscall                   # read integer
 
  sll $t4, $t0, 2           # $t4 = i * 4
  add $t4, $s0, $t4         # $t4 = &array[i]
  sw  $v0, 0($t4)           # array[i] = input;
  addi  $t0, $t0, 1         # i = i + 1
  addi  $t2, $t2, 1         # N = N + 1
  bne   $v0, $zero, Input   # while (i != n)
 
  addi  $t2, $t2, -1        # N = N - 1(don't need 0)
 
  la $a0, outputmsg1
  li $v0, 4
  syscall                   # print outputmsg
 
  jal PrintArray            # print array before sort
 
  li $a0, 0                 # left = 0
  addi $a1, $t2, -1         # right = N - 1
  jal Qsort                 # qsort(left, right)
 
  la $a0, outputmsg2
  li $v0, 4
  syscall                   # print outputmsg
 
  jal PrintArray            # print array after sort
 
  li $v0, 10
  syscall                   # Exit
 
PrintArray :                # void printArray() function
    li $t0, 0               # i = 0
  Print :
    sll $t1, $t0, 2         # $t1 = i * 4
    add $t1, $s0, $t1       # $t1 = &array[i]
 
    lw $a0, 0($t1)
    li $v0, 1
    syscall                 # print number
 
    la $a0, space
    li $v0, 4
    syscall                 # print space
 
    addi $t0, $t0, 1        # i = i + 1
    bne $t0, $t2, Print      # while (i != n)
 
    la $a0, nextLine
    li $v0, 4
    syscall                 # print "\n"
  jr $ra                    # return
 
Qsort :                     # void qsort(int l, int r) function
  slt $t8, $a0, $a1         # $t8 = left < right
  beq $t8, $zero, Return    # if (left >= right) return
  j Keep
  Return :
    jr $ra                  # return
  Keep :
 
  addi $sp, $sp, -12        # stack of right, return address, and j
  sw $ra, 8($sp)            # push return address
  sw $a1, 4($sp)            # push right
 
  sll $t3, $a0, 2           # $t3 = left * 4
  add $t3, $t3, $s0         # $t3 = &array[left]
  lw $t3, 0($t3)            # $t3 = array[left] = pivot
 
  addi $t0, $a0, 1          # $t0 = i = left + 1
  addi $t1, $a1, 0          # $t1 = j = right
  Loop :
    LoopI :
      sll $t4, $t0, 2       # $t4 = i * 4
      add $t4, $s0, $t4     # $t4 = &array[i]
      lw $t5, 0($t4)        # $t5 = array[i]
      slt $t8, $t3, $t5     # $t8 = pivot < array[i]
      bne $t8, $zero, BreakI# if (array[i] > pivot) break
      addi $t0, $t0, 1      # i = i + 1
      slt $t8, $a1, $t0     # $t8 = right < i
      bne $t8, $zero, BreakI# i > right
    BreakI :
 
    LoopJ :
      sll $t6, $t1, 2       # $t6 = j * 4
      add $t6, $s0, $t6     # $t6 = &array[j]
      lw $t7, 0($t6)        # $t7 = array[j]
      slt $t8, $t7, $t3     # $t8 = array[j] < pivot
      bne $t8, $zero, BreakJ# if (array[j] < pivot) break
      addi $t1, $t1, -1     # j = j - 1
      slt $t8, $a0, $t1     # $t8 = left < j
      beq $t8, $zero, BreakJ# left >= j
    BreakJ :
 
    slt $t8, $t1, $t0       # $t8 = i > j
    bne $t8, $zero, EndLoop # if (i > j) break;
 
    sll $t4, $t0, 2         # $t4 = i * 4
    add $t4, $s0, $t4       # $t4 = &array[i]
    lw $t5, 0($t4)          # $t5 = array[i]
    sll $t6, $t1, 2         # $t6 = j * 4
    add $t6, $s0, $t6       # $t6 = &array[j]
    lw $t7, 0($t6)          # $t7 = array[j]
    sw $t7, 0($t4)
    sw $t5, 0($t6)          # swap(array[i], array[j])
 
    j Loop                  # while (i <= j)
  EndLoop :
 
  sll $t4, $a0, 2           # $t4 = left * 4
  add $t4, $s0, $t4         # $t4 = &array[left]
  sll $t6, $t1, 2           # $t6 = j * 4
  add $t6, $s0, $t6         # $t6 = &array[j]
  lw $t7, 0($t6)            # $t7 = array[j]
  sw $t7, 0($t4)
  sw $t3, 0($t6)            # swap(array[left], array[j])
 
  sw $t1, 0($sp)            # push j
  addi $a1, $t1, 0          # $a1 = j
  jal Qsort                 # Qsort(left, j)
  lw $t1, 0($sp)            # pop j, $t1 = j
  addi $a0, $t1, 1          # $a0 = j + 1
  lw $a1, 4($sp)            # pop right, $a1 = right
  jal Qsort                 # Qsort(j + 1, right)
 
  lw $ra, 8($sp)           # pop return address
  addi $sp, $sp, 12
  jr $ra                    # return

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.