ARM Assembly - Reading ".dat" extension / importing information - arm

I am supposed to create a program with the ".dat" extension, but ARMSim# doesn't read the file. First off, how am I supposed to have it read my file?
Also, the program I am writing needs to let the user input a list of numbers and the output should be the first integer, second integer, total number of integers, total numbers that are not the first integer, and total numbers that are not the second integer.
On top of it, it needs to check for errors and have a readable output.
I am completely stuck and obviously don't know any ARM. I would like to learn it since I will be having future projects that I hopefully will be able to do on my own, so if you can describe any code that would be great. The whole week I have been trying to read websites on ARM and I still stare blankly at the screen when I try to code anything. Any help would be GREAT.

Related

How to read a text based data file into an array in C?

I have to read a text based data file, with an unknown number of data points, into an array in C, but I can't work out how to do this. I can't even manage to get my program to successfully open the text file, let alone put it into an array etc
The file contains numerical values, so it is not a string it needs to be read into. Ideally this should be done by the user inputting the file name.
I basically need the program to:
Ask user to input file name (I understand this is just a simple printf job)
When the user inputs the file name, the program opens the text file, stores the data from it into an array of an appropriate size.
Print entire array to show that this has been done.
If anyone could give a step to step explanation of how this can be done I would really appreciate it.
Anything asked to be described step by step without asking your input would be copy of others work.
Best advice is to learn things step by step on your own.
File I/O in C: http://www.tutorialspoint.com/cprogramming/c_file_io.htm
If you want to add additional features like user input:How to read a string from user input in C, put in array and print
Do some research on file content and how it's being handled from program. (Seems that you are referring to ASCII format file).
You should have done some searching before asking this complexity level questions.
If you want same advice in future for this task, I suggest to add code here.

FORTRAN: Save array and use in another programme

Is it possible to create an array in one programme and then use it in other programmes? The array I am looking to create is very large and its creation will take a while so I don't want to make it anew every time I run the main programme but instead just use it after creating it once in the other programme. Because of its size I'm not sure if printing it to file and then reading it back in would not also be quite inefficient?
It is an integer array of dimensions 1:300 000 and 100.
Long comment:
There are many formats in which you can save data: Fortran unformatted sequential, Fortran unformatted direct, Fortran unformatted stream, NetCDF, HDF5, VTK, ... Really difficult to answer this with any definite answer. We really don't know how time consuming it is to compute it, so we cannot judge whether saving would be more time consuming or not.
Definitely you should be looking for unformatted or binary formats.
Edit: your array is actually not that big. The saving and reading will ne quick. Just use an unformatted file form.

Extract records from compiled search program, C

Does anybody have an idea on how to extract all information from a compiled, record search program?
I think the program works by using a binary search. It was compiled and the database was in the program. The only way to see the records is to make a correct search.
Is there some way that I can bruteforce the program and extract all information?
The record is searched by the ID which starts with 1 and 10 digit long [ 1xxxxxxxxx ].
If you want to try, 1112700303 will work but I don't have the other numbers.
I've tried some Decompiler but I have no idea what I'm doing.
The program can be downloaded from here:
https://docs.google.com/file/d/0B9fwDRGBsrxBT3FiSFdaTnJZcUk/edit
Your help is appreciated as it will increase my knowledge and learn something new here :D
Though question. Is there no way to get hold of the source code (ask the author, search for the program name, ...)?
On Unix/Linux, the program strings extracts printable strings from a binary file. Doing that on x86 executables gives a long list of strings that are just instructions which happen to be ASCII strings, names of functions used by the program, ans other junk. Somewhere it lists initialized text data for the program (printf(3) formats, constant strings used), which in this case shows a bunch of names that look arabic, and some directory names. Perhaps searching for those could help.
This can probably be achieved by using Snowman. It might not get the exact source code you are looking for but enough to extract all the data you need such has the constant strings.

file and formatting alternative libs for c

I've done some searching and have not found anything that would boost the file and formatting functions in Visual Studio VS2010 C (not C++).
I've been able to address the raw i/o issues to some extent by using large buffers and a SSD drive, so the more pressing issue is a replacement for the family of printf functions.
Has anyone found something worthwhile?
As I understand it, part of the glacial speed issue with the printf functions is that they have to handle myriad types of arguments. Does anyone have experience with writing a datatype-specific version of printf; eg, one that only prints ints, or only prints doubles, etc?
First off, you should profile the code first before assuming it's printf.
But if you're sure it's printf and similar then you can do a few things to fix the issue.
1) print less. IE, don't call expensive operations as much if you can avoid it. Do you need all the output, for example?
2) manually replace the string concatenation with manually built routines that do all the pieces without having to parse the format specifier.
EG: printf("--%s--", "really cool");
Can become:
write(1, "--", 2);
write(1, "really cool", 11);
write(1, "--", 2);
That may be faster. But again, you won't know until you profile it. Don't spend energy on a solution till you can confirm it's the solution you need and be able to measure the success of your proposed solution.
#Wes is right, never assume you know what you need to fix until you have proof.
Where I differ is on the method of finding out.
I and others use random pausing which works for these reasons, and here's a short slide show demo & C++ code so you can see how it works, if you want.
The thing about printf (or any output) function is it spends A) a certain number of CPU cycles creating a buffer to be output, and then it spends B) a certain amount of time waiting while the system and/or auxiliary hardware actually moves the data out.
That's maybe a bit over-simplified, but if you randomly pause and examine the state, that's what you see.
What you've done by using large buffers and an SSD drive is reduce B, and that's good.
That means of the time remaining, A is a larger fraction.
You know that.
Now of the samples you find in A, you might get a hint of what's happening if you see what subordinate routines inside printf are showing up.
Usually printf calls something like vprintf to get rid of the variable argument list, which then cycles over the format string to figure out what to do, including things like parsing precision specifiers.
If it looks like that's what it's doing, then you know about how much time goes into parsing the format.
On the other hand, if you see it inside a routine that is copying a string, or formatting an integer (along with dealing with leading/trailing characters, etc.) then you know to concentrate on that.
On yet another hand, if you see it inside a routine that looks like it's formatting a floating point number (which is actually quite complicated), you know to concentrate on that.
Given all that, you want to know what I do?
First, I ask who is going to read this anyway?
If nobody really needs to read all this text, why not pump it out in binary? Or failing that, in hex?
If you simply write binary, A shrinks to nothing, and when you read it back in with another program, guess what?
No Lost Bits!

C homework, ignore for now (I think I am going repost later with some code)

I am going to be making a program that reads in a line and gets up to 6 numbers. The program will eventually solve a a square matrix between 2x2 and 6x6. My question is what errors do I need to look for on the get_numb() function?
I am thinking that the function will have to check character by character to make sure that the individual characters are actual numbers and not a EOF or \n. I will have to also check that there is not more than 6 numbers on a line. I am about a week into programing, so is there anything I need to know to tackle this?
I absolutely recommend you start by taking into use a good unit testing framework, and write unit tests as you go. This way you can cover all the cases you mention above, and make sure that your program really works the way you think it should work.
There are loads of questions on SO about C unit testing frameworks; pick your favourite.
Apart from the cases you mention, I can think of the following:
less than 6 numbers on a line
empty line
(if the numbers are floating point, various number formats)
If your teacher gave you sample input / output, you may of course incorporate that into your unit tests as well.
The potential errors you described are reasonable ones to check for.
I recommend you give it a shot. If they're not sufficient and you get stuck, then post your code and explain what you're seeing.
Most ascii to integer converters will help you out with the error checking. Here's hoping your teacher gave you some example input code and perhaps, depending on the input methods, some example conversion code. As this is homework, I don't want to get too specific.

Resources