News:

Happy New Year! Yes, the current one, not a previous one; this is a new post, we swear!

Main Menu

Never even looked at x86 let alone OSDev before yesterday.

Started by Nate, July 11, 2006, 07:27:44 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Nate

[BITS 16]
[ORG 0x7c00]

main:
xor ax, ax ;Sets ax = 0
mov cs, ax ;All I know is that ds needs
mov ds, ax ;to be offset to 0x00 but Joe did 
mov es, ax ;them all so i followed his lead,
mov fs, ax ;bad idea i know.

mov si, Helloworld ;Moves the location of Helloworld to SI

Call putSTR

jmp $ ;big ass loop, how do i get to the next stage?

PutSTR:
mov ah, 0x0E ;Set TTY mode, no idea what 0x10 is in Joe's
mov bh, 0x00 ;sets page = 0
mov bl, 0x09 ;blue screen, white text iirc
.next ;label to get to next character
lodsb ;Pretty much mov al, si
int 0x10 ;Runs BIOS video interrupt
or al, al ;Determines if al = 0
jz .end ;GoTo label .end if al = 0
jmp .next ;GoTo .next
.end ;Label to bypass loop if end of STR
ret ;Return to main
;Data

Helloworld db 'Hello World', 13, 10, 0

times 510-($-$$) db 0
dw 0xAA55


May be some suggestions or you could completely rip it apart if im not even close that would also be helpful.

zorm

Depending on what you want to do, you could play around with write string (ah = 0x13 for int 10). I wrote this and I'm not sure if its included anywhere else but I'll paste it here just because.


putString:
mov bp, sp
inc [putStringRow]
mov dh, [putStringRow] ;row
mov dl, 0 ;column
mov al, 0 ;mode
mov bl, 0x0f ;display attribute
mov ah, 0x13 ;Write String
mov cx, [bp+4] ;String length
mov bp, [bp+2] ;String
int 0x10
retn

loadingString db 'Zorms OS Loading...', 13, 10
putStringRow db 0


and then its called like:


push 21 ;String length
push loadingString
call putString


I was just looking over what I have and I don't remember what I was doing in a lot of places. Also this snippet may prove useful:

emptySpace = 510 - ($ - $$)
times emptySpace db 0
dw 0xAA55


You could then output emptySpace to know how much space you have left to use.
"Frustra fit per plura quod potest fieri per pauciora"
- William of Ockham

Nate

Well everyone of his comments pretty much says he copied and pasted out of an AIM convo.  SO anyways is it right?  And what do i do next?  Ive just been kind of reading up on more x86 assembly and NASM.

Joe

mov cx, [bp+4] ;String length
mov bp, [bp+2] ;String

If the function is called as putString(word length, LPCSTR string), and you're pushing those elements to the stack, couldn't you use this code?

pop cx
pop bp
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


Warrior

I'd refrain from using the stack at all before PMode. Once you're in PMode you just make a descriptor to protect the stack and give it an address, not too hard. Realmode is something you don't want to linger in. Most of it's usefulness can be done in either vm86 mode or with PMode port reading/writing (Talking about detecting 386, 486 and detecting the presence of 'cpuid'). Realmode is there for legacy compatability, don't use it much.
One must ask oneself: "do I will trolling to become a universal law?" And then when one realizes "yes, I do will it to be such," one feels completely justified.
-- from Groundwork for the Metaphysics of Trolling

Joe

Come to think about it, what is a two-byte pointer to a CString called? PCSTR?
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


MyndFyre

Quote from: Joex86] link=topic=6615.msg81399#msg81399 date=1152964259]
Come to think about it, what is a two-byte pointer to a CString called? PCSTR?

???  We wouldn't use a two-byte pointer.....  we use four-byte pointers.  Even in real mode, addressing is done by segment:offset.  Anything you're coding in C/C++ won't use a segment:offset addressing mode, though.  Not nowadays.

If you're talking about a length-prefixed string, since C doesn't do them, I don't know why you'd make a data type alias for them. 
Quote from: Joe on January 23, 2011, 11:47:54 PM
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Quote from: Rule on May 26, 2009, 02:02:12 PMOur species really annoys me.

Joe

Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


MyndFyre

In a 16-bit processor, all of the pointers will be 16-bit.  Why would you have a special name for it?
Quote from: Joe on January 23, 2011, 11:47:54 PM
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Quote from: Rule on May 26, 2009, 02:02:12 PMOur species really annoys me.

Joe

Because LPCSTR is a long pointer, right? Or is sizeof(long) processor dependant?
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


MyndFyre

Quote from: Joex86] link=topic=6615.msg85268#msg85268 date=1154486722]
Because LPCSTR is a long pointer, right? Or is sizeof(long) processor dependant?

LP does mean "long pointer," but on a 64-bit architecture, LPCSTR refers to a 64-bit pointer.  Pointer sizes are processor-dependent and are always the size of the machine word.
Quote from: Joe on January 23, 2011, 11:47:54 PM
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Quote from: Rule on May 26, 2009, 02:02:12 PMOur species really annoys me.