Live data from Hacker News

Echo – Assembly program that prints the first positional argument to stdout

github.com

41–50 of 50 posts

Re: Echo – Assembly program that prints the first positional argument to stdout

#41

Earlier quoted context omitted.

Serious answer: Because many developers regard assembly as some sort deep magic only understood by elder gods. This, of course, comes from some vague (and not entirely correct) understanding of "assembly" running beneath everything else, and thus being fundamental, yet not immediately useful to a large category of developers today. Hence it seems important but archaic. Archaic + difficult = elder knowledge.

I've actually had a few coworkers think I'm some sort of elder god when I find the root cause of subtle bugs that would've either required deep knowledge of the C++ standard, or not-as-deep knowledge of Asm. These are bugs that others have spent many hours staring at the source and stepping through in a debugger without any better idea of why they occur, but are solved in minutes by a glance at the Asm. IMHO if you a…

Even though it was a bit of a "sufferance", I enjoy having been full circle somehow. Starting with Java OOP in college, then went lisp maniac [1], then ml/FP. Which were all somehow further away from the machine, in a way. But at the same time lisp model seems a fairly thin layer over raw asm. And you realize that primitives of computing: arithmetic, logic, iterations.. are very similar whatever the language or paradigm. I then learned a bit about continuation, non determinism, compilation and now I'm almost free. A language is mostly an encoding. Most of them speak about the same things but in a different clothing.

Not 100% free, I think I need to finish my compiler training and forth bootstraping before I can claim that.

I can't really suggest others to follow the lisp, ml, prolog road though, so I'll just state what I wrote above.

[1] SICP especially, with its gradual pedagogy. From substitution, to environment, to register machines. You can see the relationships up close.

Re: Echo – Assembly program that prints the first positional argument to stdout

#42
post #5

Serious question: why is this on HN front page? Am I missing something?

I agree, nothing special. For comparison, "colpinsky" draws color changing Sierpinski Triangle in only 16 bytes, less than this echo :D

https://www.youtube.com/watch?v=Qw5WLk9IeX0

https://www.pouet.net/prod.php?which=62079

Re: Echo – Assembly program that prints the first positional argument to stdout

#43

Earlier quoted context omitted.

I've actually had a few coworkers think I'm some sort of elder god when I find the root cause of subtle bugs that would've either required deep knowledge of the C++ standard, or not-as-deep knowledge of Asm. These are bugs that others have spent many hours staring at the source and stepping through in a debugger without any better idea of why they occur, but are solved in minutes by a glance at the Asm. IMHO if you a…

Once you are tired being praised, teach them some valgrind. It will solve most of their problems.

I'm pretty sure the bugs I found would not have been valgrind-able as they were unrelated to memory errors.

Re: Echo – Assembly program that prints the first positional argument to stdout

#44
post #5

Serious question: why is this on HN front page? Am I missing something?

Serious answer: Because many developers regard assembly as some sort deep magic only understood by elder gods. This, of course, comes from some vague (and not entirely correct) understanding of "assembly" running beneath everything else, and thus being fundamental, yet not immediately useful to a large category of developers today. Hence it seems important but archaic. Archaic + difficult = elder knowledge.

Cool ! perfect explanation.

Re: Echo – Assembly program that prints the first positional argument to stdout

#45
post #17

Earlier quoted context omitted.

I don't understand why it is limited to 255 chars. The kernel copies the string(s) into the programs memory so it would be a kernel bug if the program got a non null-terminated or too long string. More importantly this program has a bug in that it doesn't check if there is an argument passed to it at all. Good effort but can improve a lot. I would praise the documentation but it is rather imprecise. All in all i woul…

This is great feedback, which I plan to use to improve the echo program. I'm just learning (on my own), and I figured I would just post my progress and I would get some feedback; it worked! echo is far from finished, and it's safe to say "I don't know what the hell I'm doing", but hey, I gotta start somewhere.

That's the spirit Kelsey! keep it up.

Re: Echo – Assembly program that prints the first positional argument to stdout

#46

Earlier quoted context omitted.

Once you are tired being praised, teach them some valgrind. It will solve most of their problems.

I'm pretty sure the bugs I found would not have been valgrind-able as they were unrelated to memory errors.

From my experience most of the hard to trace errors come from uninitialized variables and they are usually valgrindable. It is VM-based so it can cache jumps and other conditions that depend one uninitialized vars via taint analysis.

Re: Echo – Assembly program that prints the first positional argument to stdout

#48
post #22
post #17

Earlier quoted context omitted.

I don't understand why it is limited to 255 chars. The kernel copies the string(s) into the programs memory so it would be a kernel bug if the program got a non null-terminated or too long string. More importantly this program has a bug in that it doesn't check if there is an argument passed to it at all. Good effort but can improve a lot. I would praise the documentation but it is rather imprecise. All in all i woul…

> I don't understand why it is limited to 255 chars. The kernel copies the string(s) into the programs memory so it would be a kernel bug if the program got a non null-terminated or too long string. But you can also pass arguments to execve(2) which are not null-terminated.

The kernel copies the strings you pass in the array of pointers. (haven't checked though, but it is better then the alternative of not copying and dealing with the mess)

Re: Echo – Assembly program that prints the first positional argument to stdout

#49
post #48
post #22

Earlier quoted context omitted.

> I don't understand why it is limited to 255 chars. The kernel copies the string(s) into the programs memory so it would be a kernel bug if the program got a non null-terminated or too long string. But you can also pass arguments to execve(2) which are not null-terminated.

The kernel copies the strings you pass in the array of pointers. (haven't checked though, but it is better then the alternative of not copying and dealing with the mess)

The memory mapping is the same before and after execve(2), so I don't think it needs to be copied. I'll take a look though.

Re: Echo – Assembly program that prints the first positional argument to stdout

#50
post #49
post #48

Earlier quoted context omitted.

The kernel copies the strings you pass in the array of pointers. (haven't checked though, but it is better then the alternative of not copying and dealing with the mess)

The memory mapping is the same before and after execve(2), so I don't think it needs to be copied. I'll take a look though.

Maybe only a few pages remain as programs don't inherit memory from their parents. It could be done for those strings but consider that mappings are in 4k pages (so the rest of the page would have to be cleared to 0).
Post reply on HN