How to change this linux Assembly code into compatible UNIX assembly code?

Suggestion: Write a C program, with inline assembly. You could also call C library functions (like printf ) from your assembly, in order to remove the OS dependency.

Suggestion: Write a C program, with inline assembly. You could also call C library functions (like printf) from your assembly, in order to remove the OS dependency. Here's an example with inline assembly: softpixel.com/~cwright/programming/simd/....

Thank you, I just started learning assembly. I will look into inline assembly. (Does that just mean put parts of Assembly code into a C source file?) – BeyondSora Jun 11 at 20:49 +1.

Since there are no standard libraries for assembly, your best option is to call the c library. All you need to do is change the first int to an output function (such as printf), and the second to a call to exit. – ughoavgfhw Jun 11 at 20:50 @BeyondSora: Yes, that's most of it.

The exact syntax depends on your C compiler, but you can call assembly instructions and also use names of C variables. For this case, you can call cpuid and then use mov to transfer the results from specific registers where cpuid puts them, into C variables. – Ben Voigt Jun 11 at 20:51 Umm, I get what you mean.

But I am not sure how to do this, the book I'm reading does not say much about inline assembly. How to integrate this code in a C program. Or, how to call a C function in assembly code?

THANKS! – BeyondSora Jun 11 at 20:51 1 And here I went through the trouble of constructing my own example :-) – Nemo Jun 11 at 21:06.

At the assembly level, there is no such thing as "UNIX compatible code". Every Unix has its own interface for making system calls. I can tell you what this code is doing, though.It is calling the CPUID instruction, then putting the result in the "xxx" part of the output string, then calling: write(1, output, 42); exit(0); If you are using GCC, the closest "portable" equivalent looks something like this: #include #include int main(int argc, char *argv) { int cpuid3; char result12; asm("cpuid" : "=b" (cpuid0), "=d" (cpuid1), "=c" (cpuid2) : "a" (0L)); memcpy(&result0, &cpuid0, 4); memcpy(&result4, &cpuid1, 4); memcpy(&result8, &cpuid2, 4); printf("The processor Vendor ID is '%s'\n", &result0); return 0; } For other C compilers, you will have to consult the manual to learn their inline asm syntax.

If you really want to call this directly in assembly, you will have to find out how your particular Unix expects system calls to work.

Thank you! I am trying to run my code on Windows SUA (subsystem for unix application), I am not sure how it implements the system calls. Google "SUA system calls" does not return much useful info... – BeyondSora Jun 11 at 21:28 @BeyondSora: In that case, do not worry about invoking the system call.

Just figure out how to invoke cpuid using Micosoft Visual Studio. This sample code appears to be relevant. – Nemo Jun 11 at 21:31 but does that run in SUA?

– BeyondSora Jun 11 at 21:34 If it is just calling the CPUID instruction and then invoking printf (or similar), yes. Your goal here is just to invoke CPUID with eax equal to 0 – Nemo Jun 11 at 21:36 Thank you very much! I ll try it now – BeyondSora Jun 11 at 21:39.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions