TITLE	Transmission Program ass2.asm

COMMENT | Written by Caitlin Ross, 100735219, COMP 2003 A 
	|

.MODEL SMALL
.STACK 100H

.DATA
	message		DB 25 dup (00H)
	ip_address	DB 4 dup (00H)
	checksum	DW 00H
	error_msg	DB 'Error in Transmission', 0
	ip_msg		DB 'The IP address is ', 0
	message_msg	DB 'The message is ', 0
	test_msg	DB 'Loop done', 0
	correct_msg	DB 'EOT was found', 0

.CODE

INCLUDE io.mac
.486

main PROC
	.STARTUP

	mov DX,80H
	mov BX, OFFSET message
	mov CX, 0

read_bits:
	GetCh AL
	cmp AL, '1'
	jne write_zero
	;PutCh '1'
	add word ptr[BX], DX
	jmp check_for_last_byte

write_zero:
	;PutCh '0'

check_for_last_byte:
	shr DX, 1
	cmp DX, 00H
	jg increment
	;jg not_eot
	;PutCh ' '
	;PutCh [BX]
	;nwln
	mov DX,80H

compare_byte:
	cmp byte ptr [BX-1], 04H
	je end_bit_loop
	inc BX

not_eot:
	;cmp DX, 00H
	;jg inc_mask
	

increment:
	inc CX
	cmp CX, 201
	jne read_bits

end_bit_loop:
	mov BX, OFFSET message
	mov CX, 0

start_display_loop:

	PutCh [BX]
	inc BX
	inc CX
	cmp byte ptr [BX], 04H
	je end_display_loop
	cmp CX, 25
	jge end_display_loop
	jmp start_display_loop

end_display_loop:
	cmp byte ptr [BX], 04H
	jne not_end
	PutStr correct_msg

not_end:
	;PutStr test_msg
	;Push OFFSET message
	;Push OFFSET ip_address
	;Push checksum
	;Call sipo

	;mov BX,OFFSET message 
	;Push BX
	;Call checker

	;cmp checksum, AX
	;je output
	;PutStr error_msg
	;jmp done_main

output:
	;PutStr ip_msg
	;mov BX, OFFSET ip_address
	;PutInt [BX]
	;PutCh '.'
	;PutInt [BX+1]
	;PutCh '.'
	;PutInt [BX+2]
	;PutCh '.'
	;PutInt [BX+3]
	
	;nwln
	;PutStr message_msg
	;PutStr message
	
done_main:
	.EXIT
main ENDP



sipo PROC
	push BX
	push BP
	push SI
	push DI
	push AX
	
	mov BP, SP
	mov SI, [BP+4]
	mov DI, [BP+6]
	mov BX, [BP+10]
	
	mov AL, byte ptr [BX+4]
	mov byte ptr [DI], AL
	mov AL, byte ptr [BX+6]
	mov byte ptr [DI+2], AL

move_byte_loop:
	cmp byte ptr [BX+9], 03H
	jne move_byte
	mov byte ptr [BX], 00H
	jmp end_byte_loop

move_byte:
	mov AL, byte ptr [BX+9]
	mov byte ptr [BX], AL
	inc BX

end_byte_loop:
	pop AX
	pop DI
	pop SI
	pop BP
	pop BX

	ret 56

sipo ENDP



checker PROC
	push BP
	push DX
	
	mov BP, SP
	add BP, 4
	
	mov AX, 0
	mov DX, 0

start_check_loop:
	rol byte ptr [BP], 1
	jc not_a_one
	inc AX

not_a_one:
	inc DX
	cmp DX, 7
	jl start_check_loop
	mov DX, 0
	inc BP
	cmp byte ptr [BP], 00H
	jne start_check_loop
	
checker ENDP

END main