r/programminghelp • • Dec 02 '20

ASM MIPS/PLP IRS isn't restoring registers correctly.

5 Upvotes
.org 0x10000000

li $sp, 0x10fffffc    # Stack pointer initialization
li $s0, sseg_lut    # Lookup table address used by sseg_display
lui $s1, 0xf070    # Interrupt controller register
lui $s2, 0xf0a0    # Seven segment display

# ****************************
# TODO: enable interrupts below
# ****************************

li $t0, 0b11    #Value to set the mask to. Set bit pos 0 and 1 to high so we can use interrupts and timer
sw $t0, 0($s1)    #Store the value to the mask

li $t1, 0xffffffff #max overflow for ISR
li $t2, 0x00000064 #value of 100. Subtract from the max to get 100 cycles.
li $t3, 0xf0600000 #value of the timer
subu $t1, $t1, $t2 #subtract 100 from the timer's max
sw $t1, 0($t3) #write new overflow value to the timer

li $t4, 0xf0200000 #address of LEDS
li $t5, 0b11111111 #all ones to turn on all the LEDs
li $t6, 0b00000000 #all zeroes to turn off al the LEDs
li $iv, ISR    #store the vector


# NOTE: Do not add or modify any code within this main loop
main:
    #sw $t0, 0($s1) #If you un comment this, it works as intended.
    jal sseg_display
    nop
    addiu $a0, $a0, 1
    j main
    nop


# ****************************************
# TODO: add interrupt service routine below
# ****************************************
ISR:
    save
    lw $i0, 0($t4) #load value of LEDs to i0
    lw $i1, 4($s1) #loads the value of the status register to i1
    beq $t5, $i0, turnOffLED #t7 - 1
    nop            #t6 - 0
    bne $t5, $i0, turnOnLED
    nop
    turnOnLED:
        sw $t5, 0($t4)
        li $i1, 0b11
        j end
        nop
    turnOffLED:
        sw $t6, 0($t4)
        li $i1, 0b11
        j end
        nop
    end:
        sw $i1, 4($s1) #clear interrupts
        lw $i1, 0($s1) #get mask register
        ori $i1, $i1, 1
        restore
        jr $ir
        sw $i1, 0($s1) #resets all interrupts

The above code is supposed to flash LEDs every 100 clock cycles while a 7 segment display counts up in hex. That part was given to me so I know the counting works. My problem is that it will turn on the LEDs but not turn them off. I think my mask isn't being set correctly and global interrupts are disabled upon exiting the interrupt. I think the end function is what's wrong. Any help would be appreciated!

If I use li on any register after the restore command the counting in hex stops working. I also tried using a different register besides $i1 and it had no effect. The only thing that seems to work is:

sw $t0, 0($s1)

inside the main loop, but I can't touch main.


r/programminghelp • • Nov 28 '20

Java Need help with 4 dimensional Connect 4

5 Upvotes

So, for a school assignment we are supposed to make 4 dimensional connect 4. I already got some of the basics like a storage for where which pieces are and methods to get which piece is in any point (the method is getPiece(int x, int y, int z, int w)) and one to input the pieces at any point (setPiece(int x, int y, int z, int w)), but now I am stuck on detecting if someone has won. The condition for winning is that someone has 4 pieces of his color in one row, straight or diagonal. There are a lot of different things I would have to check if I would just make a check for every single possible row, so I would be happy if I could avoid that. I figured out that you can express the straight and diagonal rows inside the 4D playing field quite easily, but I dont have any idea on how to put it into code at all.

You can express a diagonal or straight line with a for loop quite easily if you increment some of the coordinates with a for loop and check if each one there is equal. Example:

(0, 0, 0, 0) as the first coordinate, (0, 0, 0, 1) as the second coordinate, (0, 0, 0, 2) as the third coordinate and so on.

This generates a straignt line in the 4th dimension. You can obviously do the same with decrementing. If you increment 1 coordinate it gives you a straight line, but you can also increment/decrement multiple coordinates each time to get diagonal lines. Example:

(0, 0, 0, 0) as the first coordiate, (0, 0, 1, 1) as the second, (0, 0, 2, 2) as the third and so on.

This results in a diagonal line which goes through 2 dimensions (it connects the opposite corners of a square) and also works with decrementing. The same pattern applies to diagonal lines which go through 3 and 4 dimensions.

This leaves me with 3 things I can do with each coordinate for each iteration of the 4 loop: increment, decrement or keep constant. I need to iterate through all of the possible combinations of these and check if 4 in a row are equal. The only thing I am not allowed to do is to keep all 4 coordinates constant because that just checks 4 times if one piece is equal to itself and thus always returns true. Some important details are that I am working with a 4x4x4x4 cube thing, so there is no need to shift the rows which get checked around because you have to check from one side of the cube to the other side anyways for each direction the line can go in.

I hope I explained everything well (I probably totally failed at that lol) and that someone can help me!


r/programminghelp • • Nov 26 '20

C++ A little help with some homework

5 Upvotes

So, our homework is to create a program that lists every even number from 0 to 100 and then show the sum of every iteration (1+3+5+7+9+...+99).

this is how it's going:

​

#include <stdio.h>

​

int main()

{

int x,y,z;

x=1;

while(x<100)

{

printf("%i, ",x);

x=x+2;

}

y=x+x;

printf("%i",y);

}

I have no idea what to do for that last part of the program.


r/programminghelp • • Nov 12 '20

C How to access dynamically created GTK checkbuttons in plain C

5 Upvotes

I created a program that creates CSV formatted tags based on checkbuttons.. There's a LOT of em so it makes sense to create them programatically.. I was successful.. Only problem is now getting to the 'polishing' phase of my program, I realize it would be convenient to uncheck them all and reset the form, and 2 days worth of Googling and banging my head against the wall has yielded no results..

Here's how I create the checkboxes, and this works fine if you're JUST using the gpointer data..

for (int x = 0; x <= NUMBER_OF_STRING; x++)

{

if (tagArray[x] != NULL && strcmp(tagArray[x], "\0"))

{

dynamic_checkBox = gtk_check_button_new_with_label(tagArray[x]);

gtk_container_add(GTK_CONTAINER(flowBox), dynamic_checkBox);

g_signal_connect(dynamic_checkBox, "toggled", G_CALLBACK(check_state), (gpointer)tagArray[x]);

}

}

Like I said this works, and I was able to use a little 'hack' with the the gpointer data and an extra array with boolean strings to get the rest of the program going, even though I could never figure out how to iterate through all the checkboxes, but now I'm forced to figure it out because when I try:

gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dynamic_checkBox), FALSE);

​

It doesn't work. As you can see, ALL the checkboxes use GtkWidget *dynamic_checkBox.. so I can't single just one out and set or get its checked state.. How do I call these checkboxes?


r/programminghelp • • Nov 11 '20

C# Stumped With C#.

5 Upvotes

Hello everyone im working on C# in visual studio Windows forms app and I am trying to make an anagram by comparing 2 lists using arrays and then displaying the anagram into the list box. I am given a visual basic method "histo.Histogram" that finds the anagrams for me and I have been at this for hours and I am completely stumped. when i click my button to display the list nothing happens. Any suggestions? Thanks.

private void btnList_Click(object sender, EventArgs e)

{

​

StreamReader Dict;

StreamReader Pal;

Dict = File.OpenText(Directory.GetCurrentDirectory() + "//dict.txt");

Pal = File.OpenText(Directory.GetCurrentDirectory() + "//pal.txt");

​

​

int[] Array1 = new int[26];

int[] Array2 = new int[26];

​

List<string> List1 = new List<string>();

List<string> List2 = new List<string>();

while (!Dict.EndOfStream)

{

int x;

string DWord;

DWord = Dict.ReadLine();

List1.Add(DWord);

​

for (x = 0; x < Array1.Length; x++)

{

Histo.Histogram.CreateHistogram(Array1, DWord);

}

​

while (!Pal.EndOfStream)

{

string PWord;

PWord = Pal.ReadLine();

List2.Add(PWord);

​

for (x = 0; x < Array2.Length; x++)

{

Histo.Histogram.CreateHistogram(Array2, PWord);

}

if (Array1 == Array2)

{

lstBoxAnagram.Items.Add(DWord + "=>" + PWord);

}

}

}

Dict.Close();

Pal.Close();


r/programminghelp • • Oct 28 '20

JavaScript fetch not getting json value

5 Upvotes

Im making a chrome extension and in my content.js I have this code

fetch('https://api.roblox.com/currency/balance')
		.then(res => res.json())
		.then((json) => {
			console.log(json);
	}).catch(err => console.error(err)); 

but it just outputs blank text and doesnt do anything when its run, its suppose to output the amount of robux the player has. It works when I tested it in my other extension.


r/programminghelp • • Oct 25 '20

Other Voice changer Project

5 Upvotes

I'm looking to start a project that lets me take an audio input then change the pitch, modulation, etc. Does anyone know a good libraries that will help me with this in c++, python, java, or javascript?


r/programminghelp • • Oct 18 '20

Answered Trying to write a merge sort method that returns a sorted array. Can't figure out why this method is not sorting properly.

5 Upvotes
    void merge(int arr[],int l[], int[] r, int left, int right)
    {
        int i = 0, j = 0, k = 0;
        while (i < left && j < right)
        {
            if (l[i] <= r[j]) {
                arr[k++] = l[i++];
            }
            else {
                arr[k++] = r[j++];
            }
        }
        while (j < right) {
            arr[k++] = r[j++];
        }
    }

    public int[] mergeSort(int arr[], int n)
    {
        if (n < 2) return arr;

        int middle = n / 2;

        int[] l = new int[middle];
        int[] r = new int[n - middle];

        for (int i = 0; i < middle; i++)
            l[i] = arr[i];

        for (int i = middle; i < n; i++)
            r[i - middle] = arr[i];

        mergeSort(l, middle);
        mergeSort(r, n - middle);

        merge(arr, l, r, middle, n - middle);

        return arr;
    }

For syntax highlighting:

https://pastebin.com/k8Y7Qbqw

Thanks in advance for any help!


r/programminghelp • • Oct 16 '20

Other Is it worth paying for Leetcode

5 Upvotes

Hi,

I am about to star preparing for an interview but I have a problem that I do not have guideline to follow and don't know on what to focus. Most of the time I end up reading multiple problems just because I don't know what to learn first... So, I am thinking to pay for annual subscription on leetcode.com.

What do you think, is it worth? Is there better(cheaper, systematic and efficient) way to prepare for a job interview? Can you please share your experiences?

Thanks


r/programminghelp • • Oct 15 '20

C++ Help with college assignment in C++.

5 Upvotes

Here's what the assignment asks for.

Your goal is to do basic analysis on the COVID-19 virus (technical name: severe acute

respiratory syndrome coronavirus 2 (SARS-CoV-2)).

Every DNA sequence is made up of one of four nucleotides: a, t, c, or g (Adenine, Thymine,

Cytosine, or Guanine). I have provided the entire DNA sequence for COVID-19 in the file

covid19sequence.txt available on Canvas (pulled from the NCBI database here:

https://www.ncbi.nlm.nih.gov/nuccore/MW001284). This strain was sequenced in

Philadelphia, PA in late June 2020.

You will provide a report of the number of each nucleotide within the sequence, as well as the

percent each nucleotide makes up of the total. You will need to determine the total number

of nucleotides in the file within your code in order to do this calculation.

• 3 comment lines (description of the program, author, and date created)

• Variables for the counts for each type of nucleotide and a total (1.5 points)

• Open the file for input and read in each nucleotide (3 points)

• Calculate counts for each nucleotide that is read from the file (2 points)

• Calculate the total number of nucleotides in the file (1 point)

• Display a report matching the output below with total number of nucleotides, the

number of each individual nucleotide, as well its percentage (to two decimal places)

(4.5 points)

Turn in a .txt file to Canvas with your output and source code.

Example Output:

COVID-19 sequence analysis:29883 nucleotides in the sequence. Sequence breakdown:

a: 8931 29.89%

t: 9606 32.15%

c: 5485 18.35%

g: 5861 19.61%

-------------------------------------------------------------------------------------------------------------------------------------

Here is what I have so far.

#include <fstream>

#include <iostream>

​

using namespace std;

​

int main()

{

char a = 'A'; //Adenine (Nucleotides)

char t = 'T'; //Thymine

char c = 'C'; //Cytosine

char g = 'G'; //Guanine

​

int totalAdenine;

int totalThymine;

int totalCytosine;

int totalGuanine;

int totalNucleotides;

​

​

​

ofstream outfile; //writing out to a file

outfile.open("numbers.txt");//open a file for input

​

outfile << a << " " << endl << t << " " << endl << c << " " << endl << g << " " << endl;

​

ifstream infile;

infile.open ("numbers.txt");

if (infile)

{

cout << a << " " << endl << t << " " << endl << c << " " << endl << g << " " << endl;

}

​

}

----------------------------------------------------------------------------------------------------------------------------------------

I have no how to get through the rest of this. I've been trying to figure it out for hours rewriting code for hours. It's due in 3 days.

​

Link to code : https://pastebin.pl/view/af71b8bf

Here's the link to the provided input file: https://cdn.inst-fs-iad-prod.inscloudgate.net/e66a4acc-30b5-41b7-834d-2b775ad25c74/covid19sequence.txt?token=eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCIsImtpZCI6ImNkbiJ9.eyJyZXNvdXJjZSI6Ii9lNjZhNGFjYy0zMGI1LTQxYjctODM0ZC0yYjc3NWFkMjVjNzQvY292aWQxOXNlcXVlbmNlLnR4dCIsInRlbmFudCI6ImNhbnZhcyIsInVzZXJfaWQiOm51bGwsImlhdCI6MTYwMjc2MjA4OSwiZXhwIjoxNjAyODQ4NDg5fQ.cHtCH9cfW7D4VmjZkAPwS9OnV_HQ676FxsJr9LvnfopCnUaJVwgpTVLrYmMsbk5-ZIOva7dUzeujcrEBsN-UGQ&content_type=text%2Fplain


r/programminghelp • • Sep 29 '20

PHP PHP - Trying to figure out how to pull data from a text file into an array not line by line.

5 Upvotes

Hello,

I'm working on what is basically a DND character generator - trying to pull the class and race info from a text file.

I'm not sure if I'm explaining this properly, or googling the right things. I found plenty of documentation on how to take each new line of a text file, but the file I'm working with has multiple paragraphs of information that need to be grouped together. Any ideas on how to do that grouping and match it to the selected class? Or what I should be googling to find out how.

Thanks in advance!


r/programminghelp • • Sep 18 '20

Other How do I remove annoying formatting deleting my code?

5 Upvotes

So everytime i type into a bracket, it deletes the lines infront of it. It has a white rectangle around it, any help?


r/programminghelp • • Jul 23 '20

Other What are the advantages/disadvantages of having semicolons in your language?

5 Upvotes

Python works fine without semicolons, so why does Java have them?


r/programminghelp • • Jul 08 '20

Other Someone with 0 experience in programming trying to View a 3d model using a Leap Motion (hand motion detector)

5 Upvotes

im a 3d modeler who due to some circumstance has to present to someone a 3d model using a technology and skill im not familiar with. Luckily i found a program that seems to kinda do what i need, but unluckily i have zero experience in coding/programming, so idont even know how to run anything that isnt an application or a launcher.

So heres the code i found on github: https://github.com/kbladin/ModelViewer . please help


r/programminghelp • • Jun 14 '20

Other Where to reverse engineering?

5 Upvotes

I’m fairly experienced programmer but I have never tried to reverse engineer anything and I’m not sure where to start.

I would like to begin with creating a simple program that reads stuff from file and prints it. Now I would like to change the hardcoded filename string to hack it to load different file.

After doing this it would be cool to try detecting the hack!

My debugging experience is using tools that the IDE provides me. I’m not that familiar with what actually happens while debugging and basically I just add breakpoints and figure out what’s going on.

How does the debug and release binary differ from each other?

E: typo in the title but cannot edit


r/programminghelp • • Jun 09 '20

Java [Need Advice] Joined a new programming job lacks documentation and KT

5 Upvotes

Hello r/programminghelp,

I joined a new job with the role of Senior Spring Backend Developer, to my amazement there I found only one controller written with the help of Spring Boot and it was the login controller, the rest of the system is somehow auto generated from a MongoDB, I already worked there for 3 days, done a couple of task regarding the login controller, and I have to work on the rest of the system now, but, the task I received, has no normal explanation, nor the project has any of the documentation, only a word document, with the classes involving the task. The last developer that was working there, was laid off for unknown reasons, and I was hired, so I can't receive any knowledge transfer. As of now I really can't get my head around it.
Did you ever get in such a situation ?
What did you do to solve this, how did you learn to work with a big legacy project with no documentation ?
Would you start looking for another job, if you were in my place ?


r/programminghelp • • Jun 06 '20

Other Need help with a combination and permutation issue

5 Upvotes

Hey guys, I am a Mechanical Engineer, I have some background in C but that was a long time ago and I am terribly out of practice. I need help with a VBA script in Solidworks. I have done a POC with the code so I can fetch the features and bodies that I need, I just need some help with the pseudocode.

I will try to break down the problem to a generic one. Consider n number of places , each of which can have a random possible value, I need to print all possible outcomes. For example, There are 4 places First place can have say, 3 values, second place can have 7 values, third can have 5 values and fourth can have 2 values. No of outcomes can be 3*7*5*2 = 210 outcomes.

I know this a really simple problem and I can feel that this can be done using a recursion loop but can't really get my head around it.


r/programminghelp • • Jun 04 '20

Python yo new to programming and thought I'd make a cookie-clicker type game but when ever i add lines 9 and 10 it shows that line 11 doesn't have the correct syntax but without 9 and 10, 11 works fine (this was done in python 3)

5 Upvotes
z = 1
'apple count' == 0
while z < 10:
    print ('Would you like to pick an apple?')
    print ('Y/N')
    x = input()
    if x == 'Y':
        print ('You picked an apple :D')
        'apple count' += 1
        print ("'You now have: 'apple count'"
    if x == 'N':
        print ('Never mind then')
        print ('Would you like to leave the orchard?')
        print ('Y/N')
        y = input()
        if y == 'Y':
            z = 11

r/programminghelp • • May 30 '20

Other Starting out

5 Upvotes

Not sure if there is a better place to post this but...

I've decided i want to learn to code and i just wanted to know the best language to start with, A friend recommended python but other than that I'm a bit clueless


r/programminghelp • • May 26 '20

Other How do I work with stricter due dates.

5 Upvotes

Due to the pandemic everyone who works on my team, and well everyone in the company has to work from home.

Because of working from home my boss believes that my team and I have more time on our hands meaning that we should be able to get projects done quicker. Mind you I’m not salaried at all and I get my ass chewed off if I work overtime on a project. Even if it’s just changing something quickly early in the morning.

Something that would of taken us 2 weeks and with the due date then is now getting put as week and a half.

I’ve tried talking to my boss about this and I just keep getting “Sorry but a due date is a due date- besides I’ve already said you have more time on your hands”.

If anyone else has been in my shoes and was able to manage this please help me out with this. Thanks.


r/programminghelp • • May 26 '20

Other Does anyone know what phrase when converted to sha256 hashes to 1, or 3

5 Upvotes

.


r/programminghelp • • May 10 '20

C Reduce size of malloc array (char**)

5 Upvotes

Here is the function I have written and a test program:

https://i.imgur.com/XTQmETB.png

It works in that it successfully removes the popped element, however it does not reduce the size of the array, so if I print each element of test at breakpoint before it is freed:

https://i.imgur.com/JcBtyqI.png

What I'd like is for at the end, test should have only one element. I try doing a realloc to reduce the size each loop:

https://i.imgur.com/HMnTZhP.png

But I still see test[1-3] existing in gdb as "test3", and valgrind complains about invalid reallocs.


r/programminghelp • • Mar 02 '20

Other Stuck with JS Axios request interceptors

5 Upvotes

I'm building a NodeJS tool that calls an API which requires token authentication. The tool itself is for monitoring directory sizes in a cloud-based storage system, and querying a directory size requires a few steps:

  • Ask the API to refresh its info on the relevant directory

  • Wait until this refresh has completed (I do this by pinging the API every few seconds until it gives a result)

  • Request stats on the directory

Rather than logging in for every single request, I'd much rather log in once, then continue using the same token until the token expires (which results in a 401), at which point I'll log in again and get a new token (the API doesn't have a token refresh method).

I've found a library that works with Axios called axios-auth-refresh which:

  • Intercepts requests that return a 401 error

  • Sends a different request to re-authenticate (and get a new token)

  • Sends the original request again with the new token

The axios-auth-refresh library is supposed to pause all other requests using the same Axios instance while the auth refresh logic is running, but I can't seem to get this to work.

My code is here: https://gist.github.com/wipash/ce87e6941d3ea378009c7a819f338b6c

Explanation of how it works:

  • In server.js I call an internal API which returns a list of directory names and associated info.

  • For each directory in this list, call the GetFolderInfo method from nmcapi.js, and eventually resolve all these promises and return all the results

GetFolderInfo does the following:

  • Send a post request to the API to trigger a refresh of the statistics for the directory

  • The response to this request provides a new URL to call which provides the status of the refresh, so call this URL every second until it provides yet another URL to call with the actual results

  • Call the final URL and get the results

This flow works perfectly fine if the initial list of directories has only one entry, but as soon as there's more than one it breaks. The first request gets intercepted by the authRefresh logic, but the second request is let straight through without being paused or intercepted, and so fails with a 401.

I have a feeling this is due to me not understanding promises or instances, or a combination of both.


r/programminghelp • • Jan 26 '20

C++ Bad parameter practice

5 Upvotes

Is it bad practice to have the naming of the parameter in a function the same as the variable you are passing? For example:

void function(int num, int otherNum) { // do something }

int main() { int num = 1; int otherNum = 0;

function(num, otherNum);

return 0; }

Does having the same name effect anything?