Determine min and max in the array using mips assembly language
I am trying to write a program that determines the minimum and the maximum element in the array when numbers are given . this is what I have so far: a second opinion is much appreciated.
.text
.globl main
main :
ori $3 , $0 , 1 # $3 is the count , initialized to be 1
lui $4 , 0 x1000 # $4 holds the address of the size
lw $5 , 0( $4 ) # $5 holds the size of the array
addiu $4 , $4 , 4 # $4 holds the address of the first array element
lw $6 , 0( $4 ) # load the first element in $6
sll $0 , $0 , 0 # load delay
or $11 , $6 , $0 # $11 holds the max , initialized to be the 1 st element
loop :
beq $3 , $5 , endlp # if the count == size , terminate the loop
sll $0 , $0 , 0 # branch delay
addiu $4 , $4 , 4 # $4 holds the address of the next element
lw $7 , 0( $4 ) # load the next element in $7
sll $0 , $0 , 0 # load delay
slt $8 , $11 , $7 # $8 holds 1 if $11 < $7 , and holds 0 otherwise
beq $8 , $0 , incCount # if $8 ==0 , jump to incCount ,
sll $0 , $0 , 0 # branch delay
or $11 , $7 , $0 # update the value in $11
incCount :
addiu $3 , $3 , 1 # increment the count by 1
j loop
endlp : sll $0 , $0 , 0
. data
size : . word 8
array : . word 24 , 19 , 44 , 32 , 52 , 47 , 7 , 11
See also questions close to this topic

Difference between arr[index] and calling the variable equal to arr[index]
This question regards whether python treats its "names" as pointers or references, which I have yet to find a clear explanation for.
Consider the following scenario:
L = [[][]] L1 = L[1] L1 = [1] # Interested in what happens after this line print L # L = [[], []]
However, if we change the above line of interest to L[1] = [1], namely the code block below:
L = [[][]] L1 = L[1] L[1] = [1] # Interested in what happens after this line print L # L = [[], [1]]
The above the code blocks only differ by the third line, where we use L[1] (indexing the array directly) or L1 (the variable which we assigned as L1 = L[1]).
So what are L1 and L[1] in essence? What's the difference? Is one of them reference, and the other not?
Thanks for addressing this confusion!

Multiple ForEach with Arrays in Powershell
I am trying to generate two data files (first for each) and generate just one document to each file (second for each). I can generate the two data files just fine, however, it creates 2 documents and assigns it to each file. I just need it to assign one document to one file, then the other document to another file. I've struggled and haven't been able to come up with a solution (novice developer). What can I do to accomplish this?
$filepath="C:\files\pdf\" $data_files = GetChildItem $filepath $filesss=$data_files  WriteOutput $Data2= $filesss split "`n" $i2=0 foreach ($item2 in $Data2) { $headers = NewObject "System.Collections.Generic.Dictionary[[String],[String]]" $headers.Add("Accept", 'application/pdf') $fileName="C:\files\pdf\$item2" $fileContent = getcontent Raw $fileName $fileContentBytes = [System.Text.Encoding]::Default.GetBytes($fileContent) $fileContentEncoded = [System.Convert]::ToBase64String($fileContentBytes) $gravy= GetContent "C:\files\temp.txt" $ia=0 $data44=@{} foreach($id in $gravy){ $data44= ConvertToJson @{ encrypted="false"; allowSaveBinaryData="true"; binaryData="$fileContentEncoded" divider="Expense Report"; extension="pdf"; name="$fileContentEncoded"; relProjectId="31"; } $var2[$i2]="https://XXXXXXX.com/v4/documents/$id/?guid=$AUTHtemp&fbsite=https://API/" InvokeRestMethod headers $headers ContentType 'application/json' Method PUT body $data44 Uri $var2 }$ia++} $i2++

How can I match array in php?
I have 2 arrays, I want match this arrays and get results with keys. Can I search in first array with second array keys or match diffrent way?
$boardLists = [ [ '_id' => 'a1a1a1', 'name' => 'Board Name #1', 'code' => 'B1' ], [ '_id' => 'b2b2b2', 'name' => 'Board Name #2', 'code' => 'B2 ] ];
and
$boards = [ 'a1a1a1', 'b2b2b2', 'c3c3c3' ];
My result with array_intersect:
array(1) { [0]=> string(6) "a1a1a1" }
My expected result if match 'a1a1a1':
[ '_id' => 'a1a1a1', 'name' => 'Board Name #1', 'code' => 'B1' ],

MSVC inline assembly to GCC (with parameter and return)
inline float sqrt2(float sqr) { float root = 0; __asm { sqrtss xmm0, sqr movss root, xmm0 } return root; }
here is MSVC compilator inline assembly which I want to compile with gcc x86, what I know that gcc inline assembly is getting called with asm("asm here"); but I completely don't know how to include parameter in that, the result is obtained by "=r" I know only.
Which should result in something like that:
asm("sqrtss xmm0, %1\n\t" "movss %0, xmm0" : "=r" (root) : "r" (sqr));

PIC16F877A ADC in assembly: Howto show result on 7 segment display
I am trying to perform analog to digital conversion on PIC16f877a. well the problem is when I am showing my result on led it working fine but when I am showing my result on 7 segment I have some invalid output may be I am unable to convert binary to decimal properly ("for BCD conversion I am using 74ls47") can any one help me. Regards, Haziq.
image is here. enter image description here
RES_VECT CODE 0x0000 ; processor reset vector GOTO START ; go to beginning of program ; TODO ADD INTERRUPTS HERE IF USED CNT0 EQU 0x21 ; MAIN_PROG CODE ; let linker place main program START BSF STATUS,RP0 MOVLW b'00000000' MOVWF TRISB MOVLW b'11110000' MOVWF TRISD MOVLW b'00000001' MOVWF TRISA BCF STATUS,5 MAIN_LOOP CALL ADC_INIT ;INIT ADC MODULE CALL ADC_READ ;READ ANALOG VALUE AND STORE TO ANVAL REGISTER ;OUTPUT ANVAL TO ;================================== GOTO MAIN_LOOP ;======================================================================================== ADC_INIT BSF STATUS,RP0 ;SELECTING BANK 01 FOR ADCON1 REG MOVLW b'00001110' ;LEFT JUSTIFIED, FOcs/8, +VREF=VDD, VREF=VSS, AN0=ANALOG MOVWF ADCON1 BCF STATUS,5 ;GOING BACK TO BANK 00 MOVLW b'010000001' ;FOcs/8, A0=ANALOG INPUT, MOVWF ADCON0 RETURN ;========================================================================================= ADC_READ BCF STATUS,5 ;SELECTING BANK 00 BSF ADCON0, 2 ;START CONVERTION PROCESS (WE SET THE GO BIT) WAIT: BTFSC ADCON0, 2 GOTO WAIT ;WAIT FOR CONVERTION TO FINISH (WAIT FOR GO BIT TO CLEAR) MOVF ADRESH, W ;MOVE ADRESH TO W MOVWF PORTB ;SHOWING 8 MOST SIGNIFICANT BITS OF A/D RESULT MOVLW 0x06 MOVWF CNT0 AGAIN_0: BCF STATUS, C ;WE WANT SHIFT (NOT ROTATE), SO WE CLEAR CARRY RLF ADRESL, 1 ;SHIFT LEFT 6 BITS A/D RESULT HIGH BYTE DECFSZ CNT0 GOTO AGAIN_0 MOVF ADRESL, W ;MOVE ADRESH TO W MOVWF PORTD ;SHOWING 2 LEAST SIGNIFICANT BITS OF A/D RESULT RETURN END

Adaptive sorting algorithms versus sorting networks for sorting a list of 32 random elements
If we are using a sequential machine (parallell comparisons is not possible) where comparisons are made in sequence and and we are looking to minimize the number of processor clock cycles when sorting 32 random elements, should we use a sorting network or an adaptive sorting algorithm?
There are no optimal networks (yet) for n=32 elements. In practical terms, if we want to minimize the number of CPU clock cycles, is it best to divide 32 elements into four sublists of n=8 and apply the optimal sorting network on each sublist, then merge the lists together?
We are obviously working with "average performance" here, because adaptive algorithms can get lucky if we are given an already sorted list.
Crunching the numbers we have the following:
Sorting a list of size n:
Minimum number of comparisons for n=2 is 1.
Minimum number of comparisons for n=4 is 5.
Minimum number of comparisons for n=8 is 19.
Mergin two lists of size n:
Merge two lists of n=2 is 2*n  1 = 3 comparisons
Merge two lists of n=4 is 2*n  1 = 7 comparisons
Merge two lists of n=8 is 2*n  1 = 15 comparisons.
Merge two lists of n=16 is 2*n  1 = 31 comparisons.
Total number of comparisons if we divide n=32 into sixteen n=2 sublists:
 Sorting: 1*16 = 16
 Merge: 3*8 + 7*4 + 15*2 + 31*1 = 113
 Total: 129
Total number of comparisons if we divide n=32 into eight n=4 sublists:
 Sorting: 5*8 = 40
 Merge: 7*4 + 15*2 + 31*1 = 89
 Total: 129
Total number of comparisons if we divide n=32 into four n=8 sublists:
 Sorting: 19*4 = 76
 Merge: 15*2 + 31*1 = 61
 Total: 137
Now one might think it would be better to divide the n=32 elements into n=2 or n=4 sublists since the total number of comparisons is smaller. But mergin requires storing parts of the array "outofplace" which might negate the benefit of less comparisons?
My gut feeling tells me that on average the nonadaptive sorting network is similar to an algorithm in terms of total comparisons but the sorting network wins due to less overhead, am I right?
I am trying to sort n=32 elements in less than 1200 clock cycles on average. I am working on a simple sequential machine with a simple 256 words * 16bit memory and only four registers, so the network/algorithm has to be simple, fast and not require a lot of space. The ALU only has adding, subtracting, one bit shift, one bit rotating, AND, and OR functionality. Memory and ALU operations take a single clock cycle each.

MIPS array assign infinity loop
I am trying to fix this problem for hours!!!!! When I enter 8 integers for the array and then enter 0 to finish reading, when the loop section starts it goes to infinity loop!! I can't find where's the problem, when I remove the
addiu
from the$s2
array it works fine but doesn't store the$t1
on the array!Please HELP!!
.data array: .space 32 percentage_Array: .space 32 newLine: .asciiz "\n" .text main: la $s1, array la $s2, percentage_Array read_numbers: li $v0, 5 syscall sw $v0, 0($s1) addiu $s1, $s1, 4 beqz $v0, continue j read_numbers continue: la $s1, array loop: lw $t0, 0($s1) addiu $s1, $s1, 4 beqz $t0, exit move $a1, $t0 jal calculate_Ones_and_Bits move $s6, $v0 move $s7, $v1 #put the total number of ones add $s0, $s0, $s7 #calculate the percentage addi $t5, $zero, 100 mult $s7, $t5 mflo $t1 div $t1, $s6 mflo $t1 #I THINK HERE IS MY PROBLEM #Put the percentages on percentage_Array array sw $a1, 0($s2) addiu $s2, $s2, 4 #Check which percentages are greater than 50 and print the numbers which fulfill the condition slti $t2, $t1, 50 beq $t2, 1, loop li $v0, 1 move $a0, $t0 syscall #lines 66,67,68 are extra just for printing in new line more clearly li $v0, 4 la $a0, newLine syscall j loop exit: #lines 73,74,75 are also extra just to print the value of s0, it is printed here so it #will be executed after the loop has finished li $v0, 1 move $a0, $s0 syscall #tell the OS to exit/finish li $v0, 10 syscall

C code to MIPS  arrays
I've just started learning about all this computer science stuff. One thing I find difficult is writing MIPS instruction when given a line of C code containing arrays. I understand the stack pointer and how memory works (to an extent), but I want to make sure I'm getting this right. The question is
A[2]=A[0] $s0 holds the base address of A.
I've only had practice with arrays that use
i
instead of integers, so this is a bit strange to me. Would alw
command with an offset of 2 then asw
command that stores that into thearray[0]
work? If someone could help me figure out the command sequence I need I would appreciate it. 
Issue with converting C++ Leap Year to MIPS Assembly?
I am trying to convert this chunk of C++ code to assembly.
if (Month == 1) //Subtract 1 if January { if (Year % 4 == 0) { if (Year % 100 == 0) { if (Year % 400 == 0) { Total = Total  1; } } else { Total = Total  1; } } } if (Month == 2) //Subtract 1 if February { if (Year % 4 == 0) { if (Year % 100 == 0) { if (Year % 400 == 0) { Total = Total  1; } } else { Total = Total  1; } } }
I have found two different ways to check for leap years. This one above I thought would be the easiest to convert to MIPS, but when I tried to make it in MIPS, it either skips the loop, or takes it off twice and I am not sure why.
Here is my MIPS code.
lb $t3, LFour #Load byte 4, for mod later div $s5, $t3 # Year $ 4 MFHI $s5 #Move from high, get remainder for mod math lb $t5, LHundred #Load byte, 100, to divide year/100 div $s6, $t5 #Divide year / 100 MFHI $s6 #Move from hgih, get remainder from year % 100 lb $t3, LFourHundred #Load byte 400, for mod later div $t6, $t3 #Year % 400 MFHI $t6 #Move from high, get remainder from Year %400 #$t0 = month beq $t0, 1, IfMonthOne #If (Month == 2) j ElseOtherOne IfMonthOne: beq $s5, 0, IfMonthTwo #Of (Year % 4 == 0) j Wrong IfMonthTwo: beq $s6, 0, IfMonthThree #If ( Year % 100 == 0) subi $s0, $s0, 1 IfMonthThree: beq $t6, 0, IfMonthFour #If (Year % 400 == 0) j Wrong IfMonthFour: subi $s0, $s0, 1 #Total = Total  1 ElseOtherOne: beq $t0, 2, IfMonthTwenty #IF (Month == 2) j Wrong IfMonthTwenty: beq $s5, 0, IfMonthTwentyOne #If (Year % 4 == 0) j Wrong IfMonthTwentyOne: beq $s6, 0, IfMonthTwentyTwo #If ( Year % 100 == 0) subi $s0, $s0, 1 IfMonthTwentyTwo: beq $t6, 0, IfMonthTwentyFour #If (Year % 400 == 0) j Wrong IfMonthTwentyFour: subi $s0, $s0, 1 #Total = Total  1 Wrong: addi $s0, $s0, 0
$t0 is = to the Month, and Year is = $s5, $s6, $t6. I used addi to add what I am storing the year in, just to save the year into all those variables because I still use the Year later on, so I didn't want to erase it.
Another way I thought of doing the leap year is this:
if ((Year % 4 == 0 && Year % 100 != 0)  (Year % 400 == 0)) { Total = Total  1; }
I am new to MIPS, so I know those variables I saved don't really make sense, and when I got 3/4 of this done, I realized that it was not correct, but I will go back later and fix that, for now I just want to get the leap year to work. So my question is, what is wrong with my MIPS loop, and why won't it subtract one even though the year is a leap year and it fits all the conditions?

SPIM program crashes when loaded into QtSpim
I am trying to write this sequence into a MIPS program: http://oeis.org/A093878 I "presumably" finished the program (i don't know if it's correct or not), but when trying to run it on QtSpim to verify it crashes the program without any sort of error message, what could it be? The program asks for you to insert a number from 1 to 100, throws the input into the function and then prints out the result: http://oeis.org/A093878/b093878.txt (list of inputs and results)
.data msg: .asciiz "Input a number from 1 to 100: " .text .globl main main: #prints the message to input the number li $v0, 4 la $a0, msg syscall #receives the number li $v0, 5 syscall #sends the variable to $a0, which servers as the function parameter move $t0, $v0 move $a0, $t0 add $a1, $a0, $zero #calls the function jal function #moves the result value to $a0 to be printed move $t0, $v0 move $a0, $t0 #prints the result value li $v0, 1 syscall #exits the program li $v0, 10 syscall function: #initializes the function addi $sp, $sp, 8 sw $s0, 0($sp) sw $s1, 4($sp) # test if the variable is less than 3, returns 1 if true slti $t1, $a0, 3 beq $t1, 1, oneortwo #first part of the function addi $a0, $a0, 1 add $v0, $a0, $zero jal function move $t0, $v0 move $a0, $t0 jal function move $t0, $v0 move $a0, $t0 jal function add $s0, $v0, $zero add $a0, $a1, $zero addi $a0, $a0, 1 #second part of the function (after the +) add $v0, $a0, $zero jal function move $t0, $v0 move $a0, $t0 jal function move $t0, $v0 move $a0, $t0 sub $a0, $a1, $a0 jal function add $s1, $v0, $zero #sums the two values add $v0, $s0, $s1 lw $s0, 0($sp) lw $s1, 4($sp) addi $sp, $sp, 8 jr $ra #jumps here if the variable is less than 3 oneortwo: addi $s0, $zero, 1 add $v0, $s0, $zero lw $s0, 0($sp) lw $s1, 4($sp) addi $sp, $sp, 8 jr $ra

rol pseudoinstruction MIPS code
The instructions is:
rol $t0, $t1, n rolv $t0, $t1, $t2
n: 1bit 31bit
Is this correct translation of the above instructions?
srl $t1, $s1, 1 sll $t2, $s1, 31 or $s2, $t1, $t2 #combine_words

MIPS while loop with overflow
I want to know if it is possible to implement a while loop with overflow.
Suppose I made a function called test that tests for overflow and branches to either
overflow (returns 1)
or no_overflow(returns 0).
In this While loop we want to print variables in a Fibonacci sequence where the loop stops if there is overflow.
This loop is in the main routine of the program, so it calls the fib function and the test function( as you know this one branches out). Thi function returns the Fibonacci number.
what would be the pseudocode or code to make this loop work?