Page 1 of 1

a few questions

Posted: Sat Jun 21, 2003 12:21 am
by suhmaamiar
hi

a few questions i would like to ask....

1. why there is a limit of 512 bytes when writting
a boot loader ?

2. what exactly [org 0] do ?

3. when using partcopy with 0 200 -f0 parameters.
, what does they mean, (i.e. 0 200 -f0 )?

many thanks

suhmaamiar

Re:a few questions

Posted: Sat Jun 21, 2003 12:38 am
by Perica
..

Re:a few questions

Posted: Sat Jun 21, 2003 2:07 am
by Pype.Clicker
2. it makes the assembler assume that the very first byte it assembles has offset 0. It can be used to prepare code or data that will be loaded at a fixed position without having to waste preciousss disk space with zeroes ...

[org 0] is not much useful, [org 7C00h] is much more :)

Re:a few questions

Posted: Sat Jun 21, 2003 5:25 am
by suhmaamiar
thanks for your reply :)

do you think that using

[org 7c00h]

is equal to using

[org o]
jmp 7c00h:label1

and pls tell me how can i define an empty string
in nasm ?

thanks you

suhmaamiar

Re:a few questions

Posted: Sat Jun 21, 2003 6:16 am
by Pype.Clicker
do you think
[org 7c00h]
is equal to using
[org o]
jmp 7c00h:label1
no. it's not the same. In the first approach, you tell the assembler the code will be starting at offset 7C00 (which means you assume the segment CS will be 0x0000)

the second code makes no sense ... what would you do in 0x7C000+label ?
if what you mean is

Code: Select all

[org 0]
jmp 0x7C0:label1

label1:
what you're doing is actually *forcing* the execution with CS=0x7C0.

The difference between the two is the value of CS (note that the first code will likely fail if CS wasn't 0 as expected but rather 0x7C0 -- so it should have a jmp 0x0000:label1 aswel). Which one you should use is a matter of taste, but 0x0000:0x7C00 seems to be easier to use when you have to set up protected mode.

Re:a few questions

Posted: Sat Jun 21, 2003 6:36 pm
by suhmaamiar
this is the exact code which i wanted to understand
i dont have any nasm book with me so i am not
sure about the code wrriten in nasm style

the code is from a bootstrap tutorial

[org 0]

jmp 07c0h:label

label:
mov ax,cs
mov ds,ax
mov es,ax

...
..
...

and pls tell me how to define an empty string
in nasm.

thank you :)

Re:a few questions

Posted: Sun Jun 22, 2003 5:27 am
by Pype.Clicker
as there's no "string" in nasm, i can hardly tell you how to make an empty one. More precisely, you can implement strings in a number of ways in assembler:
  • have 2 words, one being the string pointer and the other one counting the string size. in that case, an empty string is just a string which size is 0, regardless of the actual pointer.

    Code: Select all

    hello_data: db 'hello'
    world_data: db 'world'
    hello_str dw 5,hello_data
    world_str dw 5,world_data
    helloworld_str dw 10,hello_data
    null str dw 0,0
    
  • use C-like strings, which means the size is unknown a priori, but the null character is the end of the string. In that case, the empty string is made of one 0 byte

    Code: Select all

    hello_str db 'hello',0
    helloworld_str db 'hello'
    world_str db 'world',0
    null_str db 0
    
  • if the API says so, the termination character might not be a 0. For instance, ms-dos "print string" function (int 0x21, ah=9) requires the string to be '$' - terminated (don't ask me why, i guess those guys felt the urge to see $ everywhere in their source code)

    Code: Select all

    hello_str db 'hello$'
    null_str db '$'