|
|
# ? Sep 10, 2010 01:39 |
|
|
# ? Jun 9, 2024 01:58 |
|
Howdy. I'm taking my first programming class and want someone to check over my first lab assignment before I turn it in to make sure I'm not loving up stuff like comments and whatnot. We have to use machine language to make a program that will calculate the GCD of two integers in an emulated simple computer using Unix.code:
edit - Looking over it I just realized that line 12 would just store zero no matter what. Would I be right that adding a new line above it that says LOA A and giving it the DONE title would fix it? So that part would end up looking like code:
Xinlum fucked around with this message at 05:23 on Sep 10, 2010 |
# ? Sep 10, 2010 05:11 |
|
Putty has a SFTP client. Most good GUI FTP clients support it too.
|
# ? Sep 10, 2010 05:17 |
|
Xinlum posted:Howdy. I'm taking my first programming class and want someone to check over my first lab assignment before I turn it in to make sure I'm not loving up stuff like comments and whatnot. We have to use machine language to make a program that will calculate the GCD of two integers in an emulated simple computer using Unix. No one's going to do your homework for you. If you're unsure of the logic, go through it on paper with a few inputs. As for your comments, some of them are just plain pointless (the comments are supposed to be for someone who understands the language), some are just confusing (repeats from step 1?).
|
# ? Sep 10, 2010 12:08 |
|
When it comes to comments inside their logic flow, I always tell my students "don't write comments explaining *how* you're doing something, unless it's clever or tricky in some way. Your *code* explains how, and your comments explain *why*." So a comment like "LOA B ; loads B into the accumulator" is pointless -- you haven't said anything that the instruction didn't already say, so you've just added more bytes to the file at that point. Your code should be well-written enough that a reader doesn't need comments to understand how it's doing something except in very complex cases. Now that's harder to apply to assembly language than a language like C++ or Java, so I would recommend instead of putting meaningless comments at the end of every line, comment larger blocks and describe what larger task it is supposed to accomplish.
|
# ? Sep 10, 2010 15:06 |
|
Oh please, are you guys serious? Yes, comments should be 'why' not 'how' in the industry, but it's his first programming language. The comments might be for him to remember the syntax. It also looks like he's not asking you to do his homework for him, just to help him out with something he's clearly attempted and having a bit of trouble with.
|
# ? Sep 10, 2010 15:56 |
|
We were supposed to comment on each line for this assignment, and step 1 refers to the algorithm we were given for calculating GCD. Sorry about that (but thanks for clearing it up anyway, I figured I would have to go comment crazy with everything after this). Also I asked for help with figuring this out because we haven't actually been given a way to actually test what we wrote without it spitting out a few hundred lines of binary. So my question still stands if adding a JMZ command for the BGTA part and the quick change of adding a LOA A line before I use STO C would fix it up. The storing the result part isn't needed but I figured I should probably try everything I can to get a good grip on it before we jump into learning this language our professor wrote.
|
# ? Sep 10, 2010 16:27 |
|
Orzo posted:Oh please, are you guys serious? Yes, comments should be 'why' not 'how' in the industry, but it's his first programming language. The comments might be for him to remember the syntax. It's about enforcing good habits early on. I took the same approach in a class that I taught this summer which as an intro to C++ for non-majors, many of whom had never done any programming before. Now if his assignment said that he should comment every line (as he's since posted), that's a different animal. At least we offered him some good advice instead of popping in and criticizing other posters without adding anything of substance to the discussion
|
# ? Sep 10, 2010 16:36 |
|
It wasn't so much about criticizing others as it was defending his original post, which I thought was perfectly fine. Comments are great for learning languages and bad in a work environment where everyone knows the language, I think it's plenty substance enough to offer an alternative viewpoint to your absolute dismissal of them. And honestly, the comment habit isn't one that is really that hard to break. I've seen a lot of people start where I work and add useless comments. Somebody takes 5 minutes to explain why they shouldn't do that, they learn, and it's over. Not a big deal!
|
# ? Sep 10, 2010 16:44 |
|
Orzo posted:Somebody takes 5 minutes to explain why they shouldn't do that, they learn, and it's over. Not a big deal! Which is exactly what I did I would have offered him more help on his assembly but I was writing the post on the bus. I don't think he was asking anyone to do his homework for him, it's pretty clear that he did the work and just wanted some advice.
|
# ? Sep 10, 2010 17:09 |
|
Orzo posted:And honestly, the comment habit isn't one that is really that hard to break. I've seen a lot of people start where I work and add useless comments. Somebody takes 5 minutes to explain why they shouldn't do that, they learn, and it's over. Not a big deal! It's easy to break the "stop making useless comments" habit, but oh so hard to cultivate the useful "post the correct types of comments" habit. Though I agree, when you're first starting out who really cares. You aren't building anything of consequence that would really need comments anyway and it's only once you're well past the "first programming class" phase that it become an issue.
|
# ? Sep 10, 2010 17:10 |
|
Flobbster posted:Which is exactly what I did And the thing about the homework was in response to Painless, not you.
|
# ? Sep 10, 2010 17:14 |
|
If you're starting out it's definitely important to comment everything. As you go on and learn programming parlance, you'll get a feel for what's obvious. "Why" is definitely important once you're in the real world, with future code-maintainers in mind. When you're starting out, though, "How" is important if only because it makes you think more critically about what you're doing. Even as a professional, "How" can also be important if you manage to come up with an exceptionally clever method of doing something that isn't necessarily intuitive. Regular Expressions are a great example of something where the more clever you are, the more opaque the methodology can be.
|
# ? Sep 10, 2010 18:30 |
|
1337JiveTurkey posted:[*]The moon is tide locked to the Earth. As far as you're concerned, this means the Earth is always going to be at the same spot in the sky and this is a function of your location on the moon. Wow, for all the thinking I was putting into figuring out phases and whatnot, this obvious constraint completely slipped my mind! The trick is that we have no means of determining our location on the moon. There's obviously no GPS, and a compass would be useless since the moon has no magnetic field. Using the stars is useful for figuring out what direction we're facing, but not really accurate enough to determine location. While we technically will have information available from Earth, our goal is make the robot as autonomous and self-contained as possible in its calculation. Chances are there will be two states: Scanning the sky to find the Earth -- and making adjustments to keep it centered once located. quote:[*]Barring some unusual circumstances, there are going to be two visible objects the size of the Earth in the sky. One of the checks performed will definitely be of a presence-of-blue histogram. I can't imagine a circumstance that would thwart this, unless the Earth is in a very narrow phase with a white storm cloud covering the entire sliver. quote:[*]Barring some completely loving bizarre circumstances, one of those two objects will have an apparent magnitude close to -27 and have the spectral distribution of a black body at 5700 K. This is new terminology for me, could you expand on these? And thanks a lot, I hadn't considered any of these and the prof wont be able to get the jump on me with them now
|
# ? Sep 10, 2010 18:41 |
|
Butt Cord posted:While we technically will have information available from Earth, our goal is make the robot as autonomous and self-contained as possible in its calculation. Knowing something about what angle the earth is at in the sky tells you something about where you are. Earth is the moon's Polaris - you just have to redefine north on the moon. quote:This is new terminology for me, could you expand on these? And thanks a lot, I hadn't considered any of these and the prof wont be able to get the jump on me with them now http://en.wikipedia.org/wiki/Apparent_magnitude http://en.wikipedia.org/wiki/Black_body He's saying the sun will always look exactly the same (barring a lunar eclipse - don't forget that).
|
# ? Sep 10, 2010 20:06 |
|
loving around in 64-bit x86 asm, did the basic hello world program and a program that reads a line from stdin and echoes it back to stdout, now I'm working on something like echo(1). As a first step, I tried writing a program that prints its first argument to stdout, but I'm not getting any output. The program is as follows:code:
|
# ? Sep 11, 2010 00:25 |
|
1337JiveTurkey posted:
That's not exactly true. The lunar orbit isn't circular (so the Moon appears to wiggle as it orbits the Earth) and it has other imperfections like a 9-year precession cycle and other precessions. 1337JiveTurkey posted:
No, only the Earth will be the size of the Earth. The Sun will be smaller, about the size of the Moon as viewed from the Earth.
|
# ? Sep 11, 2010 00:38 |
|
Otto Skorzeny posted:write(2) has the signature (int fd, char *buf, size_t count) and writes up to count bytes from buf to fd, so I thought this would work fine. What am I doing wrong For starters, you're using the 32-bit system call interface from a 64-bit process and I'm surprised that works at all.
|
# ? Sep 11, 2010 00:45 |
|
pseudorandom name posted:For starters, you're using the 32-bit system call interface from a 64-bit process and I'm surprised that works at all. Works for contrived examples (cf. hello.s and repeater.s), but is there some other syscall interface for 64 bit stuff that I ought to use?
|
# ? Sep 11, 2010 01:05 |
|
Yes, you should be using the 64-bit system call interface.
|
# ? Sep 11, 2010 01:10 |
|
pseudorandom name posted:Yes, you should be using the 64-bit system call interface. Is there some place this is documented? Reading the ABI docs from AMD and googling around hasn't turned anything up besides a recommendation on SO to look at the glibc source e: found it, was in section A2 of http://www.x86-64.org/documentation/abi.pdf: quote:User-level applications use as integer registers for passing the sequence %rdi, %rsi, %rdx, %rcx, %r8 and %r9. The kernel interface uses %rdi, %rsi, %rdx, %r10, %r8 and %r9. Switching to the correct registers to pass arguments made it work but also print a bunch of poo poo from the environment (the length I passed was still 128), so now I guess the task is to whip up an asm implementation of strlen. Hooray progress! Blotto Skorzany fucked around with this message at 01:38 on Sep 11, 2010 |
# ? Sep 11, 2010 01:20 |
|
Got the whole thing working, had the syscall numbers wrong too (they've also changed in x86_64) so I corrected them (if anyone here or a stray googler needs the linux amd64 or x86_64 syscall numbers in a handy reference, there's one at http://lkml.indiana.edu/hypermail/linux/kernel/0104.0/0547.html ) in addition to whipping up an implementation of strlen based on repnz scasb. Now I'm going to go drink.
|
# ? Sep 11, 2010 02:22 |
|
Otto Skorzeny posted:Got the whole thing working, had the syscall numbers wrong too (they've also changed in x86_64) so I corrected them (if anyone here or a stray googler needs the linux amd64 or x86_64 syscall numbers in a handy reference, there's one at http://lkml.indiana.edu/hypermail/linux/kernel/0104.0/0547.html ) in addition to whipping up an implementation of strlen based on repnz scasb. Now I'm going to go drink. Care to post the finished code? I haven't looked at x86 asm in years and not once at x86-64
|
# ? Sep 11, 2010 04:08 |
|
Why the gently caress notcode:
Some real obvious changes from x86 asm: syscalls are done via the syscall instruction rather than interrupt 0x80, syscall parameters are passed in the sequence rdi, rsi, rdx, rcx, r8, r9, write(2) is syscall number 1 rather than 4, exit(2) is number 60 rather than 1
|
# ? Sep 11, 2010 09:10 |
|
csammis posted:Care to post the finished code? I haven't looked at x86 asm in years and not once at x86-64
|
# ? Sep 11, 2010 09:28 |
|
shrughes posted:No, only the Earth will be the size of the Earth. The Sun will be smaller, about the size of the Moon as viewed from the Earth. You're right. I messed up the relative diameters from that perspective because I was thinking of the moon from the Earth, but I think the upshot is still very similar. The Earth is going to be the biggest drat thing in the sky on the Moon and while it may not be perfectly stationary, there's a limit to the area it can wander in the sky. Given that the rover is going to be using a ridiculously expensive embedded system, the most sensible thing to do is to plan for the average case to be as quick and simple as possible. Luckily there are several facts that do in fact make it quite simple in the big scheme of things.
|
# ? Sep 11, 2010 18:10 |
|
Orzo posted:classmate spotted Hah, I didn't even think about the question coming across like that. I graduated years ago.
|
# ? Sep 12, 2010 03:43 |
|
I have an SConstruct question that isn't as hippy abstract as my last ramblings, so I figured somebody might be able to say something about this. Why can't I have more than one target in my current directly referring to the same object files? I have two targets I build with different main functions that refer to some common code. SConstruct complains when it starts building the second one about this. I've resorted to just commenting out the target I don't particularly add at a moment, but that's a bit annoying. I read somewhere to the effect that each target should have a build directory. So is that the big rule of SConstruct? What's the least intrusive way I could change things to make it generally happy?
|
# ? Sep 14, 2010 18:40 |
|
Not strictly a programming question, and I know the subject of text editors can be... touchy, so I apologize in advance if I start a Holy War here. For most of my C++ work I've been using Sun Studio 12. Recently however (in the last week) doing anything in it has been dog-slow, to the point where I've leaned more and more on simpler editors like nedit until the sysadmin gets back from vacation and restarts the thing or reinstalls it or whatever he's gotta do. Anyway, most of my coworkers use emacs instead of Sun Studio, on the basis that that's what they've always been using, and it does seem like it can do what I need (project searching, syntax highlighting, indentation, find-declaration type stuff, etc). However, the command syntax is an absolute loving bugger, at least to me. So what I'm wondering is, is it worth the time to learn how to use emacs, or should I go looking for another C++ editor for when I don't feel like waiting 20 minutes for Sun Studio to fully load? Also, a specific question about emacs, how the hell do I make it accept the alt key as M- instead of A- ?
|
# ? Sep 14, 2010 19:03 |
|
I didn't see a thread for Fortran95, so I'll ask here- we're learning it for my Stat Mech class and while we've been given code to alter the random number seeds, I'm trying to find a way to make the seeds truly random (you have to set them manually in the given code). A friend of mine suggested using the time as a way to obtain seed values, but I'm having a hard time figuring out both how to call the date & time as well as how to set them as variables. Anyone know Fortran enough to help?
|
# ? Sep 15, 2010 06:13 |
|
C-Euro posted:Fortran95 date and time Use DATE_AND_TIME. shrughes fucked around with this message at 06:25 on Sep 15, 2010 |
# ? Sep 15, 2010 06:19 |
|
Simple concept that I haven't found much information on. I'm about to launch a website next week and I have one gaping hole in my security: People can post HTML and have it displayed on the site. I'm using PHP/CodeIgniter and I use form validation for everything and I also have XSS turned on site-wide, but apparently none of that will prevent people from inputting HTML. So far my simple, retarded solution that I haven't been able to research thoroughly is to do something like this: code:
TreFitty fucked around with this message at 11:34 on Sep 15, 2010 |
# ? Sep 15, 2010 11:29 |
|
TreFitty posted:Simple concept that I haven't found much information on. I'm about to launch a website next week and I have one gaping hole in my security: People can post HTML and have it displayed on the site. I'm using PHP/CodeIgniter and I use form validation for everything and I also have XSS turned on site-wide, but apparently none of that will prevent people from inputting HTML. If you're just after those HTML tags, then try replacing with < and > to give your users their input right back.
|
# ? Sep 15, 2010 12:06 |
|
You probably want to escape the html with htmlentities($stuff), unless I'm missing the point of what you're doing....
|
# ? Sep 15, 2010 16:51 |
|
Ledneh posted:Not strictly a programming question, and I know the subject of text editors can be... touchy, so I apologize in advance if I start a Holy War here. First of all, take all of this with a grain of salt because I've only used emacs for a few months and vi for a few weeks. NEdit is fantastic and if it supported UTF-8 I would probably still be using it. JEdit is like a modern NEdit with more features and a plugin architecture and a lovely XML format for syntax hilighting rules. However, it's not rocking' the classic Motif widget set. It can do most of the cool stuff emacs and vi can, but is still more a "language-aware editor" than an IDE - although plugins provide things like project management, integrated debugging, and whatnot. emacs and vi can be used as IDEs, but you will have to contend with: - both of them have a vicious learning curve - VI's cool features are hidden behind a UI written by, and for, aliens - emacs's cool features are provided by undocumented and poorly maintained third-party elisp scripts which can and will randomly break just when you need them So, I would say: it can be worth it, but you should also investigate whether more friendly editors like NEdit or JEdit do (or can be made to do) what you need. Now I wait for all of the emacs/vi users to explain why I'm wrong.
|
# ? Sep 15, 2010 18:03 |
|
If you like jEdit try Factor
|
# ? Sep 15, 2010 18:11 |
|
shrughes posted:Use DATE_AND_TIME. How? My plan is -Get date & time from computer, ideally hours:minutes:seconds:milliseconds or something -Store each part of the time as a variable -Set random number seeds to these values( iseed(1)=hour, iseed(2)=min, etc) I know DATE_AND_TIME is something I need to use but I can't seem to find just how to use it- do I call it like a random number? Can I tell it to write somewhere?
|
# ? Sep 15, 2010 18:34 |
|
ToxicFrog posted:
|
# ? Sep 15, 2010 18:48 |
|
I can't remember the last editor I used that doesn't have etags support; nedit jedit, emacs and vi all support it. NEdit-specific stuff: nedit won't automatically generate the tag file for you (although there may be a script for that). Once it's generated, though (using ctags, or etags, or 'make tags', or whatever), you can load it by hand with File->Load Tags File. The tag file, if loaded, will also be used for calltips. If you want it to autoload tags, you can either use 'nedit -tags <tagfile>' to launch it, or set the XResource nedit.tagFile to an (absolute or relative) path. Bear in mind that etags is not the same as a full IDE's intelligent parser; in particular: - the tags won't auto-update as you change the code, you need to re-run etags to update the tag file as you add/remove/change functions. - if you have lots of functions with the same name in different scopes, it can't always figure out which one you're referring to and will just list them all and ask you to choose one vvv ToxicFrog fucked around with this message at 21:22 on Sep 15, 2010 |
# ? Sep 15, 2010 19:28 |
|
|
# ? Jun 9, 2024 01:58 |
|
Don't worry, intelligent needs some :fingerquote:s around it when speaking of sun studio. Oi. Thanks, though, I'll look at nedit and see if it and etags play nice (edit: damnit where'd fingerquote go. Oh well)
|
# ? Sep 15, 2010 21:08 |