flat assembler
Message board for the users of flat assembler.

Index > OS Construction > es:bx int 13h

Author
Thread Post new topic Reply to topic
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 24 Aug 2007, 02:47
mov ah,02h
mov al,1 ;number of sectors to read
mov ch,0 ;track
mov cl,0 ;sector
mov dh,0 ;head
mov dl,00h
int 13h

The function above is for reading a disk with bios.
The question I have is:

It loads the read contents into es:bx..
How would I load this into a string?
example string:

disk_data db 515 dup(' ')

I have tried a lot of different ways and have searched the net..
The onlything I can find is reading and executing the data.. I just want to read a disk and display the data read..

I know the data out will look like its been debuged.
but thats what I want- I want to be able to read the floppy and display exactly whats written on the disk the fat ect to the video screen..

Thanks in advance for any help..


Last edited by dosin on 24 Aug 2007, 03:09; edited 1 time in total
Post 24 Aug 2007, 02:47
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 24 Aug 2007, 03:07
Try
Code:
out_buffer:  times 512 db ' '                  dd 0    

You can mod this to suit your print function.
Post 24 Aug 2007, 03:07
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 24 Aug 2007, 03:45
Code:
out_buffer:
        times 512 db ' '
                  dd 0
    



Sorry but that don't help me...
I am new to asm...

And I am trying to move the data from es:bx to the data buffer


Code:
mov data, byte ptr es:bx    


or something like that..
Post 24 Aug 2007, 03:45
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 24 Aug 2007, 04:30
Here is a simple com file example
Code:
use16                            ; 16bit addressingorg 0x100                        ; Com file stuffstart:push cs                          ; Push CS on stackpop ds                           ; Move CS into DSpush ds                          ; Push DSpop es                           ; Move DS into ESmov [count],3mov bx,out_bufferTryAgain:mov ah,02hmov al,1 ;number of sectors to readmov ch,0 ;trackmov cl,1 ;sectormov dh,0 ;headmov dl,00hint 13hjnc PrintBuffer                   dec [count]cmp [count],0jne TryAgainFddError:mov si,fdd_err                   ; Point SI to stringcall print                       ; call our print functionjmp $                            ; Note: if run from dos change this for RETPrintBuffer:mov si,out_buffer                ; Point SI to stringcall print                       ; call our print functionjmp $                            ; Note: if run from dos change this for RET;====================================================;;  print.                                            ;;====================================================;print:mov ah,0Eh                       ; Request displayagain1:lodsb                            ; load a byte into AL from DS:SIor al,al                         ; Or ALjz done1                         ; Jump 0, to label done1int 10h                          ; Call interrupt servicejmp again1                       ; Jump to label again1done1:ret                              ; Return  count db 0  fdd_err db 'Error reading floppy',0            out_buffer:   times 512 db ' '                  dd 0    
You can run the above code from dos or use "bootprog" see here:
http://alexfru.chat.ru/epm.html#bootprog
Note the above code as not bean tested.
Post 24 Aug 2007, 04:30
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 774
Location: Adelaide
sinsi 24 Aug 2007, 05:24
Quote:
It loads the read contents into es:bx..

It loads the data (512 bytes) into a buffer pointed to by ES:BX - a buffer you need to allocate yourself

Quote:
And I am trying to move the data from es:bx to the data buffer

As above, you should already have a buffer...
Post 24 Aug 2007, 05:24
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 24 Aug 2007, 17:10
I have tried the example above but it crashes when I read the disk.


And just to make sure I understand the above example:

I need to point my diskdata db 512 ' ' to es:bx before calling int 13h?
and then print the string..




Thanks again for any help
Post 24 Aug 2007, 17:10
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 24 Aug 2007, 18:23
Well it run fine on my PC run in Dos (win98), the only change is to the print function because if not it only print about 10 byte as it must have a 0 in the boot sector.
Code:
use16                                 ; 16bit addressingorg 0x100                   ; Com file stuffstart:push cs                         ; Push CS on stackpop ds                              ; Move CS into DSpush ds                      ; Push DSpop es                               ; Move DS into ESmov [count],3mov bx,out_bufferTryAgain:mov ah,02hmov al,1 ;number of sectors to readmov ch,0 ;trackmov cl,1 ;sectormov dh,0 ;headmov dl,00hint 13hjnc PrintBuffer                   dec [count]cmp [count],0jne TryAgainFddError:mov si,fdd_err                    ; Point SI to stringcall print                        ; call our print functionret                          ; Note: if run from dos change this for RETPrintBuffer:mov si,out_buffer          ; Point SI to stringcall printF                       ; call our print functionret                          ; Note: if run from dos change this for RET;====================================================;;  print.                                            ;;====================================================;print:mov ah,0Eh                       ; Request displayagain1:lodsb                           ; load a byte into AL from DS:SIor al,al                  ; Or ALjz done1                       ; Jump 0, to label done1int 10h                       ; Call interrupt servicejmp again1                    ; Jump to label again1done1:ret                                 ; Return  ;====================================================;;  printF.                                           ;;====================================================;printF:mov cx,512mov ah,0Eh                       ; Request displayagain2:lodsb                           ; load a byte into AL from DS:SIint 10h                   ; Call interrupt serviceloop again2                   ; Jump to label again1ret                             ; Returncount db 0  fdd_err db 'Error reading floppy',0               out_buffer:      times 512 db ' '              dd 0    

Note: your code to read boot sector is wrong, it should be sector = 1.
How was you running it ?.


Last edited by Dex4u on 25 Aug 2007, 15:07; edited 1 time in total
Post 24 Aug 2007, 18:23
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 24 Aug 2007, 18:41
Thanks its working now!
Post 24 Aug 2007, 18:41
View user's profile Send private message Reply with quote
Hayden



Joined: 06 Oct 2005
Posts: 132
Hayden 26 Aug 2007, 19:29
here is a 16-bit boot sector i wrote a while ago, it shows you how to correctly load address into es:bx. ( sectors are read into the 'SystemSpace' variable ) hope it helps.
Code:
; ------------------------------------------------
; BOOT-OS.ASM Build(0620a)
; Created By: Hayden McKay
; ------------------------------------------------
use16

jmp far 007C0h:init_bootsys           ; must be far
align 4

    SystemStack  dd 08000h:0fbffh    ;  1k
    SystemSpace  dd 09000h:00000h    ; 64k

    SectorStart  dw 1                   ; lba
    SectorCount  db 128        ; maximum 64k

align 4

init_bootsys:

    ; setup stack ect...

    lss  sp, dword [cs:SystemStack]       ; nmi safe
    pushf
    pusha
    push dx                             ; boot num
    push sp

    ; setup for lba->chs translation...

    mov  ah,08h                  ; drive params
    int  13h
    xor  ah, ah
    mov  al, dh                    ; maximum head
    and  cx,3fh               ; clear d6->d7
    inc  ax
    mul  cx
    mov  si, cx              ; sector count
    mov  di, ax               ; heads x secs

    ; begin the lba->chs, mutli-sector read...

    pop  bp                      ; ptr boot num
    les  bx, dword [cs:SystemSpace]
    align 4

read_sectors:

    mov  ax, word  [cs:SectorStart]
    xor  dx, dx
    div  di
    mov  cl, ah
    mov  ch, al             ; cylinder d0->d7
    shl  cl, 6d                 ; cylinder d8->d9
    mov  ax, dx
    xor  dx, dx
    div  si
    inc  dl
    mov  dh, al             ; head
    or        cl, dl                  ; sector d0->d5
    mov  dl, byte  [ss:bp]

    ; read how many sectors...

    mov  al, cl
    and  ax,3fh
    sub  ax, si                    ; - max sec...
    neg  ax                           ; abs
    inc  al                            ; +=1
    cmp  al, byte  [cs:SectorCount] ; more than...
    jbe  @f
    mov  al, byte  [cs:SectorCount] ; less than...
    align 4
    @@:

    ; use the bios int13 i/o...

    pusha                             ; bios safe
    xor  ax, ax                  ; calibrate
    int  13h
    popa
    pusha
    mov  ah,02h                 ; read secs
    stc                          ; bios safe
    int  13h
    popa
    jc         @b                            ; use force

    ; prepare for some more sectors...

    add  word  [cs:SectorStart], ax ; update start
    sub  byte  [cs:SectorCount], al ; update count
    jz       @f                         ; done!
    shl  ax, 9d              ; *=512
    add  bx, ax              ; update es:bx
    jmp  near  read_sectors
    align 4
    @@:
    pop  dx                          ; boot num

    ; initiate the system file...

    popa
    popf
    lds  bx, dword [cs:SystemSpace]   ; setup data
    call far dword [cs:SystemSpace]   ; enter code

    ; 157 bytes

    ; Todo list...

    ; * maybee copy the system to the hma
    ; * maybee supply an open file system

    rb 510d - $
    db 055h
    db 0AAh                              ; bootme!
    

_________________
New User.. Hayden McKay.
Post 26 Aug 2007, 19:29
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-2023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.