Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##############################################
- # Program Name: String Length
- # Programmer: David Thornberg
- # Date: 10/14/2015
- #############################################
- #
- #
- #
- #############################################
- #
- ###########################################
- .data # Data declaration section
- Prompt: .asciiz " \n Set1: "
- Prompt2: .asciiz " \n Set2: "
- Set1: .space 80
- Set2: .space 80
- Result: .asciiz ","
- Result2: .asciiz "\n The set is..."
- Bye: .asciiz " \n Have a nice day."
- .globl main
- .text
- main:
- la $t0, printSet
- li $v0, 4 #System call code for Print
- la $a0, Prompt #load add.dress of prompt into $a0
- syscall
- li $v0, 8
- la $a0, Set1
- la $a1, 80
- syscall #print the prompt message
- li $v0, 4 #System call code for Print
- la $a0, Prompt2 #load add.dress of prompt into $a0
- syscall
- li $v0, 8
- la $a0, Set2
- la $a1, 80
- syscall #print the prompt message
- la $s0, Set1
- la $s1, Set2
- move $s3, $s0
- jalr $s6, $t0
- move $s3, $s1
- jalr $s6, $t0
- j End
- printSet:
- li $t2, 0x0 # A one to test the results
- li $t3, 0x0 # A zero to test the results
- li $t4, 0x1 # The number of the set
- lw $t6, ($s3) # Load set from address $s3
- li $t7, 0x32 # Max number of sets
- li $v0, 4 #System call code for Print String
- la $a0, Result2 #load add.dress of msg into $a0
- syscall #print the string
- loop:
- and $t5, $t6, $t2 # Test the lowest bit
- beq $t5, $t3, check # Result is non-zero only if the bit is set
- li $v0, 1 # system call code for integer print
- move $a0, $t4 # set integer to be printed
- syscall # print the integer
- li $v0, 4 #System call code for Print String
- la $a0, Result #load add.dress of msg into $a0
- syscall #print the string
- check: beq $t7, $t4, back # check whether it was the last set
- srl $t6, $t6, 1 # shift the bit one place right to test next bit
- addi $t4, $t4, 1 # add 1 to the set number
- b loop
- back:
- jr $s6
- End:
- li $v0, 4 #System call code for Print String
- la $a0, Bye #load add.dress of msg into $a0
- syscall #print the string
- li $v0, 10 #terminate program run and
- syscall #return control to the system
Advertisement
Add Comment
Please, Sign In to add comment