flat assembler
Message board for the users of flat assembler.

Index > Main > How can I program Assembly without using libraries and apis?

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 08 Jun 2012, 20:47
Glad to become a part of the forums!

Here's my problem:
I am very interested in assembly and after a lot of research I've chosen FASM because of the active community and the minimalistic but powerful cornerstone on which it is built. I've been a PHP programmer for years, but never really cared about how it worked, just that it worked. But now I find myself wanting to explore something more. That 'more' is Assembly. To make a long story short....Here's what I know and what I don't know, and why I'm hoping someone here can give me guidance. Thanks in advance!

: I want to deal with x86 32-bit/64-bit exclusively
: I've read Assembly Step-by-Step cover to cover a few times, but it uses nasm and nasm's not what I want, and I haven't grasped enough knowledge to apply code conversions between different assemblers.
: I have done some 16-bit console dabbling with the 8086 microprocessor emulator; nothing grand, just basic 'Hello World type stuff'
: I'm starting to understand registers, still confused by the stack, and have been trying to memorize the basic Intel Instruction set that came with the 8086 emulator as well as the ascii table

This is what I want to accomplish with assembly...
I know I may be re-inventing the wheel, but I like the idea of knowing I can do something on my own without having to rely on something already in place...which is why I didn't look into C/C++ for my goals...I want to develop my own programming language that will be focused on OS development with Integrated Web/Internet programming abilities. Kind of a general purpose language that has not only the ability to create apps, but design for the web too. Please keep in mind, this is just a hobby I want to pursue to see if I could accomplish it. It may take the next 40 years and x86 may no longer be around, but this is my goal. What I'm having trouble understanding at this point, because I'm just getting my feet wet is...how to develop 32-bit functionality(I'll worry about 64-bit if I live long enough to get that far..LOL) that is completely OS Independent and how would I start such a task as this? Every tutorial or book or online pdf I've read usually involves win32 libraries or win api's or some sort of library or api specific to linux, etc, etc, etc....and I think I read somewhere here on the forums that windows requires you utilize their OS to sort-of hand-off the apps and what-not so that the OS can handle how to utilize the apps/programs...as if there is no way to by-pass it for independent design. I may be wrong but I think I understood that correctly...Please enlighten me...I have 32-bit windows vista and 64-bit windows 7 and I've installed fasm on both of them, cause I don't know if I can develop 32-bit apps on the 64-bit...anyways at least i've got a stable computer to work on either way... So how can I program Assembly without relying on the libraries, and api's of other OS Platforms???
Sorry for the long intro, but I really need some help trying to understand the concepts before I start trying to apply some coding. Thanks again!

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com
Post 08 Jun 2012, 20:47
View user's profile Send private message Visit poster's website Reply with quote
Inagawa



Joined: 24 Mar 2012
Posts: 153
Inagawa 08 Jun 2012, 22:12
Hello, as a fellow newbie, I'd like to welcome you here. I have grasped a few things here and there and I'd be happy to share my knowledge, tutorials or books.

And yes, you can develop 32bit applications on a 64bit computer.
Post 08 Jun 2012, 22:12
View user's profile Send private message Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 09 Jun 2012, 00:36
Thanks for the reply! I must've asked a rather unusually question...lol...I was beginning to think no one really had an answer..but thanks for offering your knowledge as insight. So, tell me,..what has helped you the most during your assembly quest thus far?

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com
Post 09 Jun 2012, 00:36
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19468
Location: In your JS exploiting you and your system
revolution 09 Jun 2012, 01:58
newport: Have a look at the OS Construction section on this board. There are many examples of boot code and minimal programs that run on the CPU without the need for any other OS.
Post 09 Jun 2012, 01:58
View user's profile Send private message Visit poster's website Reply with quote
Stephen



Joined: 13 Aug 2011
Posts: 30
Stephen 09 Jun 2012, 03:14
A lot depends on what you mean by "completely OS Independent". most of the 'modern', Intel CPU, multi tasking, OS's get nasty with your program if you try to directly access any of the hardware. To access the hardware in any way you package up your data the way the os wants you to and ask the os to access the hardware. You can still write 16bit, 32bit or even 64 bit programs that don't require an OS at all. You can also write your own OS or along the lines you are talking, you can write a language ide that directly boots. Depending on hgow you look at it, the language doesn't need an OS or the language is the OS.

There is TatOS that boots you right into an ASM IDE
MikeOS that boots you right into a Basic IDE (kins of like a lot of the old 8 bit computers)
Post 09 Jun 2012, 03:14
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 09 Jun 2012, 03:15
Thanks revolution. Will do. I saw that section early but didn't have a chance to look through it... and to tell you the truth I wasn't entirely sure that was where I should begin, but I will definitely take your advice and start there. At least now I have a direction. Thank you!

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com
Post 09 Jun 2012, 03:15
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 09 Jun 2012, 03:23
Thanks Stephen..That makes a lot of sense in that the language is the OS. I never looked at it from that perspective. It most certainly seems logical. Coming from high-level to low-level; for me at least; is gonna take some thought re-processing and rearranging...All you guys responses have been great so far and is exactly what I've been needing to find...

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com
Post 09 Jun 2012, 03:23
View user's profile Send private message Visit poster's website Reply with quote
Inagawa



Joined: 24 Mar 2012
Posts: 153
Inagawa 09 Jun 2012, 05:46
Well, about learning the 86 Instruction Set, the best three sources were the Intel Manual, FASM.pdf in the folder that your FASMW is, and this.

A good explanation of which registers to use for what can be found here.
Post 09 Jun 2012, 05:46
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4314
Location: Now
edfed 09 Jun 2012, 13:04
programming from scratch lead to library, it is a fundamental fact. every time you will use the call instruction, you will call a function, and a function is always part of a library.

a library don't have to be a DLL or a linux package, it can be a set of functions in your code that will do elementary things.

even the cpu instruction set can be seens as a library from this point of view.

about coding your os, it is very good (from my point of view) because you will first try to understand your needs, and translate it in code, without any external ideas.
ones you got a working set of code, you will finally find that you have reinvented the wheel, but your wheel will be very different from what still exists.

using the wheel analogy, you can consider a wheel as just a disk, or as a complex object composed by brakes, axle, motor, tires, or even more complex thing.

and as revolution say, the more difficult thing when reinventing the wheel is to choose it's color.
Post 09 Jun 2012, 13:04
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 10 Jun 2012, 22:20
thanks to everyone for all the great responses! i'm starting understand more already....

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com
Post 10 Jun 2012, 22:20
View user's profile Send private message Visit poster's website Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 10 Jun 2012, 22:45
As edfed said, you'll always need to use OS calls for an application. With this in mind, you'll probably want to define a set of generic OS calls and implement OS-specific wrappers for each OS you want it to run on; you can then put the core functionality into a common code group.

This makes things a little more complicated to start off with but should be easier for development and debugging.
Post 10 Jun 2012, 22:45
View user's profile Send private message Reply with quote
bubach



Joined: 17 Sep 2004
Posts: 341
Location: Trollhättan, Sweden
bubach 11 Jun 2012, 14:00
This is a great book for learning, which I used many times when starting out on my own OS. Even if the examples is for nasm and DOS, it will teach you about registers, stack and instruction usage.
http://www.drpaulcarter.com/pcasm/
Post 11 Jun 2012, 14:00
View user's profile Send private message Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 11 Jun 2012, 18:33
cod3b453 wrote:
As edfed said, you'll always need to use OS calls for an application. With this in mind, you'll probably want to define a set of generic OS calls and implement OS-specific wrappers for each OS you want it to run on; you can then put the core functionality into a common code group.

This makes things a little more complicated to start off with but should be easier for development and debugging.


so cod3b453...are you saying that starting out I should use already defined OS calls such as a console call or gui calls for testing while I develop my own generic calls to take their place...cause I was worried that using native api's or libraries(Windows in particular) that I would be infringing on copyrights....am I wrong in thinking this or have I misunderstood the question? I appreciate the input. Thanks!

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com
Post 11 Jun 2012, 18:33
View user's profile Send private message Visit poster's website Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 11 Jun 2012, 22:42
I think it might be easier to have a working version on an existing OS and then replacing the API calls such as file access, memory allocation or user interface with your own ones, once they are created.

FASM uses this approach for the different Windows/Linux/BSD builds. Another option is to use something like C library functions, which are the same for all OSs but you'd then have to implement these libraries in your OS. [I actually have a mixture of these in my own OS project so that I can develop under Windows or Linux IDEs and then test them on a VM].

Hope that helps Cool
Post 11 Jun 2012, 22:42
View user's profile Send private message Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 12 Jun 2012, 03:23
good deal..yea that seems it may make it somewhat easier especially in trying to gain knowledge and understanding of exactly what's going on with the code. Thanks!

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com
Post 12 Jun 2012, 03:23
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1898
DOS386 15 Jun 2012, 03:58
> So how can I program Assembly without
> relying on the libraries, and api's of other OS Platforms???

You can, but:

- You can't "simply" access hardware from Windows

- Win32 apps will run on Win64 (Win64 emulates Win32 for you)

- 32-bit code runs on 64-bit CPU (even 16-bit RM code "still" does ...) when CPU is in suitable mode

- Accessing "standard" IBM PC hardware is a horrrrrrrrrrrrrrrror

- To test your OS, you need to boot it into your PC or an emulator (BOCHS)

- You can provide a layer "isolating" your app from Windaube ... your app communicates with this layer only and "doesn't know" that Windaube exists ... you can test in Windaube and later you can keep your app and exchange only this layer to port your app into your OS ... FASM is done that way Smile (of course the risk is that no "later" will ever occur)
Post 15 Jun 2012, 03:58
View user's profile Send private message Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie 16 Jun 2012, 17:52
Well, I think it all begins with "Non-system disk or disk error..." Very Happy

People might suggest using the emulator... but then you'll end up using libraries from other OS, since emulator like the Bochs is a kind of OS in some way. Just a simple tune, Bochs can then become a full-blown OS.

My suggestion is for you to create your own virtual machine, and after reading what you 'want', I am pretty sure that you are actually referring to developing your own VM. Platform-independent, web applications, etc, etc... sounds like a VM to me Very Happy
Post 16 Jun 2012, 17:52
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1898
DOS386 17 Jun 2012, 06:58
> People might suggest using the emulator... but then you'll
> end up using libraries from other OS

no

> since emulator like the Bochs is a kind of OS in some way

no

> Just a simple tune, Bochs can then become a full-blown OS

no (I'll put BOCHS onto my CRAP LIST if it starts showing attempts to "be an OS")

> My suggestion is for you to create your own virtual machine

Code:
; Untested, at your own risk
    lea eax, [my_VM]
    vmbrew [eax]
    vmwrite ecx
@@: vmread ecx
    jnz @b
    
Post 17 Jun 2012, 06:58
View user's profile Send private message Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode 02 Jul 2012, 17:50
baremetal here,
http://www.returninfinity.com/baremetal.html
is a very promising 64bit OS written with nasm. one can start assembly just there. the code is clean and well organized.
newport wrote:
..what has helped you the most during your assembly quest thus far?

the following pdf


Description:
Download
Filename: assembly_grid_4x4x8bit.pdf
Filesize: 16.39 KB
Downloaded: 339 Time(s)


_________________
⠓⠕⠏⠉⠕⠙⠑
Post 02 Jul 2012, 17:50
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 05 Jul 2012, 21:49
hopcode wrote:

newport wrote:
..what has helped you the most during your assembly quest thus far?

the following pdf


Is that a joke? Try this one instead:

http://www.jegerlehner.ch/intel/IntelCodeTable.pdf
Post 05 Jul 2012, 21:49
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.