How to find a matrix declaration pattern in C [closed] - c

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm building a two-pass assembler in C.
A part of its job is to be able to work on matrices.
Let's say that there is the following line:
mov m[r2][r5], XYZ
mov is the operation.
and m[r2][r5] and XYZ are the operands.
I need to find out if an operand is a matrix. and get the:
1. matrix name.
2. row.
3. column.
How is it possible?
Tried to use sscanf without any success.
Thanks in advance!

Unfortunately writing an assembler is not as easy as using the scanf. Simplifying: You need to divide the input stream into the tokens, then you need to parse it and build the semantic tree, then you need to do the semantic analysis, reduce the tree (by evaluating constant expressions, finding addresses etc etc), and eventually generate the machine code.

Related

graph traversal in C [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have to implement a backtracing algorithm in C which will emulate a hardware in purely software, and trace a single path from output of a system to the input pin, registering all the gates, their outputs and inputs(taken) on the path in a reverse order. I figured out that it can be done in graph traversal algorithm but not able to implement in C. Any useful suggestions shall be helpful indeed!
I've done a few maze solving algorithms, both breadth and depth first search.
I'd say you should first build a graph and make sure its perfectly built and without any incoherence, and something i found to be very useful was to find a way to print my graph to check for errors :).
Other than that, good luck !
Depends on what kind of path tracing, it can follow both breadth first search or else Depth first search. I have tried both of them and it works.

Read a file in C then using it in the program for several times [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am trying to write a C program in Linux system which the main function is read a data file (csv format 200MB file) in struct array and searching condition file (few lines) then output the matching result.
The read data function takes around 1 second to run and the matching part is pretty quick. I am thinking is that possible I can pre read the data file in memory by some methods then run the searching function for many time as I want.
It maybe similar to R. Read a csv file first then do some calculate from it.
Create a tokenizer using read system call to read until you hit the comma and then update up to that part to your struct using memcpy or strncpy. After that it would be easy for searching and validation.

How to add, subtract, multiply and divide 2 numbers each containing 100 digits in C? (using arrays) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'am trying to write a C code to add, subtract, multiply and divide 2 numbers each containing 100 digits. This should include the use of arrays.
Can anyone please give me any suggestions, a pseudo code or a sample code?
To be more clear
The user will enter 2 numbers(Integers)
Each number can comprise of 100 or less digits i.e integer a can be 10 or 234 or 43582 or 23456788 or 23445667788...... etc. Same for integer b.
Now taking these two integers I have to perform the arithmetic operations of Addition,Subtraction,Division,Multiplication,Modulas(%)
You could try using the GMP Library as answered in this question. It can perform Bigint operations in both C and C++. Also if you are fine with C++ code for Bigint you could check out this blogpost.
You are looking for hints on implementing arbitrary precision arithmetic. Start be reading this article: https://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic , then search for bignum c code with a search engine, sample implementations are easy to find. Avoid full blown packages such as gnu MP because they are too advanced and not the right starting point.

How is encoding faster than not encoding? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm making a virtual machine in C and I was told that by converting the "assembly" code into hexadecimal or binary, I could speed up the execution. My question is, if I have a string and I encode it to numbers, how can it be faster than not encoding it when it adds and extra step to the execution in the VM?
--EDIT--
An example of the VM assembly is:
push 10 # Push the value 10 to the top of the stack
print # Print the value at the top of the stack
The encoded instructions look like this:
010a 0c
But the part I don't get is how encoding the assembly into instructions can be faster than not doing it because you have to decode them again. Please let me know if I'm wrong though.
Yes, encoding is better in the case on the re-use of the code.
Keep in mind that a function or piece of code is called many times, and so you loose little times for the first conversion and after you gain a lot of time when you start interpret the same code.

A byte has 8-bits. Can it be larger in another system? give an example [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
A byte has 8-bits. Can it be larger in another system? Give an example.
Also, how many different types of calls such as writeint,writedec,writestring,writechar are there in assembly language.
Thanks.
Not any more. There was a time, yes, when there were systems without a fundamental 8-bit byte.
System where 1 byte != 8 bit?
how many different types of call such as writeint,writedec,writestring,writechar are there in assembly language
This question makes no sense. Assembly language is just a means of writing code that translates directly to machine instructions. call is just one of these instructions - it jumps to some other section of code, with the intent of returning to the place where the call was made.
The things you're referring to sound more like library routines - in which case there are any number of them, depending on the programming environment.

Resources