Author Topic: independent Assembly  (Read 8847 times)

nobody

  • Guest
independent Assembly
« on: December 04, 2008, 10:10:17 AM »
I'm new to assembly programming, and slowly figuring things out.  I was wondering if it was possible to create independent Assembly.  Where it doesn't depend on dos, win32, or linux?  or any operating system at all, but still be ran from dos, win32, or linux?

nobody

  • Guest
Re: independent Assembly
« Reply #1 on: December 04, 2008, 03:47:16 PM »
Yes and no. Any code the CPU executes is machine language, and could be written/expressed as assembly language. Right from power-up, before any OS is loaded, so that's about as "independent" as you can get, I guess.

Once an OS has control, not so much... We can "add eax, ebx", or crunch numbers all day long, or scan memory looking for zeros or other bytes (strlen, etc.). But if we want to display the results - or do *any* I/O at all - we're going to be dependent on the OS. We depend on the OS to load our progam and set it running, and unless we want to just "hang" at the end, we need an "exit to OS" function.

Windows and Linux are "protected" OSen. They're "protected" from *us*, I'm afraid. Real dos will give us unrestricted access to the hardware, so we can be a little more "independent". Here's a dos .com file with no dos interrupts showing:

;---------------------------------
; nasm -f bin -o hwnoint.com hwnoint.asm

org 100h

push word 0B800h    ; segment of video memory
    pop es              ; (because stosw uses es:di)
    mov di, (10 * 80 + 30) * 2  ; offset into screen
        ; (row * width + column) * 2 bytes/character
    mov si, msg         ; offset of our string
    mov ah, 0B0h        ; color (blinking black on cyan)
top:
    lodsb               ; get byte from [ds:si] into al
                        ; and increment si for next one
    or al, al           ; this doesn't change al, but sets
    jz depart           ; the flags - if zero, we're done
    stosw               ; stores ax (char & color) to [es:si]
                        ; and add 2 to di for next one
    jmp short top       ; do more
depart:
    ret                 ; return to dos (or other caller)

msg db " Look, Ma! No ints! ",0  ; note 0, not '$', terminated
                                 ; '$' is just for int 21h/9
;------------------------------------

(Gawd, that's gonna wrap unreadably!) There's actually an int 20h hidden behind the "ret", so this isn't as "independent" as it looks.

You can do a lot of "stuff" independent of the OS, but if you've got one, I think it's fair to say that a "complete program" is going to have to interact with it sooner or later. If you *don't* have an OS, "independent" is the only choice, of course. It may feel more like "out here in the wilderness, all alone". :)

Best,
Frank

nobody

  • Guest
Re: independent Assembly
« Reply #2 on: December 05, 2008, 12:32:27 AM »
Thanks for the explanation.  I think I understand.  Eventually, I would like to create my own bootloader and kernel all from assembly language.  I KNOW this will be a lot of work.  Are there any references that show dos commands and independent non-OS commands, and explanations of these commands?  I am sure there are some out there, and I will be searching google.

nobody

  • Guest
Re: independent Assembly
« Reply #3 on: December 05, 2008, 12:45:35 PM »
I was doing some more searching and found this: http://www.cs.cmu.edu/~ralf/files.html

I haven't looked at the interrupt lists yet, but the site seems it might be some of what I was looking for.