## Nicholas_Roge

[ ] I've got a working bootloader. Now I need to learn how to pass control from that bootloader to... Well, I'm really not sure how to do that.

[ ] Once I have passed control out of the bootloader. How do I access the graphics driver?

[ ] How is

``LEA AX,var1``

any different from

``MOV AX, OFFSET var1``

?

[ ] Why would you XOR something by itself in order to zero it out rather than just moving 0000h into it? It is just more efficient?

More questions to come... (probably)

## gerard4143 371

I have a few questions...Is this a boot loader you wrote or one you downloaded.

Why would you XOR something by itself in order to zero it out rather than just moving 0000h into it? It is just more efficient?

Its more efficient.

## coffeeuncle

xor ax,ax is better than mov ax,0
its not faster but take less code
as you know, in your bootloader you do not have much space for code
xor ax,ax has occupies one byte and mov ax,0 occupies 3 bytes

WHERE do you want pass control to ?
in fact the job of the bootloader is to load another program

if you want to loose control of your bootloader why do you want control to graphic controller ?

mov ax, offset var1 AND lea ax,var1 is the same (see your question regarding xor and mov)
lea is often used for complex addressing like

``````lea,[bx+10]
lea,[bx+SI+10]
lea,[bx+SI*2]``````

it can combine several register, adding and multiplying in one instruction
lea,[ax+ax*4] is like multiplying ax with 5

the advantage is that you can access several variables without moving register content, mostly with stack

``````lea ax,[bp-10]
lea bx,[bp-8]
lea cx,[bp-6]``````

you have to write

``````mov bp,xx
sub bp,10
mov ax,[bp]
mov bx,[bp]
mov cx,[bp]``````

some people use lea simple for a calculator - easy and efficient

## Nicholas_Roge

WHERE do you want pass control to ?
in fact the job of the bootloader is to load another program.

I guess that's my question. Where DO I pass control of the bootloader to. And how do I actually do that? (that's what I was confused about.)

if you want to loose control of your bootloader why do you want control to graphic controller ?

That is for reference so that after I get out of the bootloader and into the main program itself I'll be able to access it.

the advantage is that you can access several variables without moving register content, mostly with stack.

Okay, I understand what you're saying. (I'm about to go off on a little bit of a tangent here...) But isn't the purpose of the stack to BE a FILO structure. So why would you need to access the stack out of order?

## coffeeuncle

to your last question, yes the stack is in a FILO structure (first in - last out) but can be used in other ways. stack is often used to pass variables to a function (instead of filling registers).

So you can use:
push var1
push var2
push var3
call function

and then in function you have first on top of stack the return address of calling function. you have to pop return address, store it somewhere and before ret you have to put in on stack again. and where do you put your variables ? in what registers and what to do if all regs are in use ? copy data again in some memory area ?

the easiest way to reference var1, var2, var3 etc is with sp (stackpointer) and use with bp (basepointer) like
mov ax,[sp-bp]
or
mov si,[sp-bp-6]

this is a common way of using stack for data referenced in two functions (main function and called function).

## Nicholas_Roge

to your last question, yes the stack is in a FILO structure (first in - last out) but can be used in other ways. stack is often used to pass variables to a function (instead of filling registers).

So you can use:
push var1
push var2
push var3
call function

and then in function you have first on top of stack the return address of calling function. you have to pop return address, store it somewhere and before ret you have to put in on stack again. and where do you put your variables ? in what registers and what to do if all regs are in use ? copy data again in some memory area ?

the easiest way to reference var1, var2, var3 etc is with sp (stackpointer) and use with bp (basepointer) like
mov ax,[sp-bp]
or
mov si,[sp-bp-6]

this is a common way of using stack for data referenced in two functions (main function and called function).

Okay, that makes sense. Do you just POP the stack into a register upon exiting the call?

My questions is how do I load a program from the bootloader. That's what I don't understand.

And when you say to hook a suitable interrupt vector, how do I found out which interrupt I should use? Every graphics card and chipset is going to have it's own set of interrupts, right?

## NotNull 23

Just to note newbie
the addressing mode [sp], is extant.
In 16-bit assembly language bp is provided to be used
in indirect addressing mode.
[sp-bp]
does not exist.
If you are writing a bootstrap routine and you wonder
where to pass control, that is either to another
Operating Systems bootstrap routine, or your own, if
you are developing an OS.
If to a preexisting operating system your bootstrap
routine must load its boot sector from the drive or
some other permanent media, so you must know
its file system and be able to interpret its structures.
In other words, the system must have an OS installed
in it already before there is anything to pass control
to. If you are merely chaining to its bootstrap routine
you merely need to locate the partition (on most systems)
and load its first sector and pass control to it if I'm right.

If parameters are placed on the stack for a subroutine
call the stack grows from higher to lower addresses
so a positive + displacement would be used,
for example: (unlike what coffeeuncle said)

``````push var1
push var2
call sub
...
sub:
mov bp, sp
mov ax, [bp+2] ; would access var2
mov ax, [bp+4] ; would access var1``````

Good day.

^\_||
\_Xa|
XX|||