All pastes #913157 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-02-21 21:31 UTC
rendered paste body
.TITLE "assign1"
.PSIZE 35,200
/*****************************************************************
******************************************************************
 
   FILENAME: assignment1.a86
   AUTHOR (STUDENT NAME): Jason Reid
   STUDENT NUMBER: 040561786
   E-MAIL ADDRESS: reid.jason@gmail.com
   LAB SECTION: 313
   ASSIGNMENT NUMBER AND NAME: Lab 5
   PROFESSOR'S NAME: Robert Allison
   PURPOSE: To read multiple lines from the user.

******************************************************************
*****************************************************************/

/************ [INCLUDE FILES] ***********************************/

	.NOLIST
	.INCLUDE "..\\include\\ascii.i" | ASCII symbols
	.LIST
                
/*****************************************************************
*****************************************************************/
/************ [CONSTANT DATA] ***********************************/

        .TEXT 1
WelcomeMessage: .ASCII "Enter a string, enter to seperate lines, ^D to quit."
                .BYTE   CR,LF,0
MaxMessage:     .ASCII "Maximum amount of space reached."
                .BYTE   CR,LF,0
ExitMessage:    .ASCII "Thank you for using the program."
                .BYTE   CR,LF,0
errorReport:    .ASCII "An error occured with readLine, D0 is -1."
                .BYTE   CR,LF,0
CharMessage:    .ASCII "Amount of characters entered: "
                .BYTE   CR,LF,0       
debugmsg:       .ASCII "WOOT"
                .BYTE   CR,LF,0    
.EQU    EOF,0x04
.EQU    CRLF,0x0D
.EQU	BACK,0x08
/*****************************************************************
*****************************************************************/
/************ [DATA] ********************************************/

	.DATA
string: 	.SPACE 1024,0
capNext:	.SPACE 1,0
/*****************************************************************
*****************************************************************/
/************ [VARIABLES] ***************************************/

	.TEXT 0
	.GLOBAL 	assign1
	
/*****************************************************************
*****************************************************************/
/************ [CODE] ********************************************/

assign1:	
        MOVEA.L #WelcomeMessage,A0
        JSR	NewLine
        JSR     PrintMsg	| Output the welcome message.
        JSR	NewLine
        MOVEA.L #string,A0	| Store location of string in A0
        MOVE.W  #1024,D1	| Store buffer size in D1
        MOVE.B  #0,D2		| Initiate D2 (used for count)
        JSR	readLine	| readLine subrutine
        CMP.B	#-1,D0		| Check to see if an error returned
        BNE.B	endProgram	| If no error occured
        MOVEA.L	#errorReport,A0 
        JSR	NewLine
      	JSR	PrintMsg	| Ouput error message
        
endProgram:
	MOVE.B	#2,D1
	MOVEA.L	#CharMessage,A0
	JSR	NewLine
	JSR	PrintMsg
	JSR	OutHex
	RTS
                     
readLine:
	JSR 	ConsoleIn			
	CMP.B	#CRLF,D0	
	BEQ.W	detectEnter	| If the character hits enter.			
	CMP.B	#EOF,D0
	BEQ.W	detectEOF	| If the user enters the EOF character.
	CMP.B	#BACK,D0
	BEQ.W	detectBackspace
	MOVE.B	D0,(A0)		| Store the character in the buffer.
	JSR	ConsoleOut
	ADDQ.L	#1,A0		| Increase by one so we are pointing to next memory location.
	ADDQ.B	#1,D2		| Increase temporary character count by one.
	SUBQ.B	#1,D1		| Decrease the variable buffer size.
	CMP.B	#0,D1
	BEQ.W	bufferFull
	JMP	readLine	

detectEnter:
	JSR	NewLine
	MOVE.B	#0x00,(A0)
	ADDQ.L	#1,A0
	ADDQ.B	#1,D2		| Increase the temporary character count by one.
	SUBQ.B	#1,D1
	MOVEA.L	A0,A1		| Store A0 into A1 so we can manipulate it the A0 (for PrintMsg)
	SUBA.L	D2,A0		| Goto the start of the string.
	JSR	fixCaps
	JSR	PrintMsg	| Print the name just entered.
	JSR	NewLine
	MOVEA.L	A1,A0		| Move stored A1 back into A0
	MOVE.B	#0,D2		| Empty the character count.
	CMP.B	#0,D1
	BEQ.W	bufferFull
	JMP	readLine

detectBackspace:
	CMP.B	#0,D2
	BEQ.W	readLine
	JSR 	ConsoleOut
	SUBQ.B	#1,D2
	ADDQ.B	#1,D1
	SUBA.L	#1,A0
	JMP	readLine
	
fixCaps:
	MOVEA.L	#capNext,A4
	MOVE.B	#1,(A4)
	MOVEA.L	A0,A2
	
loopChar:
	CMP.B	#0x00,(A2)
	BEQ.W	endFixCaps
	MOVEA.L	#capNext,A4
	CMP.B	#1,(A4)
	BEQ.W	capChar
	CMP.B	#0x21,(A2)	| If its a !
	BEQ.W	flagCaps
	CMP.B	#0x3F,(A2)	| If its a ?
	BEQ.W	flagCaps
	CMP.B	#0x2E,(A2)	| If its a .
	BEQ.W	flagCaps
	CMP.B	#0x69,(A2)	| If its an i
	BEQ.W	capI
	CMP.B	#0x41,(A2)	| below A
	BLT.W	nextChar
	CMP.B	#0x5A,(A2)	| above Z
	BGT.W	nextChar
	MOVE.B	(A2),D0
	JSR	ToLower
	MOVE.B	D0,(A2)
	MOVE.B	#0,(A4)
	JMP	nextChar

capI:
	MOVEA.L	A2,A3
	SUBA.L	#1,A3
	CMP.B	#0x20,(A3)	| If the previous character is not a space
	BNE.W	nextChar
	ADDQ.L	#2,A3		| If the next character is not a space
	CMP.B	#0x20,(A3)	
	BNE.W	nextChar
	MOVE.B	(A2),D0
	JSR	ToUpper
	MOVE.B	D0,(A2)
	JMP	nextChar

capChar:
	CMP.B	#0x21,(A2)	| If its a !
	BEQ.W	flagCaps
	CMP.B	#0x3F,(A2)	| If its a ?
	BEQ.W	flagCaps
	CMP.B	#0x2E,(A2)	| If its a .
	BEQ.W	flagCaps
	CMP.B	#0x30,(A2) 	| If its below 0
	BLT.W	nextChar
	CMP.B	#0x39,(A2)	| If its a number... dont caps.. duh
	BLT.W	isCapChar
	CMP.B	#0x41,(A2) 	| If its below A
	BLT.W	nextChar
	CMP.B	#0x5A,(A2) 	| If its below Z but A or above... capital.
	BLT.W	isCapChar
	CMP.B	#0x61,(A2) 	| If its below a, but not A-Z
	BLT.W	nextChar
	CMP.B	#0x7A,(A2) 	| If its above z, so not A-Z
	BGT.W	nextChar
	MOVE.B	(A2),D0
	JSR	ToUpper
	MOVE.B	D0,(A2)
	MOVEA.L	#capNext,A4
	MOVE.B	#0,(A4) 	| Unflag capitalization.
	JMP	nextChar

flagCaps:
	|MOVEA.L #debugmsg,A0
	|JSR	PrintMsg
	MOVEA.L	#capNext,A4
	MOVE.B	#1,(A4)
	JMP	nextChar

isCapChar:
	MOVEA.L	#capNext,A4
	MOVE.B	#0,(A4)
	JMP	nextChar

nextChar:
	ADDQ.L	#1,A2
	JMP loopChar
	
endFixCaps:
	RTS
	
bufferFull:
	MOVEA.L	A0,A1		| Store A0 into A1 so we can manipulate it.
	SUBQ.L	#1,A1		| Subtract 1 from A1 to point to last character.
	CMP.B	#0x00,(A1)	| Check to see if the last character was CR
	BEQ.B	detectEOF	| End the program.
	JSR	NewLine
	MOVEA.L	#MaxMessage,A0
	JSR	PrintMsg
	ADDQ.L	#1,A1
	MOVEA.L	A1,A0
	MOVE.B	#-1,D0		| Set D0 to -1 as we hit the buffer size and the last character is not CR.
	
detectEOF:
	CMP.B	#-1,D0
	BEQ.B	finish
	MOVE.W	#1024,D3	| Move our total size into D0.
	SUB.B	D1,D3		| Subtract space left from total size
	MOVE.B	D3,D0		| Move amount of characters into D0 per specs.		

finish:	MOVEA.L A0,A1		| Store A0 into A1 so we can output a message.
	JSR	NewLine
	MOVEA.L #ExitMessage,A0
	JSR	PrintMsg	| Print Exit Message
	MOVEA.L A1,A0
	MOVE.B	#0 ,(A0)
	RTS
	

/*****************************************************************
******************************************************************
************** [END OF PROGRAM] *********************************/