Understanding Assembly Code

Discussion in 'Assembly Language Programming (ALP) Forum' started by Unity, May 14, 2013.

  1. Unity

    Unity New Member

    Joined:
    May 14, 2013
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    My knowledge regarding assembly code is very limited and I wanted to ask if someone could help figure out what the following is doing? There is a routine that calls the disk (this is code loaded directly by BIOS) and I would like to know where this is and how it is executed:

    Code:
    //allow interrupts
    :0000                 cli
    //ax=0
    :0001                 xor       ax, ax
    //ss=ax(=0)
    :0003                 mov     ss, ax
    //sp=0x7c00
    :0005                 mov     sp, 7C00h
    //si=sp
    :0008                 mov     si, sp
    //es=ax(=0)
    :000A                 push    ax
    :000B                 pop     es
    //ds=ax(=0)
    :000C                 push    ax
    :000D                 pop     ds
    :000E                 sti
    :000F                 cld
    //di=0x600
    //cx=0x100
    :0010                 mov     di, 600h
    :0013                 mov     cx, 100h
    :0016                 rep movsw
    //
    //
    :0018                 jmp     far ptr 0:61Dh
    //dh=0
    //cx=2
    //di=5
    :001D                 mov     dh, 0
    :001F                 mov     cx, 2
    :0022                 mov     di, 5
    :0025
    :0025 loc_25:      
    //bx=0x700
    //ax=0x201                        
    :0025                 mov     bx, 700h
    :0028                 mov     ax, 201h
    //di=16 bit destination register
    :002B                 push    di
    // AX= AH | AL=0x201
    // CX=CH | CL = 2
    //AL=1=> number of sector to read =1
    //AH=2 => int 13h will be READ SECTORS INTO MEMORY
    // CH=track=0
    // CL= sector = 2
    //this code reads the second sector, that is to say the data from 0x200 to 0x3FE.
    :002C                 int     13h             ; DISK - READ SECTORS INTO MEMORY
    :002C                                         ; AL = number of sectors to read, CH = track, CL = sector
    :002C                                         ; DH = head, DL = drive, ES:BX -> buffer to fill
    :002C                                         ; Return: CF set on error, AH = status, AL = number of sectors read
    :002E                 pop     di
    //will jump if CF=0
    :002F                 jnb     short loc_3D
    //ax=0
    //CX=3 => track=0 and sector =3
    :0031                 xor     ax, ax
    // AL=AH=0
    //the disk is reseted
    :0033                 int     13h             ; DISK - RESET DISK SYSTEM
    :0033                                         ; DL = drive (if bit 7 is set both hard disks and floppy disks reset)
    //di--
    //the destination counter is decremented
    :0035                 dec     di
    //jump if ZF is set
    //untill di=0 we loop
    :0036                 jnz     short loc_25
    //end of loop, di=0
    //si=source index
    //si=0x68A
    :0038                 mov     si, 68Ah
    //jump to next block
    :003B                 jmp     short loc_78
    :003D ; ---------------------------------------------------------------------------
    :003D
    :003D loc_3D:                      
    //cx=3
    :003D                 mov     cx, 3
    :0040
    :0040 loc_40:                                 ; DATA XREF: :0083#r
    :0040                 mov     di, 5
    :0043
    :0043 loc_43:                                 ; CODE XREF: :0059#j
    :0043                 mov     bx, 2000h
    :0046                 push    bx
    :0047                 pop     es
    :0048                 assume es:nothing
    :0048                 mov     bx, 0
    :004B                 mov     ax, 220h        ; DATA XREF: :002C#r
    :004B                                         ; :0033#r ...
    :004E                 push    di
    :004F                 int     13h             ; DISK - READ SECTORS INTO MEMORY
    :004F                                         ; AL = number of sectors to read, CH = track, CL = sector
    :004F                                         ; DH = head, DL = drive, ES:BX -> buffer to fill
    :004F                                         ; Return: CF set on error, AH = status, AL = number of sectors read
    :0051                 pop     di
    :0052                 jnb     short loc_60
    :0054                 xor     ax, ax
    :0056                 int     13h             ; DISK - RESET DISK SYSTEM
    :0056                                         ; DL = drive (if bit 7 is set both hard disks and floppy disks reset)
    :0058                 dec     di
    :0059                 jnz     short loc_43
    :005B                 mov     si, 68Ah
    :005E                 jmp     short loc_78
    :0060 ; ---------------------------------------------------------------------------
    :0060
    :0060 loc_60:                                 ; CODE XREF: :0052#j
    :0060                 mov     cx, 3FFFh
    :0063                 mov     si, 800h
    :0066                 xor     di, di
    :0068
    :0068 loc_68:                                 ; CODE XREF: :0071#j
    :0068                 lodsw
    :0069                 and     si, 0FFBFh
    :006C                 xor     ax, es:[di]
    :006F                 stosw
    :0070                 dec     cx
    :0071                 jnz     short loc_68
    :0073                 jmp     far ptr 2000h:0
    :0078 ; ---------------------------------------------------------------------------
    :0078
    :0078 loc_78:                                 ; CODE XREF: :003B#j
    :0078                                         ; :005E#j ...
    :0078                 lodsb
    :0079                 cmp     al, 0
    :007B                 jz      short loc_88
    :007D                 push    si
    :007E                 mov     bx, 7
    :0081                 mov     ah, 0Eh
    :0083                 int     10h             ; - VIDEO - WRITE CHARACTER AND ADVANCE CURSOR (TTY WRITE)
    :0083                                         ; AL = character, BH = display page (alpha modes)
    :0083                                         ; BL = foreground color (graphics modes)
    :0085                 pop     si
    :0086                 jmp     short loc_78
    :0088 ; ---------------------------------------------------------------------------
    :0088
    :0088 loc_88:                                 ; CODE XREF: :007B#j
    :0088                                         ; :loc_88#j
    :0088                 jmp     short loc_88
    :008A ; ---------------------------------------------------------------------------
    If more information is needed Ill try my best to provide as much detail as possible.

    Thanks!
     
  2. Unity

    Unity New Member

    Joined:
    May 14, 2013
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Can a mod please move this to the assembly code section, thanks.
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Done.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice