Laman

Kamis, 11 April 2013

Potongan Pertama

Bagian pertama dari program ini adalah membaca string yang diinputkan oleh user. Stack diinisialisasi dengan cara menge push dengan null, natinya null ini berguna ketika program melakukan loop untuk mengepop stack, bergunanya yaitu saat loop mencapai null maka proses pop berhenti.

# Reverse and output a user-supplied string
#
# Settings: Load delays OFF; Branch delays OFF,
#           Trap file    ON; Pseudoinstructions ON   
#
# $t0 --- character pushed or popped
# $t1 --- index into string buffer str

        .text
        .globl  main

main:   #input the string
        li      $v0,8          # service code
        la      $a0,str        # address of buffer
        li      $a1,128        # buffer length 
        syscall       
                               # initialize the stack:        
        li      $t0,      # push a null
         
             $sp,$sp,4    # onto the stack
        
        sw      $t0,( )   # to signal its bottom
        li      $t1,0          # index of first char in str buffer

        # push each character onto the stack

        # pop chars from stack back into the buffer

        # print the reversed string

        .data
str:    .space  128            # character buffer            

Quest 12: Fill in the blank

Tidak ada komentar:

Posting Komentar