Author Topic: Some think to share, happy to listen yours  (Read 6880 times)

Offline dalfonso01

  • Jr. Member
  • *
  • Posts: 44
Some think to share, happy to listen yours
« on: June 23, 2014, 07:52:11 AM »
Hi,
Happy beginning of week (this post could eventually not help...). :)
I would share some think after some weeks on the assembly (and NASM) stuff and hope this could start a reasoning in a large view.

Also if there are some books on the topic they are few, mainly introductory and somehow "one to any one different assembler",  nasm fasm, masm, if any. 

I understand the need to link assembly to the ability to use C glibc, but the departure starts too early.

Unless one needs to examine the code produced by gcc, the main reason to use AT&T syntax is in a job perspective, as there is no more stuff on that than on others (quite few).

Given the flat nature of the stuff any attempt to go into C should show the strategy more than I/O examples. I got a minimal mmap in less code than an example using some machinery in C that supposes I am interested in the toy purpose of the writer.
So it could be better to teach to fish, and use some better part of the library.

It is possible both embed the asm in C and use glibc in asm with call, it seems to me that the second is a better solution as the partition between the two stays floating, inside the single source or time by time and with no "brute" separation _asm {}.
About this, the statement from Duntemann : "However, one of the major ways you’ll end up learning many of the standard C library calls is by using them in short C programs and then inspecting the .s assembly output files that gcc generates".

>If this means playing with function to experiment, good, it this means that one needs to try a function to discover how and where the results of the call will have to be found, not so quite good ???, which would favor the  _asm {} , that at least, will rely on the C layer prototypes about usage of the C partition.
Someone with more knowledge, about all of this?

I find NASM quite neat and clean and that makes interesting to use it so thanks to developers.

Thanks
Fabio D'Alfonso

PS. It is sad that we study assembly to plan where and when to abandon it on the highway.
PPS. Duntemann says "Complexity kills, programs at least" , I would add "Emphasis kills ,  learners at least" . There is nothing special about some things but the preceding big announce will let you wonder what you are missing after that. 1 is just 1 and lea is just that: load the effective address... 
« Last Edit: June 23, 2014, 02:07:29 PM by dalfonso01 »

Offline Max

  • Jr. Member
  • *
  • Posts: 7
  • Country: us
Re: Some think to share, happy to listen yours
« Reply #1 on: June 24, 2014, 04:59:14 AM »
GCC can create Intel syntax sources with:
Code: [Select]
gcc -S -masm=intel $file
GAS also can read Intel syntax with the directive:
Code: [Select]
.intel_syntax

Offline dalfonso01

  • Jr. Member
  • *
  • Posts: 44
Re: Some think to share, happy to listen yours
« Reply #2 on: June 25, 2014, 01:21:15 PM »
Hi,
looking here and there I found (in college course material) that it is possible to use nasm procedures in C code not in embedded mode but anyway in separate .o just making something like this:

extern int sum();
int a1, a2, x;
x = sum(a1, a2);

with:
_sum
push ebp ; create stack frame
mov ebp, esp
mov eax, [ebp+8] ; grab the first argument
mov ecx, [ebp+12] ; grab the second argument
add eax, ecx ; sum the arguments
pop ebp ; restore the base pointer
ret

>>>>>I am wondering what is that makes the need to discover such basic things in the back of baggage, or a sparsed pdf and no one tells about this things while explaining the basics.

Offline gammac

  • Jr. Member
  • *
  • Posts: 71
  • Country: 00
Re: Some think to share, happy to listen yours
« Reply #3 on: June 25, 2014, 02:34:11 PM »
... it this means that one needs to try a function to discover how and where the results of the call will have to be found, not so quite good ???,

I am not sure, that I've understood your post right. If I got it, then take a look at this http://en.wikipedia.org/wiki/X86_calling_conventions#cdecl.
Please comment your code! It helps to help you.