News for hackers. Stuff that matters.
Re:Int 80h (2001) by mediocrejoker on Sunday August 21, 2016 @01:12PM (#12331677)
> Secondly, there is a common myth among programmers that assembly language is very hard to use and that it takes much longer to code the same program in assembly language than in a HLL. [...] An experienced assembly language programmer can and does code as fast in assembly language as an experienced C programmer does in C. It is simply a matter of familiarity.

I don't really understand this argument. If a few lines of c can generate dozens of lines of assembly, how can it not be faster to have the compiler write assembly for you?

Re:Int 80h (2001) by naner on Sunday August 21, 2016 @01:26PM (#12331750)
Also when writing C you don't have to be 'an experienced assembly programmer' to write performant and portable code. That is one of the driving points of a HLL: you don't need to know as much minutiae to write good maintainable code. I understand getting into assembly for the purpose of learning or squeezing out that last bit of performance, but it isn't a general purpose programming language anymore and shouldn't be a default choice over a HLL for most applications.
Re:Int 80h (2001) by shandor on Sunday August 21, 2016 @01:48PM (#12331854)
I came to post this exact thing. I guess the article is actually quite old. It talks people "migrating from MS-DOS to Unix/BSD" among other things, which sounds more than a little odd to be even from this millennium.
Re:Int 80h (2001) by robert_tweed on Sunday August 21, 2016 @01:23PM (#12331728)
Macro assemblers. It would be a pain without macros.
Re:Int 80h (2001) by _c_ on Sunday August 21, 2016 @02:39PM (#12332120)
"It is simply a matter of familiarity."

Your comment focuses on how fast the compiler generates lines of assembly, after the programmer has constructed a solution.

But unless I have misunderstood the author was focusing on how fast the programmer can construct a solution.

The final step of depressing keys to input the solution into the computer can be sped up by using libraries and perhaps macros.

It's also possible to write programs ("code generators") that generate lines of assembly based on a "template". And that "template" need not be written in C or any other popular computer language.

It could be some "DSL", a shorthand for assembly, that the programmer creates for himself.

djb's qhasm might be considered an example.

While it may be generally true that C requires less key punching than assembly (certainly it requires fewer "lines"), this does not mean constructing a solution in C necessarily comes faster than constructing one in assembly... if the programmer is familiar and efficient working with assembly.

Re:Int 80h (2001) by gens on Sunday August 21, 2016 @04:50PM (#12332681)
Something like "(x3+(y/20)5)" will generate a few lines of assembly (about 3 to 5 in this case, assuming registers are pre-loaded). But usually no, there won't be much more code. For example "while(1){..." equals just one instruction, and "for(x=10, x<0, x--){..." is 2-3 instructions.

edit: idk how to put a asterisk up there in the example above

I have no idea where people get the idea that one line of C equals 10 lines of asm.

PS Assembly is not hard at all, and is good to understand/read assembly when coding C. The only thing is that it is a bit rough to start coding in it (no good tutorials is one of the two-three difficulties).

Re:Int 80h (2001) by mschuster91 on Sunday August 21, 2016 @05:58PM (#12332906)
> I have no idea where people get the idea that one line of C equals 10 lines of asm.

Because coding in asm takes more than just the raw instructions.

x86 doesn't have many registers so you're shifting around stuff across registers and memory all the time, not to mention stack setup/teardown and the error checking (e.g. div0, overflow) you are supposed to do after operations.

Re:Int 80h (2001) by gens on Sunday August 21, 2016 @06:25PM (#12332989)
C doesn't check for overflows..

I also disagree with "shifting around stuff across registers and memory all the time". An "average" function doesn't really have all that many variables and x86 has 8 GP registers (16 on amd64). You don't even have to declare variables, you just take a register (and/or a location in memory) and use it as you wish.

I'm now sitting here thinking what can be done in C that would end up being a lot of instructions, and i can't think of anything. Going over an array does not, neither does recursion (recursion is just syntactic sugar in the end). What else.. i can't think of anything. Macros ? But macros are cheating in this comparison (not to mention that the flat assembler has actual macros, that are extremely powerful)

Re:Int 80h (2001) by userbinator on Sunday August 21, 2016 @06:57PM (#12333111)
C doesn't check for overflows..

This is one of the things where (x86) Asm is definitely easier: divide overflows naturally cause an exception which will get handled automatically, and add/subtract/multiply overflows can be checked with one extra (JO or JC) instruction. In C, this is all undefined behaviour.

I'm now sitting here thinking what can be done in C that would end up being a lot of instructions, and i can't think of anything.

Crypto algorithms come to mind, but like you said, macros can take care of that easily... and on this page is an AES-256 CFB implementation in Asm that is around the same size of source as others in C (but much smaller binary):

http://reimagery.com/fsfd/encrypt.htm

Re:Int 80h (2001) by wtetzner on Sunday August 21, 2016 @01:14PM (#12331686)
Yes, and C isn't even particularly high level.
Re:Int 80h (2001) by frozenport on Sunday August 21, 2016 @05:33PM (#12332827)
Its a common trope expressed by bitter people. In general this happens when you don't keep up with technology trends, you just don't understand why somebody prefers one thing over another when both, peripherally, yield the same product. Its also obviously not true.
Re:Int 80h (2001) by pavlov on Sunday August 21, 2016 @01:33PM (#12331788)
Because programmers are not typists? Translating a thought into a programming concept usually takes more time than typing it out, even in assembly.
Re:Int 80h (2001) by pcwalton on Sunday August 21, 2016 @01:58PM (#12331913)
I dunno. I think by any measure being able to write "x / 3" will gain you productivity vs. "imul eax,2863311531; shr eax,1" (with the trip to the Hacker's Delight page necessary to look up the magic number).
Re:Int 80h (2001) by psyklic on Sunday August 21, 2016 @03:48PM (#12332429)
Or just use DIV/FDIV/FIDIV.
Re:Int 80h (2001) by mschuster91 on Sunday August 21, 2016 @06:00PM (#12332914)
DIV is way slower than MUL, so unless you need the extra precision or the result of the modulo, don't use DIV.
Re:Int 80h (2001) by psyklic on Tuesday August 23, 2016 @12:39AM (#12341444)
We were talking about readability, not speed. (Of course, you could also just write a macro.)