![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Aug 2005
Posts: 3
Rep Power: 0
![]() |
New to ASM
I am trying very hard to learn ASM, however the fact that I currently only use a Centrino processor makes it very had to learn from tutorials and books. If I try to use some of the code displayed in the book I will generally get a seg. fault or something of that nature... I'm not totally new to programming, I just can't seem to find use full documentation. Someone told me that the Intel Centrino was equivalent to the Intel P4 Mobile when it comes to instructions and all that, is this true? As there is a programmers manual that (although very long and not new programmer friendly) documents it's memory handling procedures as well as it's instructions/registers etc. Please, I would really like to learn ASM to give me a better understanding of high level programming such as C++ but I really need help getting off on the right foot! Thanks.
Oh, and looks like a great forum you guys have here, it's good to be a member. |
|
|
|
|
|
#2 |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,126
Rep Power: 5
![]() |
What assembler are you using? I recommend NASM, due to its cross-platform capability and zero price tag. You might need a linker as well; you should be able to find one of these, or may already have one that will work, if you have a C/C++ compiler.
Perhaps if you posted a small (ideally not more than a couple pages' worth of source code) program you're having trouble with, we can help. I highly doubt your processor is the issue; if I recall, the Centrino is just a low-power (as in power consumption, to prolong battery life) version of the Pentium (of whatever generation, P4 might be accurate). It's much more likely you've made an error, either in coding, or assembling/linking. Something you can try is writing simple DOS-based test programs. This will allow you to avoid many of the 'red tape' directives (such as naming your segments/sections to conform to what your linker expects), as well as allowing you to make flat binary programs (ie .COM files), skipping the link stage. You can use INT 21H to call DOS (primarily to print output). Run these from a DOS box or console window, and you will be able to learn how the various instructions work. Important ones to learn are the math ones (ADD, SUB, INC, DEC, MUL, DIV, etc), control transfer ones (JMP, CALL, RET, and the various conditional jumps), bitwise ones (AND, OR, XOR), and the MOV, INT, and CMP instructions. You should also learn about the CPU flags (mainly zero, parity, carry, and overflow), how the instructions modify these flags, and how memory is addressed (including what a stack is, and how it works). There are a lot of other useful instructions, but with these building blocks, you will have a lot of power. You'll also notice that many correspond directly to C/C++ constructs.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Aug 2005
Posts: 3
Rep Power: 0
![]() |
Im sorry, I forgot to mention that I am coding under Linux. I'm using Debian, and of course, I'm using gas to compile and ld to link.
|
|
|
|
|
|
#4 |
|
Professional Programmer
|
You can still get NASM as a .deb, and I'd recommend it.
__________________
% rc4 hexkey < input > output
#define S ,t=s[i],s[i]=s[j],s[j]=t /* rc4 hexkey <file */
unsigned char k[256],s[256],i,j,t;main(c,v,e)char**v;{++v;while(++i)s[
i]=i;for(c=0;*(*v)++;k[c++]=e)sscanf((*v)++-1,"%2x",&e);while(j+=s[i]
+k[i%c]S,++i);for(j=0;c=~getchar();putchar(~c^s[t+=s[i]]))j+=s[++i]S;} |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Aug 2005
Posts: 3
Rep Power: 0
![]() |
Yeah, I'm probably doing something wrong. Ok, I'm thinking that a good way to learn ASM would be do disassemble running programs or using the -S switch for gcc to get it to compile the source into ASM only. Then maybe I could compile it using as and link it using ld? I don't really know, if anyone has a suggestion or a link to a tutorial I'm all ears!
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: Aug 2005
Posts: 1
Rep Power: 0
![]() |
Hi James - I'm Nasmist too, but (G)as works. Jonathan Bartlett's "Programming from the Ground Up" uses Gas syntax, and covers programming for Linux... well, "from the ground up"...
http://www.cafepress.com/bartlettpublish.8640017 or the "free, as in freeloader" version: http://savannah.nongnu.org/download/pgubook/ A web site to check out is: http://linuxassembly.org Mirrored at: http://asm.sf.net There's a "new twist" in kernels newer than 2.6.10 - you *must* have a writable section *last* in your executable. This won't give you any trouble with Gas - it gives you a ".data" section whether you ask for it or not. Other assemblers - Nasm or Fasm - give you enough control so you can get in trouble with this. Segfaults before your program even loads! This isn't a "kernel bug"... exactly. As a security measure, they check the return value of some functions that were ignored in previous kernels. Just something that Linux asm programmers have to know about. Ignore the indignant squawking from the Penguin ![]() Best, Frank |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|