flat assembler
Message board for the users of flat assembler.

Index > OS Construction > compiler bug.....maybe

Author
Thread Post new topic Reply to topic
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER 12 Apr 2011, 16:44
Hi everyone,
I made code for hard drive(bootsector
Code:
        ORG 7C00h

        START1:

        jmp START

        DATASECT:

        DAP:
        DAP_Size             db 10h         ;2h
        DAP_Res1             db 0           ;3h
        DAP_Bytes2Transfer   db 1h          ;4h
        DAP_Res2             db 0           ;5h
        DAP_Buff_Addr1       dw 0000h       ;7h
        DAP_Buff_Addr2       dw 0810h       ;9h
        DAP_LBA              dq 1h          ;12h

        DAT:
        DAT_Disk_Num         db 80h         ;13h
        DAT_Num_Of_Sects     db 1h          ;14h     

        START:
        mov bp, START1

        READ_HD:
        mov ah, 42h
        xor al, al
        mov dl, 80h
        mov si, cs
        mov ds, si
        mov si, DAP
        mov byte cl, [cs:bp+14h]

        RHD_LOOP:
        pusha
        int 13h
        popa
        jc ERROR
        add word [ds:si+6h], 20h
        inc word [ds:si+8h]
        loop RHD_LOOP

        COMPLETE:
        nop
        jmp COMPLETE

        ERROR:
        nop
        jmp ERROR



        times 449 db 0
        dw 0AA55h       

Somewhy and somehow, Virtualbox executes commands with code 00h,
WHY?
Post 12 Apr 2011, 16:44
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 12 Apr 2011, 17:28
In the last part, better use this:
Code:
        rb 512 - 2 + $$ - $
        dw 0AA55h    


And as for receiving error code zero, after calling INT 13 you are using POPA which restores the previous AL value (zero). So this is not a compiler problem, I'll move this thread to OS Construction.

[edit]Sorry, I made a mistake, error code is returned in AH so you should see 48H again. It seems that when you mention code 00H you mean something else. But still not a compiler problem as disassembling the code gives exactly what you compiled:
Code:
seg000:7C00 ;
seg000:7C00 ; +-------------------------------------------------------------------------+
seg000:7C00 ; ¦     This file is generated by The Interactive Disassembler (IDA)        ¦
seg000:7C00 ; ¦     Copyright (c) 2006 by DataRescue sa/nv, <ida@datarescue.com>        ¦
seg000:7C00 ; ¦                      Licensed to: Freeware version                      ¦
seg000:7C00 ; +-------------------------------------------------------------------------+
seg000:7C00 ;
seg000:7C00 ; ---------------------------------------------------------------------------
seg000:7C00 ; File Name   : C:\Documents and Settings\Hernan\Escritorio\test.bin
seg000:7C00 ; Format      : Binary file
seg000:7C00 ; Base Address: 0000h Range: 7C00h - 7E00h Loaded length: 0200h
seg000:7C00
seg000:7C00                 .686p
seg000:7C00                 .mmx
seg000:7C00                 .model flat
seg000:7C00
seg000:7C00 ; ---------------------------------------------------------------------------
seg000:7C00
seg000:7C00 ; Segment type: Pure code
seg000:7C00 seg000          segment byte public 'CODE' use16
seg000:7C00                 assume cs:seg000
seg000:7C00                 ;org 7C00h
seg000:7C00                 assume es:nothing, ss:nothing, ds:nothing, fs:nothing, gs:nothing
seg000:7C00                 jmp     short loc_7C14
seg000:7C00 ; ---------------------------------------------------------------------------
seg000:7C02                 db  10h
seg000:7C03                 db    0
seg000:7C04                 db    1
seg000:7C05                 db    0
seg000:7C06                 db    0
seg000:7C07                 db    0
seg000:7C08                 db  10h
seg000:7C09                 db    8
seg000:7C0A                 db    1
seg000:7C0B                 db    0
seg000:7C0C                 db    0
seg000:7C0D                 db    0
seg000:7C0E                 db    0
seg000:7C0F                 db    0
seg000:7C10                 db    0
seg000:7C11                 db    0
seg000:7C12                 db  80h ; Ç
seg000:7C13                 db    1
seg000:7C14 ; ---------------------------------------------------------------------------
seg000:7C14
seg000:7C14 loc_7C14:                               ; CODE XREF: seg000:7C00j
seg000:7C14                 mov     bp, 7C00h
seg000:7C17                 mov     ah, 42h ; 'B'
seg000:7C19                 xor     al, al
seg000:7C1B                 mov     dl, 80h ; 'Ç'
seg000:7C1D                 mov     si, cs
seg000:7C1F                 mov     ds, si
seg000:7C21                 mov     si, 7C02h
seg000:7C24                 mov     cl, cs:[bp+14h]
seg000:7C28
seg000:7C28 loc_7C28:                               ; CODE XREF: seg000:7C35j
seg000:7C28                 pusha
seg000:7C29                 int     13h             ; DISK -
seg000:7C2B                 popa
seg000:7C2C                 jb      short loc_7C3A
seg000:7C2E                 add     word ptr [si+6], 20h ; ' '
seg000:7C32                 inc     word ptr [si+8]
seg000:7C35                 loop    loc_7C28
seg000:7C37
seg000:7C37 loc_7C37:                               ; CODE XREF: seg000:7C38j
seg000:7C37                 nop
seg000:7C38                 jmp     short loc_7C37
seg000:7C3A ; ---------------------------------------------------------------------------
seg000:7C3A
seg000:7C3A loc_7C3A:                               ; CODE XREF: seg000:7C2Cj
seg000:7C3A                                         ; seg000:7C3Bj
seg000:7C3A                 nop
seg000:7C3B                 jmp     short loc_7C3A
seg000:7C3B ; ---------------------------------------------------------------------------
seg000:7C3D                 db 1C1h dup(0), 55h, 0AAh
seg000:7C3D seg000          ends
seg000:7C3D
seg000:7C3D
seg000:7C3D                 end    
Post 12 Apr 2011, 17:28
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 12 Apr 2011, 17:58
I see you miscalculated the offsets of two variables, DAT_Disk_Num is at bp+12h and DAT_Num_Of_Sects at bp+13h. I think you have some other offsets wrong as well and perhaps you are not incrementing the buffer address correctly. Perhaps you should use plain labels first and then move to use BP-relative stuff (for which I recommend you to learn the "virtual" directive and/or struc)
Post 12 Apr 2011, 17:58
View user's profile Send private message Reply with quote
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER 13 Apr 2011, 11:35
thank you, I changed address, I changed address of variable and it works
Post 13 Apr 2011, 11:35
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.