How can I store back the value to memory so I can loop over them? I tried couple of times but it's not working. Unable to loop them. What can I do?
.data
'by rowmajor order'
mA: .float 1.5,2.5,3.5,4.5
'by rowmajor order'
mB: .float 5.5,6.5,7.5,8.5
'4 elements in resultant matrix mC, each 4 bytes'
mC: .float 0,0,0,0
space: .asciiz " "
.text
'a3 stores byte size of resultant matrix mC'
la $a3,mC
'a1 stores i/p matrix mA'
la $a1,mA
la $a2,mB
'a'
l.s $f1, 0($a1)
'b'
l.s $f2, 4($a1)
'c'
l.s $f3, 8($a1)
'd'
l.s $f4, 12($a1)
l.s $f5, 0($a2)
'e'
l.s $f6, 4($a2)
'f'
l.s $f7, 8($a2)
'g'
l.s $f8, 12($a2)
'Here using the Strassen's Algorithm for matrix multiplication
add.s $f0,$f1,$f4 #a+d
add.s $f9,$f5,$f8 #e+h
mul.s $f0, $f0,$f9 # p5
sub.s $f9,$f7,$f5 #ge
mul.s $f9,$f4,$f9 #d(ge)  p4
add.s $f10,$f1,$f2 # a+b
mul.s $f10,$f8,$f10 #h(a+b)  p2
sub.s $f11,$f2,$f4 # (bd)
add.s $f12,$f7,$f8 #(g+h)
mul.s $f13,$f11,$f12 #p6
add.s $f11, $f0,$f9 # p5+p4
add.s $f12,$f11,$f13 #p5+p4+p6
sub.s $f11,$f12,$f10 #p5+p4+p6p2
'Values stored in the first cell of the resultant matrix'
s.s $f11,0($a3)
#... p1,p2
sub.s $f13,$f6,$f8 # (fh)
mul.s $f12,$f13,$f1 #a(fh) $f12 p1
add.s $f13, $f12,$f10 # (p1+p2)
s.s $f13, 4($a3)
add.s $f14,$f3,$f4 # c+d
mul.s $f15,$f14,$f5 #e(c+d)
add.s $f14,$f15,$f9 #p3+p4
s.s $f14,8($a3)
sub.s $f16,$f1,$f3 '(ac)'
add.s $f17,$f5,$f6 '(e+f)'
mul.s $f16,$f16,$f17 '(ac)*(e+f)  p7'
add.s $f17,$f12,$f0 '(p1+p5)'
sub.s $f18,$f17,$f15 '(p1+p5p3)'
sub.s $f17,$f18,$f16 '(p1+p5p3p7)'
s.s $f17,12($a3)
'Print the resultant matrix'
li $t1,0
loop: beq $t1, 4, exit
'PUT YOUR CODE HERE TO PRINT THE RESULT MATRIX'
j loop
exit:
li $v0,10
syscall
See also questions close to this topic

How to translate an untidy list into a tidy data frame?
The data that I scraped online is structured in an odd way. I'm having trouble tidying this vector in to a data frame.
Below is a a chart depicting how the data flows through the vector, indicated by the arrows.
When converting the vector into a matrix, I'm struggling to think of an efficient way to do this. I can get the desired outcome by subsetting every 20 entries.
Reproducible code
c("+282", "331", "+295", "325", "+283", "352", "+270", "325", "+260", "320", "+270", "330", "+275", "340", "+265", "325", "+283", "352", "+270", "325", "+266", "311", "+280", "310", "+267", "330", "+260", "310", "+275", "350", "+265", "325", "+270", "330", "+250", "320", "+267", "330", "+260", "310")
** Working code to get desired outcome
as.data.frame(matrix(odds[1:20], ncol = 10, byrow = F)) as.data.frame(matrix(odds[21:40], ncol = 10, byrow = F))
In theory I could just bind these two dataframes together, however in my larger dataset I have a significant amount of subsets that would need to be done to complete this. What is the most efficient way to tackle this problem?

how to ignore values in a matrix?
I'm trying to get the sum of a row in a matrix, whilst ignoring the negative values. So far, I have
int main() { int matrix[n][l] = { {8, 4, 7,  2, 3}, {1, 8, 9}, {2, 8, 7, 9} }; int row, col, sum; for (row = 0; row < n; row++) { sum = 0; for (col = 0; col < l; col++) sum = sum + matrix[row][col]; cout << "Row sum " << row + 1 << " = " << sum << endl; } return 0; }
I've tried using
while(matrix>0) continue;
and it just ends up giving me junk in the output.

Matrix dropping the column names inconsistently in R
I have a small function called
foo
. When I run it withm0
, it correctly shows the column names. But when I use it withm1
,foo
omits all column names.Is there a fix for that?
library(lme4) library(Matrix) sng < read.csv('https://raw.githubusercontent.com/rnorouzian/e/master/sng.csv') m0 < lmer(y ~ A * B * C + (A * B * C  group), data = sng) m1 < lmer(y ~ A * B * C + (A * B * C  group), data = sng) foo < function(fit){ vc < VarCorr(fit) as.matrix(Matrix::bdiag(vc)) } # EXAMPLES OF USE: foo(m0) # SHOWS COLUMNAMES FINE :) foo(m1) # OMITS COLUMNNAMES ALL :(

MIPS Program that shows the lowest of 3 userinputted integers, doesn't register negative numbers
My code correctly manages to compile and it does find the lowest positive integers, but it can't seem to detect negative signs correctly. I think maybe I need to be using a signed command but I can't find whihc one may need to be changed. Any ideas?
.data prompt1: .asciiz "Enter an integer: " prompt2: .asciiz "Enter an integer: " prompt3: .asciiz "Enter an integer: " smallest: .asciiz "\nThe smallest integer is: " .text li $v0, 4 la $a0, prompt1 syscall li $v0, 5 syscall move $t0,$v0 li $v0, 4 la $a0, prompt2 syscall li $v0, 5 syscall move $t1,$v0 li $v0, 4 la $a0, prompt3 syscall li $v0, 5 syscall move $t2,$v0 blt $t1, $t0, Num1 move $t1, $t0 Num1: blt $t2, $t1, Num2 move $t2, $t1 Num2: li $v0, 4 la $a0, smallest syscall li $v0, 1 move $a0, $t1 syscall li $v0, 10 syscall

MIPS get the data from txt file
I have a .txt file that contain 64 hex number. My task now is to store those number into register to do calculation. For example:
0x3e77904b 0x4027e6e7 0x3f5de12d 0x3fc4137f 0x3e754280 0xbfaa1dd9
I know how to open, read, close the file
.data fileName: .asciiz "C:\Python\Python3832\64point.txt" fileWords: .space 1024 .text .globl main main: #Open file li $v0, 13 la $a0, fileName li $a1, 0 syscall move $s0, $v0 #Read file li $v0, 14 move $a0, $s0 la $a1, fileWords la $a2, 1024 syscall #Print li $v0, 4 la $a0, fileWords syscall #Close file li $v0, 16 move $a0, $s0 syscall li $v0, 10 syscall
Anyone has the idea how to do it? Thank you.

Trying to run this code in MIPS and i am getting an error saying "Runtime exception at 0x00400090: address out of range 0x00000008"
.text main: #Main function to be run la $a0, prompt li $v0, 4 syscall la $a0, n0 li $a1, 8 li $v0, 8 syscall move $t0, $v0 la $a0, n1 li $a1, 8 li $v0, 8 syscall move $t1, $v0 la $a0, n2 li $a1, 8 li $v0, 8 syscall move $t2, $v0 la $a0, n3 li $a1, 8 li $v0, 8 syscall move $t3, $v0 la $a0, n4 li $a1, 8 li $v0, 8 syscall move $t4, $v0 #Outputs la $a0, ($t0) li $v0, 8 syscall la $a0, ($t1) li $v0, 8 syscall la $a0, ($t2) li $v0, 8 syscall la $a0, ($t3) li $v0, 4 syscall la $a0, ($t4) li $v0, 4 syscall li $v0, 10 syscall .data prompt: .asciiz "Enter a series of 5 formulae:\n" #The prompt to ask the user to type 5 strings n0: .space 20 n1: .space 20 n2: .space 20 n3: .space 20 n4: .space 20

How does a computer convert from binary for printing on screen in decimal (especially arbitrary large numbers)
I have been wondering up until now of the following dilemma : everything computer sees and know are all in binary, for text and such they are stores in bytes and to print each character the computer just reference them, but what about numbers? (well each digit is ASCII but I don't mean that of course)
The point is that I want to know and understand the details of how when the computer sees 10000000000 it knows that it should print 4 digit with respectively 1,0,2 and 4 or any large number (arbitrary large or even a number so large that no one knows what to use for, or the biggest know prime number for the sake of science). We know that the computer sees only binary and that when we convert it to decimal for the computer it is still binary. That is why the process of converting it to decimal and print it for those who can't understand binary is what I yern to understand (and please I don't want any answers involving multiplications in binary base, I only want to know how it know how many digits it should print and to be able to get the sequence right and correctly and then print it)
I have search the internet up and down and still not manage to find an answer to satisfy my curiosities

what exactly is a variable under the hood in javascript?
I understand that a variable that is assigned with an object is actually a pointer(reference) to object. eg x=[1,2,3,4}, here x is a pointer to the memory location where the array is stored.
But when i assign a primitive value to a variable , x=16 or x="abc", what is 'x' under the hood? Is it also a pointer(reference) to the memory where 16 is stored ? in case x is a reference here, and if i say y=x then why is the value of x is copied to y? ( if its a reference then ,y=x is suppose to make y point to the same memory location where x is pointing to right?)

Write a function that finds the 10 most frequent vocabulary items in the Brown Corpus that are not stopwords
all. Math grad student. This is my first real foray into coding...
Here's what I have written:
lowerbrown = [w.lower() for w in brown.words()] stopwords = nltk.corpus.stopwords.words('english') notstopwords = [w for w in lowerbrown if w not in stopwords] cfd = nltk.ConditionalFreqDist( (genre, word) for genre in brown.categories() for word in notstopwords) genres = ['news', 'editorial', 'reviews', 'religion', 'hobbies', 'lore', 'belles_lettres', 'government', 'learned', 'fiction', 'mystery', 'science_fiction', 'adventure', 'romance', 'humor'] result = cfd() cfd[10:]
This is the result when compiled:
TypeError Traceback (most recent call last) <ipythoninput430b8092b42663> in <module> 9 genres = ['news', 'editorial', 'reviews', 'religion', 'hobbies', 'lore', 'belles_lettres', 'government', 'learned', 'fiction', 'mystery', 'science_fiction', 'adventure', 'romance', 'humor'] 10 > 11 result = cfd() 12 cfd[10:] TypeError: 'ConditionalFreqDist' object is not callable
I'm sure my code is just... a mess. But I would really appreciate some help with this.
Update: I looked at the solution for a similar question, and modified my code.
lowerbrown = [w.lower() for w in brown.words()] stopwords = nltk.corpus.stopwords.words('english') notstopwords = [w for w in lowerbrown if w not in stopwords] cfd = nltk.ConditionalFreqDist( (genre, word) for genre in brown.categories() for word in notstopwords) genres = brown.categories() cfd.tabulate(conditions=genres)
But I'm not sure of how to modify the code to only give me the ten most frequent vocabulary items.

Quicksort that sorts all elements except one, can't find bug
It's written in assembly (MIPS), translated from C. The array gets sorted properly with the expection of one element and it's always the same.\
Array to be sorted: 4 5 2 2 1 6 7 9 5 10
Output of quicksort: 1 2 2 4 5 6 7 9 5 10The 5 is the one which never moves. I have gone through the program stepbystep in MARS and I wasn't able to see the problem..
I thought it would be easier if I put the assembly code in one pastebin and the C code that I used to translate it into assembly.
Assembly: https://pastebin.ubuntu.com/p/54KkgrHY2Y/\ C equivalent: https://pastebin.ubuntu.com/p/NtmDGDyVFX/Would be very grateful if someone could see what I cannot and tell me, I've been stuck a long time.

MIPS: program that takes in user input values and calculates exponents using loops
So I have this whole program written out and my loops for calculating the exponents work in a program of their own but when i step through the program they are not running through multiple times the way that i want them to and the out put the program is giving is all 0s.
Here is the code: EDIT: Ive updated the code to what I have currently plus a division function in the end. Currently im getting the proper values for the first 3 loops sets. This means that i am getting the right value for f, but the second component of g which is d^w is not spitting out the right values.
##designed and written by Aidan RosserJones .data #data needed A : .word 0 B : .word 0 C : .word 0 D : .word 0 ## AD are the base values that the user inputs x : .word 8 y : .word 5 z : .word 7 w : .word 5 ## xw are the exponents with hardcoded student ID numbers userPrompt : .asciiz "Please enter four integers seperated by an enter key." ## prompting the user F : .asciiz "f(decimal) : " ## result for F in base 10 binaryF : .asciiz "f(binary) : " ## result for F in base 2 G : .asciiz "g(decimal) : " ## result for G in base 10 binaryG : .asciiz "g(binary) : " ## result for G in base 2 quotientH : .asciiz "h quotient : " ## quotient result for H remainderH : .asciiz "h remainder : " # remainder result for H skipLine : .asciiz "\n" ## for printing a new line .text ##switching back to code section .globl main main: #first we must prompt the user for the four integers la $a0, userPrompt #loading the prompt from data section into $a0 li $v0, 4 #syscall for printing a string syscall # this actually does the printing #now we gotta read the first integer li $v0, 5 syscall lw $s4, A #loading the address of variable a into $t0 move $s4, $v0 #copying the user input to $t0 #time to read the second integer (basically second verse, same as the first for the next 3) li $v0, 5 syscall lw $s5, B move $s5, $v0 #3rd integer li $v0, 5 syscall lw $s6, C move $s6, $v0 #4th integer li $v0, 5 syscall lw $s7, D move $s7, $v0 #time to do some calculations #calculating a^x move $t1, $s4 #loading address of A into $t1 ##lw $t1, ($t1) #loading the value of A into $t1 la $t2, x #loading address of x into $t2 lw $t2, ($t2) #loading the value of x into $t2 #loop prep move $t5, $t1 #answer = base move $t6, $t1 #increment = base li $t3, 1 # i = 1 li $t4, 1 # j = 1 For0: ble $t2, $t3, Exit0 #for(i =1; i<x; i++) addi $t3, $t3, 1 #i++ li $t4, 1 #resesting j to 1 so nested loop works properly move $t6, $t5 j For1 For1: ble $t1, $t4, For0 #for(j=1; j < A; j++) add $t5, $t5, $t6 #answer+=increment addi $t4, $t4, 1 #j++ j For1 Exit0: move $s0, $t5 #storing a^x in $s0 #calculating b^y move $t1, $s5 #loading address of B into $t1 ##lw $t1, ($t1) #loading the value of B into $t1 la $t2, y #loading address of y into $t2 lw $t2, ($t2) #loading the value of y into $t2 #loop prep move $t5, $t1 #answer = base move $t6, $t1 #increment = base li $t3, 1 # i = 1 li $t4, 1 # j = 1 For2: ble $t2, $t3, Exit1 #for(i =1; i<y; i++) addi $t3, $t3, 1 #i++ li $t4, 1 #resesting j to 1 so nested loop works properly move $t6, $t5 j For3 For3: ble $t1, $t4, For2 #for(j=1; j < B; j++) add $t5, $t5, $t6 #answer+=increment addi $t4, $t4, 1 #j++ j For3 Exit1: move $s1, $t5 #storing b^y in $s0 #calculating c^z move $t1, $s6 #loading address of C into $t1 ##lw $t1, ($t1) #loading the value of C into $t1 la $t2, z #loading address of z into $t2 lw $t2, ($t2) #loading the value of z into $t2 #loop prep move $t5, $t1 #answer = base move $t6, $t1 #increment = base li $t3, 1 # i = 1 li $t4, 1 # j = 1 For4: ble $t2, $t3, Exit2 #for(i =1; i<z; i++) addi $t3, $t3, 1 #i++ li $t4, 1 #resesting j to 1 so nested loop works properly move $t6, $t5 j For5 For5: ble $t1, $t4, For4 #for(j=1; j < c; j++) add $t5, $t5, $t6 #answer+=increment addi $t4, $t4, 1 #j++ j For5 Exit2: move $s2, $t5 #storing c^z in $s0 #calculating d^w move $t1, $s6 #loading address of D into $t1 ##lw $t1, ($t1) #loading the value of D into $t1 la $t2, w #loading address of w into $t2 lw $t2, ($t2) #loading the value of w into $t2 #loop prep move $t5, $t1 #answer = base move $t6, $t1 #increment = base li $t3, 1 # i = 1 li $t4, 1 # j = 1 For6: ble $t2, $t3, Exit3 #for(i =1; i<w; i++) addi $t3, $t3, 1 #i++ li $t4, 1 #resesting j to 1 so nested loop works properly move $t6, $t5 j For7 For7: ble $t1, $t4, For6 #for(j=1; j < D; j++) add $t5, $t5, $t6 #answer+=increment addi $t4, $t4, 1 #j++ j For7 Exit3: move $s3, $t5 #storing d^w in $s3 ##THIS IS FOR TESTING PURPOSES ONLY li $v0, 1 move $a0, $s3 syscall ##CONCLUDING TEST CODE #calculating and storing f = a^x + b^y add $s0, $s0, $s1 #f = $s0 #calculating and storing g = c^z + d^w add $s2, $s2, $s3 #g = $s2 #now lets print out all of the data, starting with a fresh line to avoid confusion! la $a0, skipLine li $v0, 4 syscall #skips a line #printing f la $a0, F li $v0, 4 syscall li $v0, 1 move $a0, $s0 syscall #print f in decimal #printing new line for organization la $a0, skipLine li $v0, 4 syscall #skips a line la $a0, binaryF li $v0, 4 syscall li $v0, 35 move $a0, $s0 syscall #this should print the binary f #printing new line for organization la $a0, skipLine li $v0, 4 syscall #skips a line #lets print g! la $a0, G li $v0, 4 syscall li $v0, 1 move $a0, $s2 syscall #this should print decimal g #printing new line for organization la $a0, skipLine li $v0, 4 syscall #skips a line #lets print g but binary this time! la $a0, binaryG li $v0, 4 syscall li $v0, 35 move $a0, $s2 syscall #now we must calculate h = f/g #division prep # f = $s0 # g = $s2 add $t0, $zero, $s0 #copies the value of f into $t0 add $t1, $zero, $s1 #copies the value of g into $t1 add $t2, $zero, $zero #make $t2 the counter starting at 0 div_loop: sle $t3, $t2, $t1 #checks if equal beq $t3, $zero, end_divis sub $t0, $t0, $t1 addi $t2, $t2, 1 j div_loop end_divis: move $s6, $t2 # stores quotient in $s6 move $s7, $t0 # stores remainder in $s7 #now its time to print the values for h #printing new line for organization la $a0, skipLine li $v0, 4 syscall #skips a line la $a0, quotientH li $v0, 4 syscall # prints quotientH string li $v0, 1 move $a0, $s6 syscall #print integer value for quotient H #printing new line for organization la $a0, skipLine li $v0, 4 syscall #skips a line la $a0, remainderH li $v0, 4 syscall #print remainder H string li $v0, 1 move $a0, $s7 syscall #print integer value for remainder H #terminate the program li $v0, 10 syscall
If some of the comments are off I apologize. I copy and pasted the loops and then changed where the calculations were stored and the loop names for jumping purposes to achieve the functionality needed.
Currently my output looks like this:
Please enter four integers seperated by an enter key.2 3 1 2 1 (THIS IS A TEST PRINT FOR THE VALUE OF d^w) f(decimal) : 499 f(binary) : 00000000000000000000000111110011 g(decimal) : 2 g(binary) : 00000000000000000000000000000010 h quotient : 244 h remainder : 58793  program is finished running 
As previously stated the problem has something to do with my loops but I've been staring at it for awhile now and cannot figure out whats up. Any help would be greatly appreciated as I have been learning MIPS for less than a week now.
And for reference the loops were modeled after this Java code I wrote:
/* * Written by Aidan RosserJones */ public class exponentLoop { public static final int BASE = 5; public static final int POWER = 6; public static void main(String[] args) { int answer = BASE; int increment = BASE; for(int i = 1; i < POWER; i++) { for(int j = 1; j < BASE; j++) { answer += increment; } increment = answer; } System.out.println(answer); } }
**For this project we arent allowed to use any sort of multiplication instruction or functions, thats why the code is formatted the way it is

In MIPS I need programs that will calculate exponents using repeated addition, and one that can solve division using repeated subtraction
Code for Exponents:
.data a: .word 5 #base B: .word 6 # power .globl main main: lw $s0, a # $s0 = a lw $s1, B # $s0 = B li $s3, 1 # i = 1 li $s4, 1 # j = 1 move $t0, $s0 # answer = base move $s1, $t0 # increment = base For1: blt $s1, $s3, Exit #for(i=1; i < B; i++) addi $s3, $s3, 1 #i++ li $s4, 1 # resets j to 1 move $t0, $t1 j For2 For2: blt $s0, $s4, For1 #for(j=1; j <a; j++) add $t0, $t0, $t1 addi $s4, $s4, 1 j For2 Exit: li $v0, 1 move $a0, $t0 syscall li $v0, 10 syscall
Code for Division:
.data a: .word 1562 B: .word 7 space: .asciiz "\n" .globl main main: lw $s0, a lw $s1, B add $t1, $zero, $s0 #make copy of first integer value in $s0 add $t2, $zero, $s1 #make copy of second integer value in $s1 add $t0, $zero, $zero #make $t0 the counter div_loop: sle $t3, $t2, $t1 #checks if equal beq $t3, $zero, end_divis sub $t1, $t1, $t2 addi $t0, 1 j div_loop end_divis: move $s5, $t0 move $s6, $t1 li $v0, 1 move $a0, $s5 syscall addi $v0, $zero, 4 la $a0, space syscall li $v0, 1 move $a0, $s6 syscall li $v0, 10 syscall
I modeled both of these off of Java programs i wrote that perform the same functions but i am getting a "program is finished running (dropped off bottom) error on them both as well as a Mars message saying "Go: execution terminated by null instruction"
I the exponents program to print the answer and the division program to print both the quotient and the remainder.
EDIT: Added in termination code, when ran in Step mode i errors out with the same error immediately.
I am very new to Assembly so any help would be incredible.
Thanks
EDIT2: This is the java code I am attempting to translate from EDIT3: Division Code is now functioning properly java code for exponents:
public class exponentLoop { public static final int BASE = 5; public static final int POWER = 6; public static void main(String[] args) { int answer = BASE; int increment = BASE; for(int i = 1; i < POWER; i++) { for(int j = 1; j < BASE; j++) { answer += increment; } increment = answer; } System.out.println(answer); } }
Java code for division
public class divLoopTest { public static final int F = 1562; public static final int G = 7; public static void main(String[] args) { int result = 0; int rest = F; while(rest >= G) { rest = rest  G; result ++; } System.out.println("result = "+result); System.out.println("remainder = "+rest); } }