DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 6th October 2009
lionsong lionsong is offline
Port Guard
 
Join Date: Oct 2009
Posts: 12
Thanked 0 Times in 0 Posts
Default Undertaking computer science degree, which BSD for learning professional assembly?

Iv previously used openbsd extensively for my desktop system, only changing to slackware linux recently as i am now undertaking a computer science degree, and wanted to make sure i could follow the assembler based components of the course. (This isnt to say assembly on linux = FTW and assembly on bsd = fail, just most of the documentation iv found surrounding assembly and unix is weighted towards linux.)

However i really want to switch back to openbsd.

Im not running a server at home (yet) and im not studying cryptography in any way, apart from for my own interests, but im very much inspired by the principles of standardization and code correctness the openbsd team expouse - this to me seems to be a set of "good practice" habits that as a fledgling programmer i would do well to get into.

Also the portability of openbsd is going to be a hell of alot of fun when we start working with embedded systems. The inclusion of the full GNU toolchain and a strict adherence to free-software also leads me to think openbsd is an ideal OS to learn programming (the right way).

Iv read several documents on the net, though nothing signifcantly insightful as to how nasm or asm differ between linux and BSD (lots of references to how a.out is outdated compared to ELF but little else for the neophyte like myself).
The freebsd project maintains a developers handbook which contains some decent information, but again im still left a little in the dark, most likely due to my inexeprience with assembly language and what it requires.

SO my question is this - what do i, as a novice assembly programmer need to watch out for when using nasm or asm on openbsd, or would i be better off using FreeBSD for the time being? At least that way im still utilising a BSD methodology. Would it be better i just stick with linux?

Hope iv not confused any matters here, as i pointed out i am a novice programmer so all and any help is welcome!
Reply With Quote
  #2   (View Single Post)  
Old 6th October 2009
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 3,710
Thanked 214 Times in 189 Posts
Default

AFAIK, and I don't "K" very much, the only assembly-language code included in OpenBSD is in very specific places, such as boot blocks. See the assembly language (.S) files in src/sys/arch/i386/i386/ for example.

The assembler included with the comp*.tgz file set is /usr/bin/as. It's man page is AS(1), and it is part of the GNU binutils.

The Netwide Assembler can be found in ports/packages: devel/nasm. Also in devel/ are yasm and fasm.

It matters not what assembler you use. It matters what you assemble.
Reply With Quote
  #3   (View Single Post)  
Old 6th October 2009
Beastie Beastie is offline
Daemonology student
 
Join Date: Jan 2009
Location: /dev/earth0
Posts: 270
Thanked 23 Times in 23 Posts
Default

The biggest difference between Linux and *BSD assembler is the way interrupts are called.

The following is related to FreeBSD, but it must not be *too different* for OpenBSD.
Years ago, there was a website called FreeBSD Hackers and they had two tutorials but it's down now. You can still get the first one here.
Also check http://int80h.org/.

Don't forget you may have to brand ELF files manually.
__________________
May the source be with you!
Reply With Quote
  #4   (View Single Post)  
Old 6th October 2009
lionsong lionsong is offline
Port Guard
 
Join Date: Oct 2009
Posts: 12
Thanked 0 Times in 0 Posts
Default

Thanks for the reply, all input is good input!
Thinking about it i should have probably submitted a more considered OP, as im aware of the as and nasm assemblers, and i wasnt expecting alot of open assembly code inside any operating system outside of the boot processes.

What im concerned about is writing my own assembly on a BSD system and having to utilise a non-standard or difficult format to get my code to work.

I understand there is a difference between microsoft/linux and the unix way of doing assembler, can any openbsd as/nasm heads out there clarify it for me?
Reply With Quote
  #5   (View Single Post)  
Old 6th October 2009
lionsong lionsong is offline
Port Guard
 
Join Date: Oct 2009
Posts: 12
Thanked 0 Times in 0 Posts
Default

sorry beastie you posted while i was writing my reply! thanks for the info and link!
Reply With Quote
  #6   (View Single Post)  
Old 6th October 2009
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Helpful companion
 
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Thanked 193 Times in 184 Posts
Default

Both Linux and BSD use AT&T syntax assembly on i386/amd64 systems, but for system calls.. arguments must be passed on the stack instead of in registers (..DOS/Windows do it the Linux way as well, Unix systems traditionally use the stack).

Creating x86 assembly programs on OpenBSD is is a little difficult, but a few (..nefarious) tutorials exist on the mater.

As mentioned in that guide, OpenBSD needs a special section to brand the ELF executable.. because otherwise the ELF loader confuses it for something wanting to use a compat_*(8) layer.

While learning assembly is commendable, portability is definitely something you should consider.. and while both OpenBSD and Linux may share a few historic Unix system calls (..perhaps even numbering) it is not a guarantee and behaviour of these aforementioned routines may not be identical.

In summary, you may be able to adapt Linux assembly programs for OpenBSD.. but this will be difficult for a novice, source compatibility on Unix-like systems end at the C API level.

Good luck..
Reply With Quote
  #7   (View Single Post)  
Old 6th October 2009
lionsong lionsong is offline
Port Guard
 
Join Date: Oct 2009
Posts: 12
Thanked 0 Times in 0 Posts
Default

Thanks alot BSDfan, Beastie and jggimi, that clears things up nicely.
Looks like it'll be a ball ache, but I still want to use BSD for my course, the documentation alone makes it in my eyes the ideal os for developement of any kind, am i right in thinking that the manual ELF branding required will be across every BSD spin not just OpenBSD?
Having read abit more into the FreeBSD developers manual there is a a decent amount of information with regards to assembly coding nuances on Free*, how easily will that information translate to Open*?
Thanks again.
Reply With Quote
  #8   (View Single Post)  
Old 7th October 2009
IdOp's Avatar
IdOp IdOp is offline
Too dumb for a smartphone
 
Join Date: May 2008
Location: twisting on the daemon's fork(2)
Posts: 566
Thanked 14 Times in 13 Posts
Default

Quote:
Originally Posted by lionsong View Post
all input is good input!
In the spirit of that comment, let me throw out a totally different idea.

Have you considered the possibility of getting some old "beater" box ... 80386 or whatever ... and putting DOS on it and doing assembly there? You can use nasm. This way you're not running in protected mode, and you can (and will) crash the machine to your heart's content ... and learn a lot doing so!
Reply With Quote
  #9   (View Single Post)  
Old 7th October 2009
ocicat ocicat is offline
Administrator
 
Join Date: Apr 2008
Posts: 2,888
Thanked 190 Times in 160 Posts
Default

Quote:
Originally Posted by lionsong View Post
SO my question is this - what do i, as a novice assembly programmer need to watch out for when using nasm or asm on openbsd, or would i be better off using FreeBSD for the time being?
Perhaps you have already answered this question to yourself, but it is not evident from your description. You should ask your instructor what they are going to be doing in the course, & whether they have requirements later in the curriculum which necessitates one platform over another. If they are a Linux-head who expects everything to be done from a Linux slant, then you may be better off going down the road which is expected.
Reply With Quote
Old 7th October 2009
lionsong lionsong is offline
Port Guard
 
Join Date: Oct 2009
Posts: 12
Thanked 0 Times in 0 Posts
Default

Thank ocicat, in fact yesterday i did just that. The assembly parts of the course are more concerned with hardware manipulation and IO, the platform wont really be considered apparently, just whether or not it works. Even if its harder to get working on BSD, im not one to do things the easy way
IdOp>> very interestting idea! could you direct me to some online DOS resources?? pretty sure an i486 box will be easy to come by, if i dont already have one in an attic somewhere...
Reply With Quote
Old 7th October 2009
Beastie Beastie is offline
Daemonology student
 
Join Date: Jan 2009
Location: /dev/earth0
Posts: 270
Thanked 23 Times in 23 Posts
Default

Quote:
Originally Posted by lionsong View Post
The assembly parts of the course are more concerned with hardware manipulation and IO
In that case, do as IdOp proposed and get a *DOS system (you're not limited to just MS-DOS). Working in real mode with no constraints will make it easier to do what you need to do.



EDIT: Sorry, I only read one part of your message.
There are *many* DOS assembly resources on the Internet. I'm sure a google search would return a lot.

You may want to check these:
Gavin's guide to 80x86 assembly: http://www.intel-assembler.it/portale/indice.asp?pg=107
The DOS Help Magazine (6 issues): http://www.frontiernet.net/~fys/dhmag.htm
The Assembly Programming Journal (9 issues): http://mattst88.com/programming/?page=APJ
For a general Intel architecture and assembly reference, nothing is better than the Intel manuals: http://developer.intel.com/products/...uals/index.htm (you'll be interested in vol 1, 2a and 2b ; 3 is more for OS programmers)
Finally, Ralf Brown's Interrupt List, the best interrupt reference (BIOS, DOS, etc.): http://www.ctyme.com/rbrown.htm

As for the assembler itself, nasm is not the only choice. You can check fasm: http://flatassembler.net/
__________________
May the source be with you!

Last edited by Beastie; 7th October 2009 at 02:04 PM.
Reply With Quote
Old 7th October 2009
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Helpful companion
 
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Thanked 193 Times in 184 Posts
Default

If you decide to use DOS (..16-bit real mode environment, not protected mode..), you may end up having to learn more about the x86 architecture then you intended.. if the coarse assumes a 32-bit environment has already been established.

Think of real mode like an early mode of operation that no other modern architecture has, other platforms supported by *BSD and Linux typically boot up directly into 32-bit or 64-bit modes.. something unheard of in the x86 world, so I would actually avoid learning about it and even opt for 32-bit assembly programming on OpenBSD as an alternative.

Instead of pulling your old i486 out of the attic(..do it anyway, OpenBSD will likely run on it), several emulators are available on OpenBSD.. consider QEMU, BOCHS or DOSBOX if you decided to go down that route.

Hope that helps..
Reply With Quote
Old 7th October 2009
IdOp's Avatar
IdOp IdOp is offline
Too dumb for a smartphone
 
Join Date: May 2008
Location: twisting on the daemon's fork(2)
Posts: 566
Thanked 14 Times in 13 Posts
Default

Quote:
Originally Posted by lionsong
IdOp>> very interestting idea! could you direct me to some online DOS resources?? pretty sure an i486 box will be easy to come by, if i dont already have one in an attic somewhere...
It's been 10+ years since I played much with x86 assembly, so I'm not really up on all the latest resources, and am grateful to Beastie for the great links he gave up-thread. The Ralf Brown interrupt list is a must have. I'll try to add a few classic things:

* For DOS free/share-ware there's the massive Simtel Archives.
You can find nasm and other pre-compiled utilities here. Some of them will even have source code some of which may be in asm.

* Ray Duncan's book "Advanced MSDOS Programming" (Microsoft Press) ... hopefully you can find it in a library or garage sale! (Don't be put off by the "Advanced" word in the title.)

* There are various books about x86 assembly usually tied closely to some particular product like Turbo or Microsoft Assembler. One that I read, which is not the worst (but probably not the best either) is "The Waite Microsoft Macro Assembler Bible" by Barkakati (SAMS). One trouble with these kind of books is that they use the Intel/Microsoft syntax, but there's a lot of that around the DOS world so you may have to get used to it, try to get the general concept out of whatever source you're looking at, and then translate to AT&T syntax if you wish.

Quote:
Originally Posted by BSDfan666
If you decide to use DOS (..16-bit real mode environment, not protected mode..), you may end up having to learn more about the x86 architecture then you intended.. if the coarse assumes a 32-bit environment has already been established.
True, I guess we don't know that one way or the other yet. Is the purpose of the course to re-write cat in assembly tying in to a few BSD system calls, or is it to get one's hands dirty and deal directly with hardware? If it's more the latter then a certain amount of specific architecture knowlege will be needed.
Reply With Quote
Old 7th October 2009
ephemera's Avatar
ephemera ephemera is offline
Knuth's homeboy
 
Join Date: Apr 2008
Posts: 537
Thanked 49 Times in 43 Posts
Default

If you are programming on Dos, "Mastering Turbo Assembler" by Tom Swan is excellent but it's now out of print.
For Unix I found "Professional Assembly Language" by Richard Blum quite useful. "Asm step-by-step" by Jeff Duntemann is also good.

Along with a good book you will also need an OS specific guide/tutorial. Asm on Unix is not well documented so you will need to figure out some stuff by yourself.
I think the fbsd dev. handbook has a section on asm.

For x86 there is the AT&T/Unix syntax(as) & the Intel syntax(nasm). But the difference b/w them is just that; syntax. If you know assembly well in one of them you can figure out the other one too, besides asm is hard to read anyway.

IMO, Intel assembly kinda sucks and 16-bit x86 asm (segmented memory/DOS) is a pain in the *, 32-bit asm on Unix/Windows is a "lot" better.

Personally, I use GNU as - not great but it's ok.
I would suggest that you use whatever your instructor recommends. Once you get the hang of it you can try it on BSD.

Learning Asm is (still) useful. It can be used to optimize sections of code for speed/size, debugging/disassembly or for doing stuff you can't do in C.
It's even useful if you don't ever plan to write code in asm as it improves your understanding of the m/c.
Reply With Quote
Old 7th October 2009
lionsong lionsong is offline
Port Guard
 
Join Date: Oct 2009
Posts: 12
Thanked 0 Times in 0 Posts
Default

Brilliant! Thanks for all the information guys and gals, the bsd communities have to be some of the most cohesive iv talked too!
Reply With Quote
Old 18th October 2009
TerryP's Avatar
TerryP TerryP is offline
Arp Constable
 
Join Date: May 2008
Location: USofA
Posts: 1,547
Thanked 112 Times in 104 Posts
Default

One can always use an emulator like program (e.g. virtualbox, qemu, etc) to run a separate system, either for a dos box or a nearer to bare metal affair.

I've often considered using VirtualBox as a platform to play with things that are either 'hard' under an existing operating system, or prone to crashing things during R&D.
__________________
My Journal

Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
learn assembly ephemera Book reviews 5 26th December 2012 06:29 PM
Assembly and kernel programming. bsdnewbie999 Programming 9 17th May 2009 05:52 AM
Learning Programming Crypt Programming 35 27th October 2008 04:54 PM
Learning Perl mtx Book reviews 7 22nd October 2008 05:55 PM
Suggestions for my honours degree project... scotsman FreeBSD General 7 20th September 2008 01:38 PM


All times are GMT. The time now is 12:11 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick