Hello,

this is my first posting to this site and i was just wondering if anyone out there could help me figure out some code for an assignment that i have to do. I've just started learning Assembler and this assignment has stumped me. I have attached a copy of the assignment and the code that I have attempted, also the subroutines that are needed with their descriptions.


BITS 16 ; Set code generation to 16 bit mode
ORG 0x0100 ; Set code start address to 0100h


SECTION .text ; Main code section -
; test code for subroutines goes here

MAIN:


mov AX, 04C00H ; Exit the program
int 21H

; SUBROUTINES ******************************************
;*****************************************************************
; Subroutine name: ReadSector
; Function: Reads a specified sector into a buffer
; Entry conditions: Disk Head (0 or 1) in DH
; cylinder (track) number (00H to 4FH) in CH
; sector on track (01H to 12H) in CL
; buffer address for sector (200H in size) in BX
; Exit conditions: AH has success or error code value,
; sector copied to buffer,
; other register values unchanged
;*****************************************************************
ReadSector:
push BX
push CX
push DX
push AX
mov AH,02H ; read sector service number
mov AL,01H ; number of sectors to read
mov DL,00H ; drive number 0=a: floppy drive
int 13H ; BIOS Disk services

pop BX ; popping AX into BX
mov AL,BL ; restore AL to original value
pop DX
pop CX
pop BX
; AH has success/error code
ret

; *****************************************************************
; Subroutine name: WriteSector
; Function: Writes a buffer to a specified sector
; Entry conditions: Disk Head (0 or 1) in DH
; cylinder (track) number (00H to 4FH) in CH
; sector on track (01H to 12H) in CL
; buffer address for sector (200H in size) in BX
; Exit conditions: AH has success or error code value,
; buffer copied to sector,
; other register values unchanged
; *****************************************************************
WriteSector:
push BX
push CX
push DX
push AX
mov AH,03H ; write sector service number
mov AL,01H ; number of sectors to read
mov DL,00H ; drive number 0=a: floppy drive
int 13H ; BIOS Disk services

pop BX ; popping AX into BX
mov AL,BL ; restore AL to original value
pop DX
pop CX
pop BX
; AH has success/error code
ret

; *****************************************************************
; Subroutine name: InitSector
; Function: Sets bytes of specified sector to given value
; - initialises with value buffer before writing
; Entry conditions: byte value for initialisation in AL
; Disk Head (0 or 1) in DH
; cylinder (track) number (00H to 4FH) in CH
; sector on track (01H to 12H) in CL
; buffer address for sector operation (200H in size) in BX
; Exit conditions: AH has success or error code value,
; buffer copied to sector,
; other register values unchanged
; *****************************************************************
InitSector:

push CX
push DX

mov CX,512
rep mov BX,AL

pop DX
pop CX

ret


; *****************************************************************
; Subroutine name: GetByteAt
; Function: gets byte at specified location in specifed sector
; - gets sector into buffer - then gets byte
; Entry conditions: byte location in SI
; Disk Head (0 or 1) in DH
; cylinder (track) number (00H to 4FH) in CH
; sector on track (01H to 12H) in CL
; buffer address for sector operation (200H in size) in BX
; Exit conditions: AH has success or error code value,
; AL has byte from sector,
; other register values unchanged
; *****************************************************************
GetByteAt:

ret

; *****************************************************************
; Subroutine name: SetByteAt
; Function: sets byte at specified location in specifed sector
; to given value - gets sector into buffer -
; sets byte value,then writes buffer back to sector
; Entry conditions: byte location in DI
; byte value to assign to location in DL
; Disk Head (0 or 1) in DH
; cylinder (track) number (00H to 4FH) in CH
; sector on track (01H to 12H) in CL
; buffer address for sector operation (200H in size) in BX
; Exit conditions: AH has success or error code value,
; other register values unchanged
; *****************************************************************
SetByteAt:

ret

; *****************************************************************
; Subroutine name: GetSubSector
; Function: gets copy of specified subsector of given sector
; - gets sector into buffer - then gets subsector
; Entry conditions: byte location of start of subsector in SI
; length of subsector in AX
; Disk Head (0 or 1) in DH
; cylinder (track) number (00H to 4FH) in CH
; sector on track (01H to 12H) in CL
; buffer address for sector operation (200H in size) in BX
; buffer address for subsector storage in BP
; Exit conditions: AH has success or error code value,
; copy of subsector in buffer addressed by BP,
; other register values unchanged
; *****************************************************************
GetSubSector:

ret


; *****************************************************************
; Subroutine name: SetSubSector
; Function: sets specified subsector of given sector to
; value of array specified
; - gets sector into buffer - then sets subsector
; in buffer, then writes buffer to sector
; Entry conditions: byte location of start of subsector in DI
; length of subsector in AX
; Disk Head (0 or 1) in DH
; cylinder (track) number (00H to 4FH) in CH
; sector on track (01H to 12H) in CL
; buffer address for sector operation (200H in size) in BX
; buffer address for subsector storage in BP
; Exit conditions: AH has success or error code value,
; subsector in buffer addressed by BP copied into sector,
; other register values unchanged
; *****************************************************************
SetSubSector:

ret

; *****************************************************************
; Subroutine name: SectorCompare
; Function: compares 2 sectors for equality - returns FF
; if equal and 0 if not
; - get 2 specified sectors into buffers - compare
; buffers,return result
; Entry conditions: 1st sector - disk head in DH, cylinder in CH, sector in BH
; 2nd sector - disk head in DL, cylinder in CL, sector in BL
; buffer address for first sector (200H in size) in SI
; buffer address for second sector in DI
; Exit conditions: AH has success or error code value,
; AL is FF if sectors have identical contents, 0 otherwise
; other register values unchanged
; *****************************************************************
SectorCompare:

push CX
cld
mov SI, BH
mov DI, BL
mov CX, 512
repe cmpsb
jne NOTEQUAL
mov AL, FF
pop CX
ret

NOTEQUAL:
mov AL, 0
pop CX


ret

; *****************************************************************
; Subroutine name: SectorCopy
; Function: copies source sector to destination sector
; - get source sector into buffer - copy to second buffer
; - write second buffer to destination sector
; Entry conditions: 1st sector - disk head in DH, cylinder in CH, sector in BH
; 2nd sector - disk head in DL, cylinder in CL, sector in BL
; buffer address for source sector (200H in size) in SI
; buffer address for destination sector in DI
; Exit conditions: AH has success or error code value,
; other register values unchanged
; *****************************************************************
SectorCopy:

push CX
push AX
cld
mov SI, BH
mov DI, BL
mov CX, 512
rep movsb
pop AX
pop CX

ret


; *****************************************************************
; Subroutine name: DisplaySector
; Function: displays to console window contents of given sector
; display format is
; 32 (20H) lines, each line displays 16 bytes of the sector
; as ASCII characters and then as 4 digit hex numbers
; so a line consists of
; 16 ASCII characters, a 2 space separator, 16 bytes as hex numbers,
; then a newline - for readability you will need a
; space between each of the 4 digit hex numbers
; Entry conditions: Disk Head (0 or 1) in DH
; cylinder (track) number (00H to 4FH) in CH
; sector on track (01H to 12H) in CL
; buffer address for sector (200H in size) in BX
; Exit conditions: AH has success or error code value,
; sector displayed in console window -
; NOTE - since console window is 80x25 the whole
; of the sector cannot be displayed in the console
; window in one go - redirection can be used
; to send console output to a file for reading using
; an editor - thus e.g. at the dos prompt you can type
; sector-editor > filename
; filename wil contain all console output generated by
; sector-editor
; other register values unchanged
; *****************************************************************
DisplaySector:


ret


; End of user defined subroutines
;*********************************


%include "stdio.asm"


SECTION .data ; data segment for initialised data - also put constants here


SECTION .bss ; data segment for unitialised data

Sector1 resb 512
Sector2 resb 512

; you may need other buffers

Sorry to make this post such a long one but I am genuinely stuck on this. Any help would be greatly appreciated.

Regards,

PS I dont expect any one to give me the answers .. I just need some help getting started on the code thats left... I have been to my lecturers and they dont really offer me any help. My lecture notes only give the basics to 8086 coding and nothing to do with floppy sectors. And all the research done on the internet so far dosnt seem to help.

Well, after the MAIN: label you can do something like...say, read a sector:

mov DH, 0 ; set the head
mov CH, 0 ; set the track
mov CL, 1 ; set the sector
lea BX, buffer ;must define 'buffer' first
call ReadSector

Then you will want to check the value in AH and handle any errors appropriately.

If no errors, then you might want to display the sector:

mov DH, 0 ; set the head
mov CH, 0 ; set the track
mov CL, 1 ; set the sector
lea BX, buffer
call DisplaySector

Of course, you will have to write the 'DisplaySector' code first. ;)

Hope this helps!

Member Avatar for mikemark

hope that above code helpped
using 80 x 86 asm try loading a windows bitmap on to the screen (after going to graphics screen)
i tryed this and it worked (after a lot of work)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.