Hey there,

This is my first posting, as for once in my life I need extreme help with programming. I can work C with a little magic, just assembler is just NOT my cup of tea. I was hoping that my attempts will show through, yet there are numerous subroutines that are not started, simply because I have struggeled to implement the ones I have. I was hopeing someone has this code - or can help somewhere in the world before I fail my second year at uni! Unfortuneately, i am supposed to able to write 2/8 subroutines in exam conditions however wont know which ones they will be.

Hope someone can help, many thanks guys & gals
(the bits in orange are my poor attempts :-| lol )
Cheers, Ian. :)

*****************************************************************************

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 DX, 'C'
call InitSector

call GetByteAt

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,0H ; 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:

Push SI
mov CX, 00000H
call ReadSector

gbloop:
inc CX
inc BX
cmp CX, 100H
jne gbloop

mov SI, CX

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

damm this stuff is hard! Ne suggestions please!
:mad: :)

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.