int cauta(int near *a, size_t n, int x)
mov si, a
mov cx, n
mov dx, x
sub si, 2
add si, 2
cmp [si], dx
mov ax, n
sub ax, cx
asm mov ax, -1
a = 4;
a = 5;
a = 1;
a = 9;
printf("%d", cauta(a, 4, 1);
The problem is that I get some errors:
1 2 3 4 5 6
D:\C++ Projects\Preparing for ONI\main.c|4|error: expected ';', ',' or ')' before '*' token|
D:\C++ Projects\Preparing for ONI\main.c||In function 'main':|
D:\C++ Projects\Preparing for ONI\main.c|49|warning: implicit declaration of function 'cauta'|
D:\C++ Projects\Preparing for ONI\main.c|49|error: expected ')' before ';' token|
D:\C++ Projects\Preparing for ONI\main.c|50|error: expected ';' before '}' token|
||=== Build finished: 3 errors, 1 warnings ===|
It looks like the compiler didn't recognize the near keyword on line 4. The near keyword is a throwback to 16 bit memory architectures and is obsolete on 32 bit machines. That also caused your function call not to be recognized on line 49.
If you truely need the near keyword, you should check your compiler documentation. There may be a compile time switch to enable it, or it might be _near depending on the implementation, if it's supported at all.
I was going to suggest:
1. rewrite the C version using pointers rather than array indexing.
2. get the compiler to output intermediate asm code, which you can then borrow for getting the appropriate syntax.
3. tweak or replace the generated code as required.
Chervil: I tried to do that a few months ago, but the output code is absolutely understanable. For a simple Hello World program, I get over 500 lines of ASM code. I don't really know if that is ok...
AbstractionAnon: I didn't create that function in ASM. As I said below, I found it in a book, and I just copied it in the Code::Blocks environment to see if it works. So the "near" keyword belongs to the implementation found in that book.
What I did was create a simple function, such as "add two integers and return the result". But I gave the function and variables very distinctive names. That way, it was very easy to identify the relevant part of the code, and I ignored the rest.
Allright, but if you don't really know the ASM syntax, I think that is very difficult to consider just a part of that code. I mean...what if you miss some very important instruction, for instance to clear the memory or something like that?