flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Bootloader use16 edx problem

Author
Thread Post new topic Reply to topic
Enko



Joined: 03 Apr 2007
Posts: 676
Location: Mar del Plata
Enko 23 May 2007, 19:34
Hello to everyone, I stared to try to write a BootLoader.
Actually its just a HelloWorld that works, but I think it shouldn´t.
I dont understand why fasm dosn't accept this in use16 mod:
Code:
   mov  al, [dx]
    

It says, that reserved word is used as symbol. The same thing happened with [ax], [cx], [es]... but not with [bx] :S

I just used edx and it worked, tryed it in Virual PC.
Code:
use16
org 0
  jmp     0x07C0:start
start:
      mov     ax, cs
      mov     ds, ax
      mov     es, ax
      
    xor             dx, dx
start_print:
  
    mov             ah, 0Ah
     ;Why it must be msg + edx? and not msg + dx
 mov             al, [msg +edx]
      cmp             al, '$'
   je              end_print
   inc             dx
  mov             bl, 12
      mov             cx, 1
       int             10h     
    xor             bx, bx
      
    mov             ah, 2
       xor             bx, bx
      int             10h
 jmp             start_print
end_print:
       xor             ax, ax
      int             16h                   
forever:
      jmp     forever
     msg     db ' HOLA MUNDO $',0
      
    db      510 - $  dup 0
      dw  0xAA55
    

What kind of problem could happen if a use extended registers in use16 mode?[/code]
Post 23 May 2007, 19:34
View user's profile Send private message Reply with quote
Hayden



Joined: 06 Oct 2005
Posts: 132
Hayden 24 May 2007, 03:34
you should have used
Code:
mov al, byte [dx]       
    


dx specifies the offset, and byte specifies to move a byte

further more, you should also specify the segment
Code:
mov al, byte [ds:dx]   ; moves a byte from ds:dx into al
    


the 32bit version would be
Code:
mov al, byte [ds:edx]
    

_________________
New User.. Hayden McKay.
Post 24 May 2007, 03:34
View user's profile Send private message Reply with quote
Enko



Joined: 03 Apr 2007
Posts: 676
Location: Mar del Plata
Enko 24 May 2007, 19:54
Thanks a lot
Quote:

mov al, byte [dx]

I think I tried it but can't remember now very well.
Quote:

mov al, byte [ds:dx]

This thing was making me a lot of problems.
Great!!!
Post 24 May 2007, 19:54
View user's profile Send private message Reply with quote
mikegonta



Joined: 20 Nov 2005
Posts: 99
mikegonta 24 May 2007, 21:12
[ Post removed by author. ]


Last edited by mikegonta on 27 Jan 2009, 21:57; edited 2 times in total
Post 24 May 2007, 21:12
View user's profile Send private message Reply with quote
Goplat



Joined: 15 Sep 2006
Posts: 181
Goplat 25 May 2007, 00:13
Hayden wrote:
you should have used
Code:
mov al, byte [dx]       
    


dx specifies the offset, and byte specifies to move a byte

It doesn't make any difference - fasm already knows the memory operand is a byte, because the destination is the byte-sized register AL.

Quote:
further more, you should also specify the segment
Code:
mov al, byte [ds:dx]   ; moves a byte from ds:dx into al
    

Again, doesn't make any difference - the DS: segment is the default for memory accesses, unless you're using BP/EBP/ESP as the base register.

Anyway, it's dangerous to be using 32-bit addressing like "mov al,[edx]" if you don't know what's in the high word of EDX. If it isn't zero, then the address will exceed the segment limit (always 0FFFFh in real mode) and cause a general protection fault. You could of course just change the "xor dx,dx" to "xor edx,edx", but in a boot sector you want to keep things small so it's better to just avoid 32-bit stuff. I would suggest using the SI register to point to the message, that way you can use the LODSB instruction and save a couple more bytes.
Post 25 May 2007, 00:13
View user's profile Send private message Reply with quote
mikegonta



Joined: 20 Nov 2005
Posts: 99
mikegonta 25 May 2007, 01:22
[ Post removed by author. ]


Last edited by mikegonta on 27 Jan 2009, 21:57; edited 1 time in total
Post 25 May 2007, 01:22
View user's profile Send private message Reply with quote
Goplat



Joined: 15 Sep 2006
Posts: 181
Goplat 25 May 2007, 15:24
By entering protected mode you lose the ability to call the BIOS, so how would you load the operating system? 512 bytes is rather small for putting disk drivers in.
Post 25 May 2007, 15:24
View user's profile Send private message Reply with quote
Adam Kachwalla



Joined: 01 Apr 2006
Posts: 150
Adam Kachwalla 26 May 2007, 11:06
Enko wrote:

Hello to everyone, I stared to try to write a BootLoader.
Actually its just a HelloWorld that works, but I think it shouldn´t.
I dont understand why fasm dosn't accept this in use16 mod:

Code:
mov  al, [dx]    



It says, that reserved word is used as symbol. The same thing happened with [ax], [cx], [es]... but not with [bx] :S


AX, BX, CX, and DX have special meanings (ignore the fact that they seem to be derived from consecutive letters of the alphabet):

[b]BX = Base Register. This is used to store addresses (which is why only MOV AL, [BX] works - BX is used as a base address register and is designed for that purpose).

Enko wrote:
I just used edx and it worked, tryed it in Virual PC.

Code:
use16
org 0
        jmp     0x07C0:start
start:
        mov     ax, cs
        mov     ds, ax
        mov     es, ax
        
        xor             dx, dx
start_print:
        
        mov             ah, 0Ah
        ;Why it must be msg + edx? and not msg + dx
        mov             al, [msg +edx]
        cmp             al, '$'
        je              end_print
        inc             dx
        mov             bl, 12
        mov             cx, 1
        int             10h     
        xor             bx, bx
        
        mov             ah, 2
        xor             bx, bx
        int             10h
        jmp             start_print
end_print:
        xor             ax, ax
        int             16h                   
forever:
        jmp     forever
        msg     db ' HOLA MUNDO $',0
        
        db      510 - $  dup 0
        dw  0xAA55    




What kind of problem could happen if a use extended registers in use16 mode?


You will find that under a 286 or earlier processor, the system will do unpredictable things as the extended registers are only used in the 386 or greater. FASM doesn't know that EAX, EBX, ECX, and EDX cannot be used under 16-bit processors as they do not exist.
Post 26 May 2007, 11:06
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.