-2

I have this assignment to make booting program that shows the partitions disk on MY PC .. I searched a lot and figured out that the section that holed those info in 1BE so I am trying to read from that sector ..I found some codes and tried to study interrupt 13 this code and I don't know I feel there is something wrong

then when I run it with NASM it showed an error unrecognized directive ORG

thanks a lot :) :) :)

[BITS 16]                            ; 16 bit code generation
[ORG 0x7C00]                          ; Origin location

; Main program
main:                         ; Label for the start of the main program


start: 
       mov ax,cs
       mov ds,ax
       mov es,ax
       mov ss,ax
       sti

reset: mov ah,0h                  ;resetting the drive to the first sector
       mov dl, 0x80
       int 13h
       js reset

read:  mov ax,1BEh              ;reading sectors into memory address 0x1BE:0
       mov es,ax
       xor bx,bx
       mov ah,02h
       mov al,01h               ;reading 1 sector
       mov  cx, 0001h           ; track 0, sector 1
       mov  dx, 0000h           ; head 0, drive 0
       int 13h

      jc   errp                ; detect error
      ret




          jmp $            ; Never ending loop

; Procedures
errp:                          ; process error here
 mov ax,0x0000          
 mov ds,ax  
 mov si, ERRR                 ; Load the string into position for the procedure.
 call PutStr



PutStr:     ; Procedure label/start
                ; Set up the registers for the interrupt call
 mov ah,0x0E    ; The function to display a chacter (teletype)
 mov bh,0x00    ; Page number
 mov bl,0x07    ; Normal text attribute

.nextchar   
 lodsb  

 or al,al           
 jz .return         
 int 0x10   ; Run the BIOS video interrupt 

 jmp .nextchar  ; Loop back round tothe top
.return     ; Label at the end to jump to when complete
 ret        ; Return to main program

; Data

ERRR db 'ERROOOORR',13,10,0

; End Matter
times 510-($-$$) db 0   
dw 0xAA55       
rkhb
  • 14,159
  • 7
  • 32
  • 60
Sarah
  • 59
  • 1
  • 1
  • 5
  • Is 'MY PC' some sort of simulated computer system? – Craig S. Anderson Nov 09 '14 at 10:20
  • Looking at the nasm manual it looks like the ORG directive should not have the '[' and ']'. – Craig S. Anderson Nov 09 '14 at 10:47
  • Looks like you didn't assemble with `-f bin` (another modus is wrong!). – rkhb Nov 09 '14 at 11:05
  • @CraigAnderson: The primitive form with brackets is not wrong. [From the manual](http://www.nasm.us/doc/nasmdoc6.html): "NASM's directives come in two types: user-level directives and primitive directives. Typically, each directive has a user-level form and a primitive form. In almost all cases, we recommend that users use the user-level forms of the directives, which are implemented as macros which call the primitive forms. Primitive directives are enclosed in square brackets; user-level directives are not." – rkhb Nov 09 '14 at 11:11
  • @rkhb I was looking at this (http://www.nasm.us/doc/nasmdoc7.html#section-7.1.1). Is that section misleading? – Craig S. Anderson Nov 09 '14 at 11:16
  • @CraigAnderson: Very probably. I tried `[ORG 0x7C00]` with NASM 2.11.05 and got no error or warning. – rkhb Nov 09 '14 at 11:20
  • Also, that 1BEh is the offset of the partition table, not a segment. It should already be in memory. – Frank Kotler Nov 09 '14 at 14:06
  • Note that the partition table in the partition sector points to a list of possible boot sectors (only one should be "active") that may reside in a primary or an extended partition. If in a primary partition, it's a boot sector. If it's the first sector of an extended partition, it's similar to yet another partition sector. It's also possible that a custom partition utility has been used, in which case the partition table may start at a different offset. The normal sequence is to load at 0:7c00, relocate to 0:0600, then load again at 0:7c00, repeating as needed until the actual boot occurs. – rcgldr Nov 10 '14 at 04:11

1 Answers1

0

The fact that you use ORG 0x7C00 implies that you set the segment registers to zero and not to the value already in CS.
The BIOS function to reset the drive does not return anything in the sign flag SF. It does however change the carry flag CF.
The partition table is located at offset 0x01BE of the bootsector and contains 4 16-byte entries.
Your (currently unused) READ function can use a sector sized buffer anywhere in memory but I would suggest to stay away from the 512 bytes at 0x7C00.
Did you notice you're resetting the first harddisk but you are reading from the first floppydisk?
I think you meant to write jmp $ ; Never ending loop after call PutStr didn't you?
If the exercise is about displaying the partitions available then all you have to do is display the CHS values from each partition table entry unless of course the system indicator byte reads 0 meaning no partition.

Sep Roland
  • 33,889
  • 7
  • 43
  • 76