Prev: IDE
Next: New NBASM IDE
From: Nathan on 12 Mar 2010 23:05 On Mar 12, 3:59 pm, Branimir Maksimovic <bm...(a)hotmail.com> wrote: > > > "C with classes" was the original name of the language. > > > [...] > > Problem with c++ is that Bjarne imposed rules on language which > what he considered "good C". Somthing like java did for C++. > Other thing is that because of function overloading he had > to use name mangling which made language pretty useless > for interfacing with another languages... > Other thing is exceptions which violate rule "what you > don;t use you don;t have cost". > But c++ is most closest to C still, and there is no > other language that can successfully replace assembler > then C. Before we declare this "successfully replace" status, I think we should put it to a test. int main(void) { unsigned ebx; unsigned ecx; ebx = 5; for (ecx = 0; ecx < 5; ecx++) { ebx++; } return 42; } $ gcc -c -o asm.o asm.c $ objdump -d asm.o asm.o: file format elf32-i386 Disassembly of section .text: 00000000 <main>: 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 83 ec 10 sub $0x10,%esp 6: c7 45 fc 05 00 00 00 movl $0x5,-0x4(%ebp) d: c7 45 f8 00 00 00 00 movl $0x0,-0x8(%ebp) 14: eb 08 jmp 1e <main+0x1e> 16: 83 45 fc 01 addl $0x1,-0x4(%ebp) 1a: 83 45 f8 01 addl $0x1,-0x8(%ebp) 1e: 83 7d f8 04 cmpl $0x4,-0x8(%ebp) 22: 76 f2 jbe 16 <main+0x16> 24: b8 2a 00 00 00 mov $0x2a,%eax 29: c9 leave 2a: c3 ret Dang! I'd say this here new-fangled "C" assembler doesn't know its ASM from a hole in the ground. :) Nathan. [ a.l.a added ]
From: H. Peter Anvin on 13 Mar 2010 00:06 On 03/12/2010 08:05 PM, Nathan wrote: > > Before we declare this "successfully replace" status, I think we > should put it to a test. > > int main(void) > { > unsigned ebx; > unsigned ecx; > > ebx = 5; > for (ecx = 0; ecx < 5; ecx++) > { > ebx++; > } > > return 42; > } > > $ gcc -c -o asm.o asm.c > $ objdump -d asm.o > > asm.o: file format elf32-i386 > > > Disassembly of section .text: > > 00000000 <main>: > 0: 55 push %ebp > 1: 89 e5 mov %esp,%ebp > 3: 83 ec 10 sub $0x10,%esp > 6: c7 45 fc 05 00 00 00 movl $0x5,-0x4(%ebp) > d: c7 45 f8 00 00 00 00 movl $0x0,-0x8(%ebp) > 14: eb 08 jmp 1e <main+0x1e> > 16: 83 45 fc 01 addl $0x1,-0x4(%ebp) > 1a: 83 45 f8 01 addl $0x1,-0x8(%ebp) > 1e: 83 7d f8 04 cmpl $0x4,-0x8(%ebp) > 22: 76 f2 jbe 16 <main+0x16> > 24: b8 2a 00 00 00 mov $0x2a,%eax > 29: c9 leave > 2a: c3 ret > > Dang! I'd say this here new-fangled "C" assembler doesn't know its > ASM from a hole in the ground. :) > Perhaps you should turn optimization on: : tazenda 39 ; gcc -m32 -c -O2 -fomit-frame-pointer test.c : tazenda 40 ; objdump -dr test.o test.o: file format elf32-i386 Disassembly of section .text: 00000000 <main>: 0: b8 2a 00 00 00 mov $0x2a,%eax 5: c3 ret Unlike the author of your code snippet, the compiler can tell that the previous code is useless. -hpa
From: Nathan on 13 Mar 2010 04:30 On Mar 13, 12:06 am, "H. Peter Anvin" <h...(a)zytor.com> wrote: > On 03/12/2010 08:05 PM, Nathan wrote: > > > return 42; > > } > > 00000000 <main>: > 0: b8 2a 00 00 00 mov $0x2a,%eax > 5: c3 ret > So we know that "return N;" is guaranteed to set the contents of EAX. Are there any guaranteed methods of setting EBX? Nathan.
From: Seebs on 13 Mar 2010 05:45 On 2010-03-13, Nathan <nathancbaker(a)gmail.com> wrote: > So we know that "return N;" is guaranteed to set the contents of EAX. No, we don't. We know that it did in a particular function compiled with a particular compiler with particular settings for a particular target. We don't know that it would always do the same even for this function -- it might compile differently if it were compiled along with particular other functions, or with different compiler flags, or... In short, no, it is not "guaranteed". -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: jacob navia on 13 Mar 2010 06:10
Nathan a �crit : > On Mar 13, 12:06 am, "H. Peter Anvin" <h...(a)zytor.com> wrote: >> On 03/12/2010 08:05 PM, Nathan wrote: >> >>> return 42; >>> } >> 00000000 <main>: >> 0: b8 2a 00 00 00 mov $0x2a,%eax >> 5: c3 ret >> > > So we know that "return N;" is guaranteed to set the contents of EAX. > Are there any guaranteed methods of setting EBX? > > Nathan. Yes, because according to the ABI (Application Binary Interface) all functions set their return value (when they have one, and when it is a type that fits in 32 bits) in EAX. Note that the next instruction (in this case) is return, so setting EAX doesn't buy you much. The EAX register is used universally by all compilers (that I know of) to set the result in the Intel architecture. st(0) is the register used for returning a floting point value, the pair EDX:EAX is used for 64 bit returns in 32 bit programs, RAX is used in 64 bit programs. Note that EBX is not given any special significance under windows, besides that it is a register that should keep its value across function calls, so there is no way to set it using high level constructs. Under 32 bit linux I think EBX is used to hold a pointer to the GOT in shared object, so you can't set it at all in "picture" mode, unless you save it... |