flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > Help to start my own OS Goto page Previous 1, 2, 3, 4, 5, 6, 7 Next |
Author |
|
edfed 30 May 2010, 13:21
you sould put your kernel where you want.
free segments are: 1000h to 9000h org the kernel at 100h if you want to test it under dos assuming the entry point in kernel is in real mode, and then, switch to pm in the kernel. the segment for the kernel can be 1000h for example. boot = 0:7c00h kernel = 1000h:0 or kernel = 1000h:100h |
|||
30 May 2010, 13:21 |
|
Teehee 30 May 2010, 13:31
the org directive organize only the offset, not the segment, right?
but where in the code (bytes) it says to organize in some address? can i do not use the org? |
|||
30 May 2010, 13:31 |
|
edfed 30 May 2010, 13:48
you can code wihout org, in this case, it is equivalent to org 0
in fact org only refer to offsets for datas and labels. Code: org 230 mov ax,$ ;ax = $ = 230 org 100h mov ax,$ ; ax= $ = 256 org 0 mov ax,$ ; ax=$ = 0 then, you canuse several org inside the same source, because it will only change the base adress value. the binary itself will always start at offset 0, but operations on labels inside will assume the code start at a specified location. |
|||
30 May 2010, 13:48 |
|
ass0 30 May 2010, 14:24
It would be simpler and more logic:
Code: $: 230 mov ax,$ ;ax = $ = 230 $: 100h mov ax,$ ; ax= $ = 256 $: 0 mov ax,$ ; ax=$ = 0 =D _________________ Nombre: Aquiles Castro. Location2: about:robots |
|||
30 May 2010, 14:24 |
|
baldr 30 May 2010, 15:26
edfed,
Intel SDM vol. 2-A rev. 033 p. 3-595 wrote: The source operand specifies a 6-byte memory location that contains the base address (a linear address) and the limit (size of table in bytes) of the global descriptor table (GDT)… Teehee here wrote: 3. The worse step: EDIT: Dumb error with lgdt mnemonic. Last edited by baldr on 30 May 2010, 18:30; edited 2 times in total |
|||
30 May 2010, 15:26 |
|
ManOfSteel 30 May 2010, 15:26
Teehee wrote: but where in the code (bytes) it says to organize in some address? You specify the memory address when reading the sectors from the disk using BIOS interrupt 0x13. I may be misunderstanding your question though. |
|||
30 May 2010, 15:26 |
|
Teehee 30 May 2010, 16:35
ManOfSteel wrote: I may be misunderstanding your question though. yep but edfed answered: edfed wrote: you canuse several org inside the same source, because it will only change the base adress value. I was thinking that there is some byte to say "hey CPU, from here you organize at address XXXX". But it just put the data (and not code or stack(?)) at specified org position. If i understood. |
|||
30 May 2010, 16:35 |
|
edfed 30 May 2010, 16:43
org position is not adress.
when you say org xxxx, you just say to compiler a virtual base adress, something added to all label references. that's why it is a directive. |
|||
30 May 2010, 16:43 |
|
baldr 30 May 2010, 18:29
Teehee,
Have you read 2.2.4 Addressing spaces subchapter of manual? First paragraph describes it all. |
|||
30 May 2010, 18:29 |
|
Teehee 30 May 2010, 19:47
Quote: when you say org xxxx, you just say to compiler a virtual base adress, something added to all label references. I dont know if i undertood. Maybe i'm just cant figure out how it work. I made this test, but still i can't see why. i compiled this code and tried to see it in debug: Code: org 100h nop one: jmp two nop db 'one',0 ;org 200h nop two: jmp one nop db 'two',0 See img below. The first entry is with org 200h line commented; the second one it was uncommented.
_________________ Sorry if bad english. |
||||||||||
30 May 2010, 19:47 |
|
baldr 30 May 2010, 20:10
Teehee,
Nothing unusual. FASM manual wrote: org directive sets address at which the following code is expected to appear in memory. It should be followed by numerical expression specifying the address. This directive begins the new addressing space, the following code itself is not moved in any way, but all the labels defined within it and the value of $ symbol are affected as if it was put at the given address. However it's the responsibility of programmer to put the code at correct address at run-time. Code: org 100h ; $ file nop ; 100 00 one: jmp two ; 101 01; two==0x201, jmp near nop ; 104 04 db 'one',0 ; 105 05 org 200h nop ; 200 09 two: jmp one ; 201 0A nop ; 204 0D db 'two',0 ; 205 0E ; 209 12 Your code is placed at 100h by OS loader (as usual for .Com executables) as a whole. So if you want to place code below org 200h at offset 200h, you must copy it yourself. |
|||
30 May 2010, 20:10 |
|
Teehee 30 May 2010, 20:45
baldr wrote: Think of first jump as jmp 201h. I can think that, but the code is not really there (is it?). At least debug says no. Quote: So if you want to place code below org 200h at offset 200h, you must copy it yourself. _________________ Sorry if bad english. |
|||
30 May 2010, 20:45 |
|
cod3b453 30 May 2010, 21:12
Something like this:
Code: mov si,old_code_location mov di,new_code_location mov cx,length_of_code cld repnz movsb |
|||
30 May 2010, 21:12 |
|
baldr 30 May 2010, 21:21
Teehee,
cod3b453's right. There is a catch: Code: db 'one',0 ; 105 05 ; label for source address should be placed here ; because it should refer to address where the code is located now old_code_location: org 200h ; label for destination address should be placed here ; because it should be at 200h new_code_location: nop ; 200 09 two: jmp one ; 201 0A nop ; 204 0D db 'two',0 ; 205 0E ; 209 12 length_of_code = $-new_code_location |
|||
30 May 2010, 21:21 |
|
edfed 31 May 2010, 10:22
org is like that:
date 2june2056 start list,activities 1 more day: picnic mountain,family 1 more day: barbecue village,friends 1 more day: beach marseille,girls 1 more day: party monaco,money if you make the analogy between org and date, you will find that each instruction is located one day after preceding one. then, for the party, refering to date 2 june 2048, you can say it will be the 6 june 2048. if you change the origin date, each labels offset will not change, but reference will. for example: date 32may3298 here, the party date will be the 32+4= 36 may3298. it is the same for org. org 100h .0: db 0 .1: db 1 .2: db 2 .3: db 3 .4: db 4 then, each label inside this code is located at org+offset i don't understand why you don't understand that.... |
|||
31 May 2010, 10:22 |
|
Teehee 31 May 2010, 16:03
edfed wrote: i don't understand why you don't understand that.... hehe, i understood that. What i dont understand is why in debug it showns datas at same code place, if we org it in another place. e.g: Code: org 100h nop db 'aaa',0 org 200h nop db 'bbb',0 shows: Code: 0D346:0100 : 90 61 61 61 00 90 62 62 62 00 .aaa..bbb. This is how I imagine how it should be: Code: 0D346:0100 : 90 61 61 61 00 .aaa. (...) 0D346:0200 : 90 62 62 62 00 .bbb. But, INDEED, if i put some label at second org, it will shows 200h+ address. But the data is not really there. is it copied to there? hehe I don't know whats happening to me _________________ Sorry if bad english. |
|||
31 May 2010, 16:03 |
|
ManOfSteel 31 May 2010, 17:03
Teehee wrote: What i dont understand is why in debug it showns datas at same code place, if we org it in another place. That's because you don't have any memory offset there, only meaningless data. The only way to do what you want in this case is to use times xyz db 0. You really should read the fabulous manual: Quote: org directive sets address at which the following code is expected to appear in memory. It should be followed by numerical expression specifying the address. This directive begins the new addressing space, the following code itself is not moved in any way, but all the labels defined within it and the value of $ symbol are affected as if it was put at the given address. However it's the responsibility of programmer to put the code at correct address at run–time. |
|||
31 May 2010, 17:03 |
|
Teehee 31 May 2010, 18:16
yep, ManOfSteel, i've read.
Manual wrote: but all the labels defined within it and the value of $ symbol are affected as if it was put at the given address "as if"... ok, they are not there. But then why do we use the org directive? what its utility? I can't see. Take it easy guys. We are coming there! |
|||
31 May 2010, 18:16 |
|
ManOfSteel 31 May 2010, 19:56
It serves to adapt the addresses used inside your code.
For example, a .com executable is expected to run at 0x100 because MS-DOS copies the contents of the executable at memory address 0x100. If you omit the org 0x100 at the beginning of the following example, where do you think the second operands of the 2 mov instructions will point? 0x106 and 0x10b where they're expected to be, or 0x6 and 0xb (right in the IVT)? Code: org 0x100 mov si,str1 mov di,str2 str1 db 'test1' str2 db 'test2' |
|||
31 May 2010, 19:56 |
|
Goto page Previous 1, 2, 3, 4, 5, 6, 7 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.