Author Topic: writing a sector from buffer to a bin file  (Read 7694 times)

Offline flyhigh427

  • Jr. Member
  • *
  • Posts: 60
writing a sector from buffer to a bin file
« on: July 23, 2011, 08:10:19 PM »
hey
im getting an error unable to open file.
and do i have to load into the buffer or just load straight into the file ?
thanks

Code: [Select]


TARGETDRIVE     equ       0             ; hard drive (0, 1, ...)


org 100h                               
Start:
        mov     dx,80h + TARGETDRIVE    ; read MBR of target drive
        mov     cx,1h                   ; it's always the first sector
        mov     bx, buffer       ; point to our buffer
        mov     ax, 0201h               ; read one sector
        int     13h
        mov     cx,4h                   ; read up to four entries
        mov     si, buffer + 1BEh; scan our partition table
        mov     si,begin
        mov ax, 4C00h                   ; Exit to DOS.
        int 21h

buffer db 0                            ;Dynamic buffer, 512 bytes.






Begin: INCBIN "holdsec.bin"

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: writing a sector from buffer to a bin file
« Reply #1 on: July 23, 2011, 08:27:39 PM »
I'm not sure I understand the problem. "Begin" != "begin", but I don't think that's what you're talking about(?). You seem to be "incbin"ing a file, and then overwriting it. I don't "get" it.

Best,
Frank


Offline flyhigh427

  • Jr. Member
  • *
  • Posts: 60
Re: writing a sector from buffer to a bin file
« Reply #2 on: July 23, 2011, 08:44:35 PM »
hey frank
i had caps on and fixed that.
im tryng to make a copy of my mbr

Offline Serge

  • Jr. Member
  • *
  • Posts: 26
  • Country: ru
Re: writing a sector from buffer to a bin file
« Reply #3 on: July 23, 2011, 08:47:47 PM »
Hmmm...
flyhigh427, are you trying to write data to file "holdsec.bin"?
If yes, you are mistaken. INCBIN just places the content of file to the code at compilation time, not at execution.

Offline flyhigh427

  • Jr. Member
  • *
  • Posts: 60
Re: writing a sector from buffer to a bin file
« Reply #4 on: July 23, 2011, 08:50:02 PM »
thanks

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: writing a sector from buffer to a bin file
« Reply #5 on: July 23, 2011, 09:22:20 PM »
Right. Now I understand the question (Thanks, Serge!). Yeah, you'll have to read your MBR into a buffer (512 bytes +, please!), then open/create the file, and write the buffer to it. (or... you could write the buffer to stdout and redirect it - watch out for "helpful" dos routines that convert tabs to spaces, etc. - int 21h/40h should work)

Best,
Frank