[Solved] Assembly code fsqrt and fmul instructions

It looks like you are trying to do something similar to this: #include <stdio.h> double hullSpeed(double lgth) { double result; __asm__( “fldl %1\n\t” //st(0)=>st(1), st(0)=lgth . FLDL means load double float “fsqrt\n\t” //st(0) = square root st(0) “fmulp\n\t” //Multiplies st(0) and st(1) (1.34). Result in st(0) : “=&t” (result) : “m” (lgth), “0” (1.34)); return … Read more

[Solved] Why does it return a random value other than the value I give to the function?

First of all, C functions are call-by-value: the int x arg in the function is a copy. Modifying it doesn’t modify the caller’s copy of whatever they passed, so your swap makes zero sense. Second, you’re using the return value of the function, but you don’t have a return statement. In C (unlike C++), it’s … Read more

[Solved] How do I retrieve the processor time in Linux without function calls?

You should read time(7). Be aware that even written in assembler, your program will be rescheduled at arbitrary moments (perhaps a context switch every millisecond; look also into /proc/interrupts and see proc(5)). Then any hardware timer is meaningless. Even using the RDTSC x86-64 machine instruction to read the hardware timestamp counter is useless (since after … Read more

[Solved] First assembly program [closed]

I would perhaps start reading about each of those lines one at a time and just see what they do. For example, as someone in the comments said, Read about what int 21 does, it does many things, depending on what is in the AH register. http://www.ctyme.com/intr/int-21.htm e.g. Reading a line from STDIN is specified … Read more

[Solved] map c language into assembly language [closed]

I don’t know if such a book exists (if it does, it’ll likely be a book about compilers). However, there’s an easier solution: try it. Write some C code, then compile it with debug symbols (these instructions assume linux): gcc foo.c -o foo Then, use a debugger: gdb ./foo break MyFunction run disass This will … Read more

[Solved] convert 16-bit c++ inline __asm to 32-bit and remove far pointer [closed]

This an ancient DOS Protected Mode Interface system call to set a protected mode interrupt vector. See eg http://www.delorie.com/djgpp/doc/dpmi/api/310205.html. The compiler was probably DJGPP. Porting this to a different OS and/or runtime system will require a redesign from scratch to reimplement whatever functionality the interrupt handlers provided under DPMI. Good luck to you with that. … Read more

[Solved] Indexing args as an array in the Windows x86-64 ABI [closed]

Jester’s suggestion to write it in C is probably a good one, esp. if it can be inlined into calls where some of the args are compile-time constants. Your example use-case passes mostly compile-time-constant args, including the function pointer. Any decent optimizing compiler will inline this and optimize away the indirection into just a normal … Read more

[Solved] Can you help me to explain this asm code? [closed]

(My assembly is a bit rusty, anyone please correct me if I’m wrong): esp is the current stack-pointer, which is where locals and parameters typically live. esp+8 would access an item that is 8 bytes offset from the current stack-frame address. The [x] denotes a dereferencing, so the local is a pointer type. This value … Read more