LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices

Reply
 
LinkBack Search this Thread
Old 11-18-2009, 09:36 PM   #1
Mol_Bolom
Member
 
Registered: Nov 2008
Location: S.W. Kansas
Distribution: Slackware-13.37
Posts: 208
Blog Entries: 2

Rep: Reputation: 41
Bored, so yackin bout asm...


Well, I began learning assembler about 3 weeks ago, and it's not too shabby. Quite interesting, and takes me back to my days of using int86(&Hxx, AX, BX, CX, DX...) or with qb int86old() on my ol 486.

Though, the only problems I have come across are a few things that just comfuddle me. I had, for the longest time, thought ah, al were the upper and lower bits of ax. Now, it's still the same, but with memory addresses, nope, that's not the case. Somehow al is the byte where ax points to...Oooohkay...At least in one of the programs I wrote testing different ways to get a character from a string that I found that out.

Another problem, well it's really not a problem more of an unknown, is understanding the difference between eax and ax. I know the difference between 32 and 16, it's just trying to figure out what exactly that means data-wise. Of course I still have a bit of reading to do, so...eh...but doing all this has helped me learn how to use gdb, as well. So I'm killing two birds with one stone, so to speak.

Another thing I'm finding fairly fun, is trying out x86, or as, oh holy hell. Not that as is hard, but my fingers are not dexterous enough to use the shift key efficiently enough for $ and % for every single bloody register and number. So I have been mostly sticking with nasm, don't have to press the shift key but every once in a great while. Although, I might switch from nasm once I'm finished with another keyboard layout I'm busy writing, well, once I have an idea for it then I'll begin to write it.

Now there is one thing that I find quite interesting. I have always read how ingrained c was in linux, but I had no idea just how much so. Back in my ol DOS days, if I need to know the registers and interupts, all I had to do was look up the interupts (wherever I'd find them at, which was quite often in many places), read up, and voila, I could get something done with direct calls. However, with linux, it looks like most of the information is written for c. I've found a reference to the system calls, but it's all written for c, doesn't say anything about the registers that are accessed or need to be set to for what needs to be done. Probably means I need to scour the c include files to figure that out. Though there are the man pages, at least from one place I've read that, but all it said was to read the man pages, not "what" to read. Again, more reading...No problem. I ain't expecting to figure this out any time soon...

As of now I'm half way through the pcasmbook, and the first couple or so chapters in another pdf file for x86, as well as I've read quite a few pages of the nasm manual. So much to read, but I think it's fun, even exhilerating. It also helps to drive my wife nuts when I tell her what I'm doing......

Hey, for any of you programmers that happen to make it this far down, what's with the million and one Hello world examples? Just how many Hello World examples need there be? One would think that by now there would be something different. Well, whatever...I'm way passed that now...

I've learned how to pass arguments to functions, though that's another thing that tickles me the wrong way. I see the stack from down up, and right left, not left right top down. Such as when I "push" I expect that I'm shoving it up into the stack. However, when I wrote a small c program to use a function written in nasm, it took me a while to figure out what was wrong. Wasn't until I tested it in reverse that I found out the problem. So I have to tell myself over and over, when I "push" I'm shoving it down into a hole, and to "pop" I'll have to pull it up...Eh, I'm wierd that way...

Eh, anyway, that's my yack. Not very well structured not informative, but I'm bored, and quite frankly I just don't give a damn......
 
Old 11-19-2009, 02:03 AM   #2
resetreset
Senior Member
 
Registered: Mar 2008
Location: India
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,177

Rep: Reputation: 48
Great yack, keep em coming

I personally learnt ASM for the first time on my old ZX Spectrum back in 1987, then again in 96/97 when I shifted to the PC, had to adapt myself to the x86.
Programming ASM in Linux somehow just isn't as *satisfying* as on DOS, where you have the whole machine to yourself and can tamper with it as you like. So kudos to you for trying (at least you get the pleasure of a debugger like GDB, as you've mentioned).
 
Old 11-19-2009, 02:35 AM   #3
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: washington U.S.
Distribution: Damn Small Linux, KateOs, M$ Ickdows Vista, My own OS
Posts: 2,094

Rep: Reputation: 104Reputation: 104
Quote:
Another problem, well it's really not a problem more of an unknown, is understanding the difference between eax and ax. I know the difference between 32 and 16, it's just trying to figure out what exactly that means data-wise. Of course I still have a bit of reading to do, so...eh...but doing all this has helped me learn how to use gdb, as well. So I'm killing two birds with one stone, so to speak.
your kidding right? AX is to EAX as AL is to AX.
Quote:
Another thing I'm finding fairly fun, is trying out x86, or as, oh holy hell. Not that as is hard, but my fingers are not dexterous enough to use the shift key efficiently enough for $ and % for every single bloody register and number. So I have been mostly sticking with nasm, don't have to press the shift key but every once in a great while. Although, I might switch from nasm once I'm finished with another keyboard layout I'm busy writing, well, once I have an idea for it then I'll begin to write it.
theres a flag you can pass to mimic nasm, don't remember what it is because i don't use gas.
 
Old 11-19-2009, 10:24 AM   #4
Mol_Bolom
Member
 
Registered: Nov 2008
Location: S.W. Kansas
Distribution: Slackware-13.37
Posts: 208
Blog Entries: 2

Original Poster
Rep: Reputation: 41
Quote:
Originally Posted by smeezekitty View Post
your kidding right? AX is to EAX as AL is to AX.
I had thought this, but haven't seen what is to EAX as AH is to AX...That's basically what I'm wondering. <See diagram below>
Code:
               EAX
     ??                  AX
??      ??       AH       AL
                                  |
                                  |
                   nibble          nibble
                 bit     bit      bit     bit
This might be just because I'm rather nuts trying to look at RAX, EAX in the same way that I look at AX, the same way I look at binary, 1 bit, 2 bits = nibble, 2 nibbles = byte, 2 bytes = word, etc and wanting to know what it all is, even though I may never need it. Eh, it's not important though. I'll figure it out sooner or later......
 
Old 11-19-2009, 12:42 PM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 1,421

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Quote:
Originally Posted by Mol_Bolom
I had, for the longest time, thought ah, al were the upper and lower bits of ax.
Yes.

Quote:
Now, it's still the same, but with memory addresses, nope, that's not the case. Somehow al is the byte where ax points to...
I don't know what that means.

Quote:
RAX, EAX in the same way that I look at AX, the same way I look at binary, 1 bit, 2 bits = nibble, 2 nibbles = byte, 2 bytes = word,
A nibble is 4 bits, a byte is 8 bits (2 nibbles), the size of a word is usually the size of the registers (16-bits on a 16-bit compuer, 32-bits on a 32-bit computer) but Intel generally calls 16 bits a word, and 32 bits are a dword (double-word).

Quote:
I had thought this, but haven't seen what is to EAX as AH is to AX
There is no name for the upper 16 bits of EAX, and no name for the upper 32 bits of RAX.

Code:
                       EAX
               _                 AX
           _       _        AH        AL
                                  |
                                  |
                      nibble          nibble
                   bit bit bit bit  bit bit bit bit
See x86 registers
 
Old 11-19-2009, 01:22 PM   #6
mjones490
Member
 
Registered: Sep 2005
Distribution: LFS
Posts: 60

Rep: Reputation: 22
Quote:
Originally Posted by Mol_Bolom View Post
Hey, for any of you programmers that happen to make it this far down, what's with the million and one Hello world examples? Just how many Hello World examples need there be? One would think that by now there would be something different. Well, whatever...I'm way passed that now...
Whenever someone embarks on learning a new programming language, typically the first thing they do is learn how to output some characters to the screen. Then they go on about learning other features such as setting variables, loops, etc., the results of which need to be output to the screen, which they have already learned how to do as part of the first lesson.

So, what characters should we output to the screen as our first lesson? Well, why not a nice greeting! A greeting. . . Hmmm. . . How about, "Hello"? Yeah! And who are we greeting? Well, I suppose everybody, or "the world". So the first characters we output to the screen during the first lesson of a new programming language are "Hello, world!"

If it's your first programming language, you might get super excited at having told the computer what to do. "Holy shit!! Look, ma!! It says 'Hello, world!' Woo-hoo!! We could make it say other things! Hey, I bet we could. . .", until Dad whacked me upside the head and barked at me to settle down, for Christ's sake.

What was the question again?
 
Old 11-19-2009, 03:18 PM   #7
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: washington U.S.
Distribution: Damn Small Linux, KateOs, M$ Ickdows Vista, My own OS
Posts: 2,094

Rep: Reputation: 104Reputation: 104
Quote:
Originally Posted by mjones490 View Post
Whenever someone embarks on learning a new programming language, typically the first thing they do is learn how to output some characters to the screen. Then they go on about learning other features such as setting variables, loops, etc., the results of which need to be output to the screen, which they have already learned how to do as part of the first lesson.

So, what characters should we output to the screen as our first lesson? Well, why not a nice greeting! A greeting. . . Hmmm. . . How about, "Hello"? Yeah! And who are we greeting? Well, I suppose everybody, or "the world". So the first characters we output to the screen during the first lesson of a new programming language are "Hello, world!"

If it's your first programming language, you might get super excited at having told the computer what to do. "Holy shit!! Look, ma!! It says 'Hello, world!' Woo-hoo!! We could make it say other things! Hey, I bet we could. . .", until Dad whacked me upside the head and barked at me to settle down, for Christ's sake.

What was the question again?
LOL
 
Old 11-19-2009, 06:50 PM   #8
Mol_Bolom
Member
 
Registered: Nov 2008
Location: S.W. Kansas
Distribution: Slackware-13.37
Posts: 208
Blog Entries: 2

Original Poster
Rep: Reputation: 41
Quote:
Originally Posted by mjones490 View Post
What was the question again?
I guess it's too late to say that was a retorical question?

Ah hell, you already went through the trouble to explain the purpose of them...Guess the only thing to do now is to write the hello world programs...

c
Code:
#include <stdio.h>

int main(void)
{
     char *message = "Hello world!";
     printf("%s\n", message);
     return 0;
}
QBasic, RQBasic, FreeBasic...
Code:
DIM message AS STRING
message = "Hello world!"

PRINT message
Nasm
Code:
segment .data
message:  db  "Hello world!",0
msglen:    equ $-message
segment .text
                  global _start

_start:
                  mov eax, 4
                  mov ebx, 1
                  mov ecx, [message]
                  mov edx, [msglen]
                  int 80h

_exit:
                  mov eax, 1
                  mov ebx, 0
                  int 80h
There, there's a million and four hello world examples, now......
 
Old 11-20-2009, 08:09 AM   #9
mjones490
Member
 
Registered: Sep 2005
Distribution: LFS
Posts: 60

Rep: Reputation: 22
Smeezy has an nice obfuscated version of the "Hello, World!" program in another thread here in General.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASM x32 vs ASM x64 Tegramon Programming 3 02-27-2008 02:26 PM
where are you? (im bored) phantom_cyph General 20 03-01-2007 10:20 AM
Bored? Sepero General 2 01-27-2007 01:37 AM
Are You BORED? voodooutt General 21 12-02-2003 09:10 AM
For those of you who might be bored ! bigjohn General 6 08-25-2003 04:50 PM


All times are GMT -5. The time now is 02:27 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration