I. FUCKING. HATE. ASSEMBLY.

seen from Philippines

seen from Chile

seen from Germany
seen from Lithuania

seen from United States

seen from United States
seen from Türkiye

seen from United States

seen from Australia

seen from Germany
seen from China

seen from China
seen from Thailand
seen from United States

seen from Hungary

seen from Germany
seen from China

seen from United States

seen from United States

seen from Germany
I. FUCKING. HATE. ASSEMBLY.
Lab8.s
########################################################### # Program Description # CS315 Lab 8 - Stack # # 1. Use create_array to create a dynamic array of words # (note: create_array calls read_array, main does not # call read_array) # 2. Use print_array to print the array # 3. Use sum_array to calculate the sum of the array # 4. Print the sum # # This is the last one! Thanks all for reading and following me! # ########################################################### # Register Usage # $t0 # $t1 # $t2 # $t3 # $t4 # $t5 # $t6 # $t7 # $t8 # $t9 ########################################################### .data
########################################################### .text main: jal create_array # jumps to create_array subprogram jal print_array # jumps to print_array subprogram jal sum_array # jumps to sum_array subprogram lw $a0, 0($sp) # load sum to print li $v0, 1 # system call code for print int syscall addiu $sp, $sp, 12 # Unallocate 3 words mainEnd: li $v0, 10 syscall # Halt ###########################################################
########################################################### # Subprogram Description # Ask the user for an array length, dynamically alocate # an array of words with the given length # Call read_array to fill the array
########################################################### # Arguments In and Out of subprogram # # $a0 # $a1 # $a2 # $a3 # $v0 # $v1 # $sp+0 Base address (OUT) # $sp+4 Array length (OUT) # $sp+8 # $sp+12 ########################################################### # Register Usage # $t0 - Base address # $t1 - Length # $t2 # $t3 # $t4 # $t5 # $t6 # $t7 # $t8 # $t9 ########################################################### .data Array_length: .asciiz "Enter a length for your array: "
########################################################### .text create_array: # Ask the user for an array length # Allocate space for the array # Call read_array to fill the array addiu $sp, $sp, -4 # Allocate 1 word sw $ra, 0($sp) # Store the return address li $v0, 4 # system call code for print string la $a0, Array_length # load address of Array_length into $a0 syscall # print Array_length message li $v0, 5 # system call code for read integer syscall # read in the value of length int $v0 move $t0, $zero # clear $t0 to be added to add $t0, $v0, 0 # move $v0 to $t0 by adding
mul $a0, $v0, 4 # set memory to allocate based on input li $v0, 9 # system call code to allocate memory syscall # allocate memory for the array addiu $sp, $sp, -8 # Allocate 2 words sw $v0, 0($sp) # Store the array address sw $t0, 4($sp) # Store the array length jal read_array # jumps to read_array subprogram lw $t1, 4($sp) # Load the array length lw $t0, 0($sp) # Load the array address addiu $sp, $sp, 8 # Unallocate 2 words lw $ra, 0($sp) # Load the return address addiu $sp, $sp, 4 # Unallocate 1 word addiu $sp, $sp, -8 # Allocate 2 words sw $t0, 0($sp) # Store the array address sw $t1, 4($sp) # Store the array length jr $ra # jumps to previous program ###########################################################
########################################################### # Subprogram Description # Reads words into an array until the array is full
########################################################### # Arguments In and Out of subprogram # # $a0 # $a1 # $a2 # $a3 # $v0 # $v1 # $sp+0 Base address (IN) # $sp+4 Array length (IN) # $sp+8 # $sp+12 ########################################################### # Register Usage # $t0 - Array Address # $t1 - Array Length # $t2 - Index # $t3 - Offset adress to store values # $t4 - Offset for address # $t5 - Input value # $t6 # $t7 # $t8 # $t9 ########################################################### .data Prompt_value: .asciiz "Please input value: "
########################################################### .text read_array: # Read values into an array until the array is full lw $t0, 0($sp) # Load the array address lw $t1, 4($sp) # Load the array length li $t2, 0 # set starting index to 0 loop: bge $t2, $t1, end_loop # breaks loop when last index is passed mul $t4, $t2, 4 # sets offset to store the value add $t3, $t4, $t0 # sets the address to store the value
li $v0, 4 # system call code for print string la $a0, Prompt_value # load address of Prompt_value into $a0 syscall # print Prompt_value message li $v0, 5 # system call code for read integer syscall # read in the value of value int $v0 move $t5, $v0 # move value $v0 to $t5 sw $t5, ($t3) # store the value in the array add $t2, $t2, 1 # increment loop by 1 b loop # move to the top of the loop end_loop: jr $ra # Jumps to previous program ###########################################################
########################################################### # Subprogram Description # Prints words from an array, separated by spaces
########################################################### # Arguments In and Out of subprogram # # $a0 # $a1 # $a2 # $a3 # $v0 # $v1 # $sp+0 Base address (IN) # $sp+4 Array length (IN) # $sp+8 # $sp+12 ########################################################### # Register Usage # $t0 - Array Length # $t1 - Array Address # $t2 - Index # $t3 - Index Address # $t4 - Offset # $t5 - The value to be stored # $t6 - Last index check # $t7 # $t8 # $t9 ########################################################### .data Start_array: .asciiz "Your array: [" Comma: .asciiz ", " End_array: .asciiz "]\n" ########################################################### .text print_array: # Print all values from an array lw $t1, 0($sp) # Load the array address lw $t0, 4($sp) # Load the array length li $v0, 4 # system call code for print string la $a0, Start_array # load address of Start_array into $a0 syscall # print Start_array message
add $t6, $t0, -1 # -1 from for array length for clean print
li $t2, 0 # set starting index to 0 print_loop: bge $t2, $t0, end_print # breaks loop when last index is passed mul $t4, $t2, 4 # sets offset to laod the value add $t3, $t4, $t1 # sets the address to print the value from
li $v0, 1 # system call code for print integer lw $a0, ($t3) # load the value at address ($t3) syscall # print the value at index $t2 beq $t2, $t6, end_print # breaks loop when last index is passed
li $v0, 4 # system call code for print string la $a0, Comma # load address of Comma into $a0 syscall # print Commma message
add $t2, $t2, 1 # increment loop by 1 b print_loop # move to the top of the loop end_print: li $v0, 4 # system call code for print string la $a0, End_array # load address of End_array into $a0 syscall # print End_array message jr $ra # Jumps to previous program ###########################################################
########################################################### # Subprogram Description # Calculates the sum of an array #
########################################################### # Arguments In and Out of subprogram # # $a0 # $a1 # $a2 # $a3 # $v0 # $v1 # $sp+0 Base address (IN) # $sp+4 Array length (IN) # $sp+8 Array sum (OUT) # $sp+12 ########################################################### # Register Usage # $t0 - Array Address # $t1 - Array Length # $t2 - Index # $t3 - Address of value to add # $t4 - Offset to get value address # $t5 - Value loaded # $t6 - Sum # $t7 # $t8 # $t9 ########################################################### .data Array_sum: .asciiz "Sum of your array: " ########################################################### .text sum_array: # Sum of all values from the array lw $t0, 0($sp) # Load the array address lw $t1, 4($sp) # Load the array length li $v0, 4 # system call code for print string la $a0, Array_sum # load address of Start_array into $a0 syscall # print Start_array message
move $t2, $0 # set starting index to 0 move $t6, $0 # set starting sum to 0 sum_loop: bge $t2, $t1, end_sum # breaks loop when last index is passed mul $t4, $t2, 4 # sets offset to load the value add $t3, $t4, $t0 # sets the address to add the value from
lw $t5, ($t3) # load the value at address ($t3)
add $t6, $t6, $t5 # adds loaded int to the sum
add $t2, $t2, 1 # increment loop by 1 b sum_loop # move to the top of the loop end_sum: addiu $sp, $sp, -4 # Allocate 1 word sw $t6, 0($sp) # Store the sum
jr $ra # Jumps to previous program ###########################################################
Lab7.s
######################################### # Program Description # CS315 Lab 7 - Floating-points and arrays # # Do the following IN THIS ORDER: # # 1. Use make_double_array to create a first dynamic array # of doubles, store its base address and length in words # named myBaseHolder1 and myArrayLen1, respectively # # 2. Use make_double_array to create a second dynamic array # of doubles, store its base address and length in words # named myBaseHolder2 and myArrayLen2, respectively # # 3. Use read_double_array to read the first array # 4. Use read_double_array to read the second array # # 5. Use print_double_array to print the first array # 6. Use print_double_array to print the second array # # 7. Use inner_product to calculate the inner product of # the arrays # 8. Store the inner product in a variable called innerProd # 9. Print the inner product #
######################################### # Register Usage # $t0 # $t1 # $t2 # $t3 # $t4 # $t5 # $t6 # $t7 # $t8 # $t9 ######################################### .data myBaseHolder1: .word 0 myArrayLen1: .word 0 myBaseHolder2: .word 0 myArrayLen2: .word 0
Array_1: .asciiz "~~Array 1~~" Array_2: .asciiz "~~Array 2~~" Print_a1: .asciiz "Array 1: " Print_a2: .asciiz "Array 2: " Print_inner: .asciiz "Inner Product: "
# Put the words for the base addresses and lengths # in THIS DATA SECTION (other subprograms should not use # these labels, so don't put them with other subprograms)
######################################### .text main: li $v0, 4 # call code for print string la $a0, Array_1 # load Array_1 to print syscall # print Array_1 jal make_double_array # jump to make_double_array subprog la $t0, myBaseHolder1 # load address of myBaseHolder1 sw $v0, 0($t0) # save array address to myBaseHolder1 la $t0, myArrayLen1 # load address of myArrayLen1 sw $v1, 0($t0) # save length to myArrayLen1 li $v0, 4 # call code for print string la $a0, Array_2 # load Array_2 to print syscall # print Array_2 jal make_double_array # jump to make_double_array subprog la $t0, myBaseHolder2 # load address of myBaseHolder2 sw $v0, 0($t0) # save array address to myBaseHolder2 la $t0, myArrayLen2 # load address of myArrayLen2 sw $v1, 0($t0) # save length to myArrayLen2
li $v0, 4 # call code for print string la $a0, Array_1 # load Array_1 to print syscall # print Array_1 la $a0, myBaseHolder1 # load address of myBaseHolder1 lw $a0, 0($a0) # load array address from myBaseHolder1 la $a1, myArrayLen1 # load address of myArrayLen1 lw $a1, 0($a1) # load length form myArrayLen1 jal read_double_array # jump to read_double_array subprog li $v0, 4 # call code for print string la $a0, Array_2 # load Array_2 to print syscall # print Array_2 la $a0, myBaseHolder2 # load address of myBaseHolder2 lw $a0, 0($a0) # load array address from myBaseHolder2 la $a1, myArrayLen2 # load address of myArrayLen2 lw $a1, 0($a1) # load length form myArrayLen2 jal read_double_array # jump to read_double_array subprog li $v0, 4 # call code for print string la $a0, Print_a1 # load Print_a1 for print syscall # print Print_a1 la $a0, myBaseHolder1 # load address of myBaseHolder1 lw $a0, 0($a0) # load array address from myBaseHolder1 la $a1, myArrayLen1 # load address of myArrayLen1 lw $a1, 0($a1) # load length form myArrayLen1 jal print_double_array # jump to print_double_array subprog
li $v0, 4 # call code for print string la $a0, Print_a2 # load Print_a2 for print syscall # print Print_a2 la $a0, myBaseHolder2 # load address of myBaseHolder2 lw $a0, 0($a0) # load array address from myBaseHolder2 la $a1, myArrayLen2 # load address of myArrayLen2 lw $a1, 0($a1) # load length form myArrayLen2 jal print_double_array # jump to print_double_array subprog la $a0, myBaseHolder1 # load address of myBaseHolder1 lw $a0, 0($a0) # load array address from myBaseHolder1 la $a1, myArrayLen1 # load address of myArrayLen1 lw $a1, 0($a1) # load length form myArrayLen1 la $a2, myBaseHolder2 # load address of myBaseHolder2 lw $a2, 0($a2) # load array address from myBaseHolder2 la $a3, myArrayLen2 # load address of myArrayLen2 lw $a3, 0($a3) # load length form myArrayLen2 jal inner_product # jump to inner_product subprog
li $v0, 4 # system call code for print string la $a0, Print_inner # load Print_inner for printing syscall # print Print_inner
move $f12, $f0 # move $f12 to $f0 li $v0, 3 # call code for print double syscall # print inner product
li $v0, 10 # call code for exit syscall # Halt #########################################
######################################### # Subprogram Description # Ask the user for an array length, dynamically alocate # an array of doubles with the given length
######################################### # Arguments In and Out of subprogram # # $a0 # $a1 # $a2 # $a3 # $v0 Base address # $v1 Array length (number of elements) # $sp # $sp+4 # $sp+8 # $sp+12 ######################################### # Register Usage # $t0 # $t1 # $t2 # $t3 # $t4 # $t5 # $t6 # $t7 # $t8 # $t9 ######################################### .data Prompt_length: .asciiz "Enter length: "
# DO NOT put the words for the base addresses and lengths # in this data section (main uses them, so put them with # main)
######################################### .text make_double_array: # Ask user for an array length # Allocate an array of doubles with the given length li $v0, 4 # call code for print string la $a0, Prompt_length # load Prompt_length syscall # print 'enter length' li $v0, 5 # call code for read int syscall # read length move $v1, $v0 # Move length to $v1 for return sll $a0, $v0, 3 # $a0 = $v0 * 2^3 li $v0, 9 # call code for allocate memory syscall # allocate memory for array jr $ra #########################################
######################################### # Subprogram Description # Reads doubles into an array until the array is full
######################################### # Arguments In and Out of subprogram # # $a0 Base address (IN) # $a1 Array length (IN) # $a2 # $a3 # $v0 # $v1 # $sp # $sp+4 # $sp+8 # $sp+12 ######################################### # Register Usage # $t0 # $t1 # $t2 # $t3 # $t4 # $t5 # $t6 # $t7 # $t8 # $t9 ######################################### .data Prompt_value: .asciiz "Enter value: "
######################################### .text read_double_array: # Read doubles from the console, store them in # the array until the array is full move $t0, $a0 # move $a0 to $t0 move $t1, $a1 # move $a1 to $t1 read_loop: blez $t1, read_end # end when $t1 <= 0 li $v0, 4 # call code for print string la $a0, Prompt_value # load Prompt_value to print syscall # print Prompt_value li $v0, 7 # call code for read double syscall # read double s.d $f0, 0($t0) # store value to array addiu $t0, $t0, 8 # increment address to next index addiu $t1, $t1, -1 # decrement index b read_loop: # move to top of loop read_end: jr $ra #########################################
######################################### # Subprogram Description # Prints doubles from an array, separated by spaces
######################################### # Arguments In and Out of subprogram # # $a0 Base address (IN) # $a1 Array length (IN) # $a2 # $a3 # $v0 # $v1 # $sp # $sp+4 # $sp+8 # $sp+12 ######################################### # Register Usage # $t0 # $t1 # $t2 # $t3 # $t4 # $t5 # $t6 # $t7 # $t8 # $t9 ######################################### .data Space: .asciiz " " ######################################### .text print_double_array: # Prints doubles from an array, separated by spaces move $t0, $a0 # move $a0 to $t0 move $t1, $a1 # move $a1 to $t1 read_loop: blez $t1, read_end # end when $t1 <= 0 l.d $f12, 0($t0) # load value to print li $v0, 3 # call code for print double syscall # print value li $v0, 4 # call code for print string la $a0, Space # load Space to print syscall # print Space addiu $t0, $t0, 8 # increment address to next index addiu $t1, $t1, -1 # decrement index b read_loop: # move to top of loop read_end: jr $ra #########################################
######################################### # Subprogram Description # Calculates the inner product of two arrays or # prints an error and returns 0.0 if they are not # the same length # # The inner product is the sum of the products of # corresponding elements in two vectors # A[0]*B[0] + A[1]*B[1] + ... + A[n]*B[n] # # Example: # inner_product([1, 3, -5], [4, -2, -1]) = 3 # # The inner product is only defined for two vectors # of the same length # # 'Inner product' is sometimes called 'dot product' # or 'scalar product' # # http://en.wikipedia.org/wiki/Dot_product #
######################################### # Arguments In and Out of subprogram # # $a0 Base address of A (IN) # $a1 Array length of A (IN) # $a2 Base address of B (IN) # $a3 Array length of B (IN) # $v0 # $v1 # $f0|$f1 Inner product (OUT) # $sp # $sp+4 # $sp+8 # $sp+12 ######################################### # Register Usage # $t0 # $t1 # $t2 # $t3 # $t4 # $t5 # $t6 # $t7 # $t8 # $t9 ######################################### .data
######################################### .text inner_product: # Calculate the inner product of arrays A and B # I didn't ever have time to finish this lab jr $ra #########################################
Lab6.s
######################################### # Program Description # CS315 Lab 6 - Floating-point # # Ask the user for an array length # Create a dynamic array of double-precision # floating-point values of the given length # Call read_double_array to fill the array # Call print_double_array to print the array contents # Call get_sum_avg to get the sum and average # Print the sum and average #
######################################### # Register Usage # $t0 # $t1 # $t2 # $t3 # $t4 # $t5 # $t6 # $t7 # $t8 # $t9 ######################################### .data Prompt_length: .asciiz "Enter length: " Error_length: .asciiz "Invalid length." Average_array: .asciiz "Average: " Sum_array: .asciiz "Sum: "
arrayAddres: .word 0 # address of array arrayLength: .word 0 # length of array ######################################### .text main: li $v0, 4 # call code for print string la $a0, Prompt_length # load Prompt_length message syscall # print Prompt_length message li $v0, 5 # call code for read int syscall # read int
checkLength: bgtz $v0, contProg # continue program if length > 0 li $v0, 4 # call code for print string la $a0, Error_length # load Error_length message syscall # print Error_length message b main: contProg: la $a0, arrayLength # load address of arrayLength sw #v0, 0($a0) # store the array length mul $a0, $v0, 8 # multiply the length by 2 words li $v0, 9 # call code for allocating memory syscall # allocate array memory la $a0, arrayAddress # load address of arrayAddress sw $v0, 0($a0) # save address to arrayAddress la $a0, arrayAddress # load address of arrayAddress lw $a0, 0($a0) # load base address la $a1, arrayLength # load address of arrayLength lw $a1, 0($a1) # read length jal read_double_array # jump to read_double_array subprogram la $a0, arrayAddress # load address of arrayAddress lw $a0, 0($a0) # load base address la $a1, arrayLength # load address of arrayLength lw $a1, 0($a1) # read length jal print_double_array # jump to print_double_array subprogram la $a0, arrayAddress # load address of arrayAddress lw $a0, 0($a0) # load base address la $a1, arrayLength # load address of arrayLength lw $a1, 0($a1) # read length jal get_sum_avg # jump to get_sum_avg subprogram li $v0, 4 # call code for print string la $a0, sum_p # load Sum_array syscall # print Sum_array li $v0, 3 # call code for print double mov.d $f12, $f0 # move sum for print syscall # print sum li $v0, 4 # call code for print string la $a0, Average_array # load Average_array syscall # print Average_array li $v0, 3 # call code for print double mov.d $f12, 0($a0) # move sum for print syscall # print sum
li $v0, 10 # call code for quit syscall # Halt #########################################
######################################### # Subprogram Description # Prints an array of words
######################################### # Arguments In and Out of subprogram # # $a0 Base address (IN) # $a1 Array length (IN) # $a2 # $a3 # $v0 # $v1 # $sp # $sp+4 # $sp+8 # $sp+12 ######################################### # Register Usage # $t0 # $t1 # $t2 # $t3 # $t4 # $t5 # $t6 # $t7 # $t8 # $t9 ######################################### .data Print_array: .asciiz "Array: " Space: .asciiz " " ######################################### .text print_double_array: # Print doubles from the array, separated by a space move $t0, $a0 # move array address to $t0 move $t1, $a1 # move array address to $t1 li $v0, 4 # call code for print string la $a0, Print_array # load Print_array syscall # print Print_array print_loop: blez $t1, end_print # branch to end when last index is passed l.d $f12, 0($t0) # load value to print li $v0, 3 # call code for print double syscall # read double input li $v0, 4 # call code for print string la $a0, Space # load Space syscall # print Space addiu $t0, $t0, 8 # increment to next double address addiu $t1, $t1, -1 # decrement index by 1 b print_loop # branch to top of loop end_print: jr $ra # jump back to main program #########################################
######################################### # Subprogram Description # Reads words into an array
######################################### # Arguments In and Out of subprogram # # $a0 Base address (IN) # $a1 Array length (IN) # $a2 # $a3 # $v0 # $v1 # $sp # $sp+4 # $sp+8 # $sp+12 ######################################### # Register Usage # $t0 - address # $t1 - length # $t2 # $t3 # $t4 # $t5 # $t6 # $t7 # $t8 # $t9 # # $f0 - array element # $f1 - array element ######################################### .data Prompt_value .asciiz "Enter double: " ######################################### .text read_double_array: # Read doubles from the console, store them in # the array until the array is full move $t0, $a0 # move array address to $t0 move $t1, $a1 # move array address to $t1 loop: blez $t1, end_read # branch to end when last index is passed li $v0, 4 # call code for print string la $a0, Prompt_value # load Prompt_value syscall # print Prompt_value li $v0, 7 # call code for read double syscall # read double input s.d $f0, 0($t0) # Store double addiu $t0, $t0, 8 # increment to next double address addiu $t1, $t1, -1 # decrement index by 1 b loop # branch to top of loop end_read: jr $ra # jump back to main program #########################################
######################################### # Subprogram Description # Calculate sum and average of array
######################################### # Arguments In and Out of subprogram # # $a0 Base address (IN) # $a1 Array length (IN) # $a2 # $a3 # $v0 # $v1 # $f0|$f1 Sum (OUT) # $f2|$f3 Average (OUT) # $sp # $sp+4 # $sp+8 # $sp+12 ######################################### # Register Usage # $t0 # $t1 # $t2 # $t3 # $t4 # $t5 # $t6 # $t7 # $t8 # $t9 ######################################### .data
######################################### .text get_sum_avg: # Calculate and return the sum and average of # all elements in the array move $t0, $a0 # move array address to $t0 move $t1, $a1 # move array address to $t1 li.d $f0, 0.0 # initialize sum to 0 li.d $f2, 0.0 # initialize average to 0 mtc1 $t1, $f6 # move length to coprocessor 1 cvt.d.w $f6, $f6 # convert int length to double sum_avg_loop: blez $t1, esum_avg_end # branch to end when last index is passed l.d $f4, 0($t0) # load element and index $t1 add.d $f0, $f0, $f4 # add loaded value to sum addiu $t0, $t0, 8 # increment to next double address addiu $t1, $t1, -1 # decrement index by 1 b sum_avg_loop # branch to top of loop sum_avg_end: iv.d $f2, $f0, $f6 # divide sum by length to get the avg
jr $ra #########################################
Some Code Stuffs
Guys, so. I realy enjoy how MIPS assembly code looks. So I think I’m going to post each lab from this past semester once a week. I might start doing different days in different languages programming languages. You’ll see my first lab in a few minutes. What does everyone think?