.TITLE "assignment1"
.PSIZE 35,80
/*****************************************************************
* FILENAME: lab5
* AUTHOR (STUDENT NAME): Marc Tessier
* STUDENT NUMBER: 040576114
* E-MAIL ADDRESS: tess0072@algonquincollege.com
* LAB SECTION: 313
* ASSIGNMENT NUMBER AND NAME: lab 4 - Read a Line Program
* PROFESSOR'S NAME: Robert E. Allison
* Purpose: Read lines of ASCII characters from the keyboard
* and store each line in turn into a buffer in memory.
*****************************************************************/
/************ INCLUDES ******************************************/
.NOLIST
.INCLUDE "..\\include\\ascii.i"
.LIST
/************ CONSTANT DATA *************************************/
.TEXT 1
MsgProgramID:
.ASCIZ "Welcome to the Read a Line Program"
MsgStringFull:
.ASCIZ "The string is full..."
MsgUserPrompt:
.ASCIZ "Please enter a string, Press enter for newline or CTRL+D to exit:"
MsgUserExit:
.ASCIZ "Goodbye!"
.EQU CRLF,0x0D
.EQU EOF,0x04
/************* VARIABLE DATA ************************************/
.DATA
String:
.SPACE 1024,0
CapNext:
.SPACE 1,0
/************* PROCESS INSTRUCTIONS *****************************/
.TEXT 0
.GLOBAL assignment1
assignment1:
MOVEA.L #MsgProgramID,A0
JSR PrintMsg
JSR NewLine
MOVEA.W #MsgUserPrompt,A0
JSR PrintMsg
JSR NewLine
MOVEA.L #String,A0 | Point A0 to the strings location in memory
MOVE.W #1024,D1 | Store size of the string
MOVE.B #0,D2 | Store amount of characters enteres
JSR ReadLine | Go to Read Line
RTS
ReadLine:
JSR ConsoleIn | Get character
JSR ConsoleOut | Output character
ADDQ.B #1,D3 | Increment Total Character Count
CMP.B #CRLF,D0 | If "Enter" Go to New Line
BEQ.W NewLine
CMP.B #EOF,D0 | If "Ctrl+D" Go to End Program
BEQ.W EndProgram
ADDQ.B #1,D2 | Increament Character Count
MOVE.W D0,(A0) | Move character into string
ADDQ.L #1,A0 | Increament the string
SUBQ.B #1,D1 | Subtract 1 from characters remaining
CMP.B #0,D1 | If string is full
BEQ.W StringFull
JMP ReadLine | Repeat
StringFull:
MOVEA.L A0,A1 | Move A0 to A1
SUBA.L #1,A1 | Go to the beggining of the last character
CMP.B #0x00,(A1) | If that character is "EOL" End Program
BEQ.W EndProgram
MOVE.B #-1,D0 | Else Return -1(String Overflow)
JSR NewLine
MOVEA.L #MsgStringFull,A0
JSR PrintMsg
JMP EndProgram | Go to End of Program
NewLine:
MOVE.B #0x00,(A0) | Attach "EOL" to what user entered
ADDQ.L #1,A0 | Increment the string
ADDQ.B #1,D2 | Increment the character count
SUBQ.B #1,D1 | Decrease size characters remaining
MOVEA.L #CapNext,A3 | Load my capitalise flag into A3
MOVE.B #1,(A3) | Set my capitalise flag to 1 for first character
JSR CharCheck | Go to my Capitalisation check function
JSR PrintMsg | Output user input
JSR NewLine
MOVEA.L A0,A2 | Move string into "safe" place
SUBA.L D2,A0 | Go to begining of string
MOVEA.L A2,A0 | Move A2 back to A0
CMP.B #0,D1 | Check if string is full
BEQ.W StringFull
MOVE.B #0,D2 | Reset The string buffer
JMP ReadLine | Go to Read Line
CharCheck:
CMP.B #0X00,(A0) | Check to see if we are at the EOL
BEQ.W EndProgram
CMP.B #1,(A0) | If the capatalise flag is up
BEQ.W CapChar | Capitalise that character
CMP.B #0x21,(A0) | Check for ! character
BEQ.W FlagSet
CMP.B #0x3F,(A0) | Check for ? character
BEQ.W FlagSet
CMP.B #0x2E,(A0) | Check for . character
BEQ.W FlagSet
CMP.B #0x69,(A0) | Check for i character
BEQ.W iCap
CMP.B #0x41,(A0) | Check for < A
BLT.W NextChar
CMP.B #0x5A,(A0) | Check for > Z
BGT.W NextChar
MOVE.B (A0),D0 | Load character into D0
JSR ToUpper | Make character upper case
MOVE.B D0,(A0) | Return character to string
MOVE.B #0,(A3) | Remove the capatalise flag
JMP NextChar | Go to next character
iCap:
CapChar:
CMP.B #0x21,(A0) | Check for ! character
BEQ.W FlagSet
CMP.B #0x3F,(A0) | Check for ? character
BEQ.W FlagSet
CMP.B #0x2E,(A0) | Check for . character
BEQ.W FlagSet
CMP.B #0x30,(A0) | Check for > 0
BLT.W NextChar
CMP.B #0x39,(A0) | Check for < 9
BLT.W AlreadyCap
CMP.B #0x41,(A0) | Check for below A
BLT.W NextChar
CMP.B #0x5A,(A0) | Check for below Z
BLT.W AlreadyCap
CMP.B #0x61,(A0) | Check for below a
BLT.W NextChar
CMP.B #0x7A,(A0) | Check for above z
BGT.W NextChar
MOVE.B (A0),D0 | Load character into D0
JSR ToUpper | Make character upper case
MOVE.B D0,(A0) | Return character to string
MOVE.B #0,(A3) | Remove the capatalise flag
JMP NextChar
FlagSet:
MOVE.B #1,(A3) | Set the capatalise flag
JMP NextChar | Get next character
AlreadyCap:
MOVE.B #0,(A3) | Remove the capatalise flag
JMP NextChar | Get next character
NextChar:
ADDQ.L #1,A0 | Go to the next character
JMP CharCheck | Go check the new character
EndProgram:
CMP.B #-1,D0 | If String overflow go straigh to EOP
BEQ.W Finish
MOVE.W #1024,D3 | Else subtract the total amount
SUB.B D1,D3 | of characters enter from the
MOVE.B D3,D0 | total amount possible
Finish:
MOVE.B #0,(A0) | Null A0
MOVEA.L #MsgUserExit,A0
JSR PrintMsg
RTS | End program
/********* END OF PROGRAM **************************************/